Commit 9c7da663 authored by kozyatinskiy's avatar kozyatinskiy Committed by Commit bot

[inspector] added experimental is_module flag for script parsed events

This flag is true when compiled script is ES6 module.

BUG=v8:1569
R=dgozman@chromium.org,adamk@chromium.org

Review-Url: https://codereview.chromium.org/2663973002
Cr-Commit-Position: refs/heads/master@{#42910}
parent b04d1d0e
......@@ -9123,6 +9123,10 @@ bool debug::Script::IsWasm() const {
return Utils::OpenHandle(this)->type() == i::Script::TYPE_WASM;
}
bool debug::Script::IsModule() const {
return Utils::OpenHandle(this)->origin_options().IsModule();
}
namespace {
int GetSmiValue(i::Handle<i::FixedArray> array, int index) {
return i::Smi::cast(array->get(index))->value();
......
......@@ -123,6 +123,7 @@ class Script {
MaybeLocal<Value> ContextData() const;
MaybeLocal<String> Source() const;
bool IsWasm() const;
bool IsModule() const;
bool GetPossibleBreakpoints(const debug::Location& start,
const debug::Location& end,
std::vector<debug::Location>* locations) const;
......
......@@ -693,7 +693,8 @@
{ "name": "executionContextAuxData", "type": "object", "optional": true, "description": "Embedder-specific auxiliary data." },
{ "name": "isLiveEdit", "type": "boolean", "optional": true, "description": "True, if this script is generated as a result of the live edit operation.", "experimental": true },
{ "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." },
{ "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true }
{ "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true },
{ "name": "isModule", "type": "boolean", "optional": true, "description": "True, if this script is ES6 module.", "experimental": true }
],
"description": "Fired when virtual machine parses script. This event is also fired for all known and uncollected scripts upon enabling debugger."
},
......@@ -710,7 +711,8 @@
{ "name": "hash", "type": "string", "description": "Content hash of the script."},
{ "name": "executionContextAuxData", "type": "object", "optional": true, "description": "Embedder-specific auxiliary data." },
{ "name": "sourceMapURL", "type": "string", "optional": true, "description": "URL of source map associated with script (if any)." },
{ "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true }
{ "name": "hasSourceURL", "type": "boolean", "optional": true, "description": "True, if this script has sourceURL.", "experimental": true },
{ "name": "isModule", "type": "boolean", "optional": true, "description": "True, if this script is ES6 module.", "experimental": true }
],
"description": "Fired when virtual machine fails to parse the script."
},
......
......@@ -990,6 +990,7 @@ void V8DebuggerAgentImpl::didParseSource(
}
bool isLiveEdit = script->isLiveEdit();
bool hasSourceURL = script->hasSourceURL();
bool isModule = script->isModule();
String16 scriptId = script->scriptId();
String16 scriptURL = script->sourceURL();
......@@ -1009,18 +1010,20 @@ void V8DebuggerAgentImpl::didParseSource(
std::move(executionContextAuxData));
const bool* isLiveEditParam = isLiveEdit ? &isLiveEdit : nullptr;
const bool* hasSourceURLParam = hasSourceURL ? &hasSourceURL : nullptr;
const bool* isModuleParam = isModule ? &isModule : nullptr;
if (success)
m_frontend.scriptParsed(
scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(),
scriptRef->endLine(), scriptRef->endColumn(), contextId,
scriptRef->hash(m_isolate), std::move(executionContextAuxDataParam),
isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam);
isLiveEditParam, std::move(sourceMapURLParam), hasSourceURLParam,
isModuleParam);
else
m_frontend.scriptFailedToParse(
scriptId, scriptURL, scriptRef->startLine(), scriptRef->startColumn(),
scriptRef->endLine(), scriptRef->endColumn(), contextId,
scriptRef->hash(m_isolate), std::move(executionContextAuxDataParam),
std::move(sourceMapURLParam), hasSourceURLParam);
std::move(sourceMapURLParam), hasSourceURLParam, isModuleParam);
if (scriptURL.isEmpty() || !success) return;
......
......@@ -142,10 +142,13 @@ class ActualScript : public V8DebuggerScript {
}
}
m_isModule = script->IsModule();
m_script.Reset(m_isolate, script);
}
bool isLiveEdit() const override { return m_isLiveEdit; }
bool isModule() const override { return m_isModule; }
const String16& sourceMappingURL() const override {
return m_sourceMappingURL;
......@@ -191,6 +194,7 @@ class ActualScript : public V8DebuggerScript {
String16 m_sourceMappingURL;
v8::Global<v8::String> m_sourceObj;
bool m_isLiveEdit = false;
bool m_isModule = false;
v8::Global<v8::debug::Script> m_script;
};
......@@ -219,6 +223,7 @@ class WasmVirtualScript : public V8DebuggerScript {
const String16& sourceMappingURL() const override { return emptyString(); }
bool isLiveEdit() const override { return false; }
bool isModule() const override { return false; }
void setSourceMappingURL(const String16&) override {}
bool getPossibleBreakpoints(
......
......@@ -67,6 +67,7 @@ class V8DebuggerScript {
int endColumn() const { return m_endColumn; }
int executionContextId() const { return m_executionContextId; }
virtual bool isLiveEdit() const = 0;
virtual bool isModule() const = 0;
void setSourceURL(const String16&);
virtual void setSourceMappingURL(const String16&) = 0;
......
Debugger.scriptParsed and Debugger.scriptFailedToParse with ES6 module
Running test: testLoadedModulesOnDebuggerEnable
{
method : Debugger.scriptParsed
params : {
endColumn : 1
endLine : 3
executionContextId : <executionContextId>
hasSourceURL : false
hash : F8E59942466284E2766FD161CA6FFD024048A807
isLiveEdit : false
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
startLine : 0
url : module1.js
}
}
Running test: testScriptEventsWhenDebuggerIsEnabled
{
method : Debugger.scriptParsed
params : {
endColumn : 1
endLine : 3
executionContextId : <executionContextId>
hasSourceURL : false
hash : F8E59942466284E2766FD161CA6FFD024048A807
isLiveEdit : false
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
startLine : 0
url : module2.js
}
}
{
method : Debugger.scriptFailedToParse
params : {
endColumn : 1
endLine : 0
executionContextId : <executionContextId>
hasSourceURL : false
hash : FF746120E4E4F1BA4CB5762843D429DC872EBA18
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
startLine : 0
url : module-with-syntax-error-2.js
}
}
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
print('Debugger.scriptParsed and Debugger.scriptFailedToParse with ES6 module');
let moduleSource = `
export function foo() {
return 42;
}`;
InspectorTest.addModule(moduleSource, 'module1.js');
InspectorTest.addModule('}', 'module-with-syntax-error-1.js');
Protocol.Debugger.onScriptParsed(InspectorTest.logMessage);
Protocol.Debugger.onScriptFailedToParse(InspectorTest.logMessage);
InspectorTest.runTestSuite([
function testLoadedModulesOnDebuggerEnable(next) {
Protocol.Debugger.enable().then(next);
},
function testScriptEventsWhenDebuggerIsEnabled(next) {
InspectorTest.addModule(moduleSource, 'module2.js');
InspectorTest.addModule('}', 'module-with-syntax-error-2.js');
InspectorTest.waitPendingTasks().then(next);
}
]);
......@@ -10,6 +10,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -27,6 +28,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -44,6 +46,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -61,6 +64,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -78,6 +82,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : oneline-map
startColumn : 0
......@@ -95,6 +100,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : oneline-without-nl-map
startColumn : 0
......@@ -112,6 +118,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : twoline-map
startColumn : 0
......@@ -129,6 +136,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : threeline-map
startColumn : 0
......@@ -146,6 +154,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : source-mapping-url-map
startColumn : 0
......@@ -163,6 +172,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : source-mapping-url-map
startColumn : 0
......@@ -180,6 +190,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -197,6 +208,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -214,6 +226,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -231,6 +244,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -248,6 +262,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -265,6 +280,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -282,6 +298,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -299,6 +316,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -316,6 +334,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -333,6 +352,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -350,6 +370,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -367,6 +388,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -384,6 +406,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -401,6 +424,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : oneline-map
startColumn : 0
......@@ -418,6 +442,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : oneline-without-nl-map
startColumn : 0
......@@ -435,6 +460,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : twoline-map
startColumn : 0
......@@ -452,6 +478,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : threeline-map
startColumn : 0
......@@ -469,6 +496,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : source-mapping-url-map
startColumn : 0
......@@ -486,6 +514,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL : source-mapping-url-map
startColumn : 0
......@@ -503,6 +532,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -520,6 +550,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -537,6 +568,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -554,6 +586,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -571,6 +604,7 @@ scriptParsed
hasSourceURL : true
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -587,6 +621,7 @@ scriptFailedToParse
executionContextId : <executionContextId>
hasSourceURL : true
hash : <hash>
isModule : false
scriptId : <scriptId>
sourceMapURL : failed-map
startColumn : 0
......@@ -604,6 +639,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -621,6 +657,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -638,6 +675,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -655,6 +693,7 @@ scriptParsed
hasSourceURL : false
hash : <hash>
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......
......@@ -9,6 +9,7 @@ Runtime.evaluate with valid expression
hasSourceURL : true
hash : 9D04F7335D1661503EAB9AF3EACAF92020803F34
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -25,6 +26,7 @@ Runtime.evaluate with syntax error
executionContextId : <executionContextId>
hasSourceURL : true
hash : 9BCA34A10E5386925E74C1716C857BEB02821E15
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -42,6 +44,7 @@ Runtime.callFunctionOn with valid functionDeclaration
hasSourceURL : false
hash : 9D04CEA1B54DF92A01A0498543D429DC872EBA18
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -58,6 +61,7 @@ Runtime.callFunctionOn with syntax error
executionContextId : <executionContextId>
hasSourceURL : false
hash : 9D04D83251E2B7F64CB5762843D429DC872EBA18
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -75,6 +79,7 @@ Runtime.compileScript with valid expression
hasSourceURL : false
hash : 9D04F733E4E4F1BA4CB5762843D429DC872EBA18
isLiveEdit : false
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -91,6 +96,7 @@ Runtime.compileScript with syntax error
executionContextId : <executionContextId>
hasSourceURL : false
hash : FF746120E4E4F1BA4CB5762843D429DC872EBA18
isModule : false
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......
......@@ -233,6 +233,8 @@ InspectorTest._dispatchMessage = function(messageObject)
var eventHandler = InspectorTest._eventHandler[eventName];
if (InspectorTest._scriptMap && eventName === "Debugger.scriptParsed")
InspectorTest._scriptMap.set(messageObject.params.scriptId, JSON.parse(JSON.stringify(messageObject.params)));
if (eventName === "Debugger.scriptParsed" && messageObject.params.url === "wait-pending-tasks.js")
return;
if (eventHandler)
eventHandler(messageObject);
}
......
......@@ -8,6 +8,7 @@ Checks basic ES6 modules support.
hasSourceURL : false
hash : 9C014F7249BAFA12B91017817AD15091D01A9155
isLiveEdit : false
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -24,6 +25,7 @@ Checks basic ES6 modules support.
hasSourceURL : false
hash : 443A2FA24A6112E6B9101781E6A19B56BDC396D4
isLiveEdit : false
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -40,6 +42,7 @@ Checks basic ES6 modules support.
hasSourceURL : false
hash : 54D834614FBF9B389082DAE06CD3EFC499BEBF13
isLiveEdit : false
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......@@ -183,6 +186,7 @@ console.log(239)
executionContextId : <executionContextId>
hasSourceURL : false
hash : FF746120E4E4F1BA4CB5762843D429DC872EBA18
isModule : true
scriptId : <scriptId>
sourceMapURL :
startColumn : 0
......
......@@ -32,10 +32,7 @@ var module4 = '}';
InspectorTest.setupScriptMap();
// We get scriptParsed events for modules ..
Protocol.Debugger.onScriptParsed(message => {
if (message.params.url === 'wait-pending-tasks.js') return;
InspectorTest.logMessage(message);
});
Protocol.Debugger.onScriptParsed(InspectorTest.logMessage);
// .. scriptFailed to parse for modules with syntax error ..
Protocol.Debugger.onScriptFailedToParse(InspectorTest.logMessage);
// .. API messages from modules contain correct stack trace ..
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment