Commit 65dcbb2a authored by Alexey Kozyatinskiy's avatar Alexey Kozyatinskiy Committed by Commit Bot

[DevTools] Any module scripts should have correct start position

Modules generate fake script to report an import exception, this fake script should have correct start_position.

Bug: chromium:721589
Change-Id: Iac2aa91b9269210d39e834c5467e6ae071cce1e4
Reviewed-on: https://chromium-review.googlesource.com/521143Reviewed-by: default avatarKouhei Ueno <kouhei@chromium.org>
Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Commit-Queue: Aleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476418}
parent 7ea0aaca
CONSOLE ERROR: line 5: Uncaught SyntaxError: The requested module does not provide an export named 'x'
CONSOLE ERROR: line 5: Uncaught SyntaxError: The requested module does not provide an export named 'x'
Tests lineNumber for import error inside of inline module.
Script execution paused.
line 4, content: <script type="module">
Script execution resumed.
<html>
<head>
<script src="../inspector-test.js"></script>
<script src="../debugger-test.js"></script>
<script type="module">
import {x} from "./resources/empty-module.js";
</script>
<script>
var test = function()
{
InspectorTest.startDebuggerTest(step1);
function step1()
{
InspectorTest.DebuggerAgent.setPauseOnExceptions(SDK.DebuggerModel.PauseOnExceptionsState.PauseOnAllExceptions);
InspectorTest.waitUntilPaused(step2);
InspectorTest.reloadPage();
}
function step2()
{
var callFrames = InspectorTest.debuggerModel.callFrames;
var frame = callFrames[0];
var uiLocation = Bindings.debuggerWorkspaceBinding.rawLocationToUILocation(frame.location());
InspectorTest.showUISourceCode(uiLocation.uiSourceCode, dumpCallFrameLine);
function dumpCallFrameLine(sourceFrame)
{
var resourceText = sourceFrame._textEditor.text();
var lines = resourceText.split("\n");
var lineNumber = uiLocation.lineNumber;
InspectorTest.addResult("line " + lineNumber + ", content: " + lines[lineNumber]);
InspectorTest.completeDebuggerTest();
}
}
}
</script>
</head>
<body onload="runTest()">
<p>Tests lineNumber for import error inside of inline module.</p>
</body>
</html>
...@@ -101,7 +101,8 @@ void ScriptModule::Evaluate(ScriptState* script_state) const { ...@@ -101,7 +101,8 @@ void ScriptModule::Evaluate(ScriptState* script_state) const {
void ScriptModule::ReportException(ScriptState* script_state, void ScriptModule::ReportException(ScriptState* script_state,
v8::Local<v8::Value> exception, v8::Local<v8::Value> exception,
const String& file_name) { const String& file_name,
const TextPosition& start_position) {
// We ensure module-related code is not executed without the flag. // We ensure module-related code is not executed without the flag.
// https://crbug.com/715376 // https://crbug.com/715376
CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled()); CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
...@@ -111,7 +112,8 @@ void ScriptModule::ReportException(ScriptState* script_state, ...@@ -111,7 +112,8 @@ void ScriptModule::ReportException(ScriptState* script_state,
v8::TryCatch try_catch(isolate); v8::TryCatch try_catch(isolate);
try_catch.SetVerbose(true); try_catch.SetVerbose(true);
V8ScriptRunner::ReportExceptionForModule(isolate, exception, file_name); V8ScriptRunner::ReportExceptionForModule(isolate, exception, file_name,
start_position);
} }
Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) { Vector<String> ScriptModule::ModuleRequests(ScriptState* script_state) {
......
...@@ -46,7 +46,8 @@ class CORE_EXPORT ScriptModule final { ...@@ -46,7 +46,8 @@ class CORE_EXPORT ScriptModule final {
void Evaluate(ScriptState*) const; void Evaluate(ScriptState*) const;
static void ReportException(ScriptState*, static void ReportException(ScriptState*,
v8::Local<v8::Value> exception, v8::Local<v8::Value> exception,
const String& file_name); const String& file_name,
const TextPosition& start_position);
Vector<String> ModuleRequests(ScriptState*); Vector<String> ModuleRequests(ScriptState*);
......
...@@ -521,17 +521,19 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule( ...@@ -521,17 +521,19 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
return v8::ScriptCompiler::CompileModule(isolate, &script_source); return v8::ScriptCompiler::CompileModule(isolate, &script_source);
} }
void V8ScriptRunner::ReportExceptionForModule(v8::Isolate* isolate, void V8ScriptRunner::ReportExceptionForModule(
v8::Local<v8::Value> exception, v8::Isolate* isolate,
const String& file_name) { v8::Local<v8::Value> exception,
const String& file_name,
const TextPosition& start_position) {
// |origin| is for compiling a fragment that throws |exception|. // |origin| is for compiling a fragment that throws |exception|.
// Therefore |is_module| is false and |access_control_status| is // Therefore |is_module| is false and |access_control_status| is
// kSharableCrossOrigin. // kSharableCrossOrigin.
AccessControlStatus access_control_status = kSharableCrossOrigin; AccessControlStatus access_control_status = kSharableCrossOrigin;
v8::ScriptOrigin origin( v8::ScriptOrigin origin(
V8String(isolate, file_name), V8String(isolate, file_name),
v8::Integer::New(isolate, 0), // line_offset v8::Integer::New(isolate, start_position.line_.ZeroBasedInt()),
v8::Integer::New(isolate, 0), // col_offset v8::Integer::New(isolate, start_position.column_.ZeroBasedInt()),
v8::Boolean::New(isolate, access_control_status == kSharableCrossOrigin), v8::Boolean::New(isolate, access_control_status == kSharableCrossOrigin),
v8::Local<v8::Integer>(), // script id v8::Local<v8::Integer>(), // script id
v8::String::Empty(isolate), // source_map_url v8::String::Empty(isolate), // source_map_url
......
...@@ -120,7 +120,8 @@ class CORE_EXPORT V8ScriptRunner final { ...@@ -120,7 +120,8 @@ class CORE_EXPORT V8ScriptRunner final {
// Only to be used from ScriptModule::ReportException(). // Only to be used from ScriptModule::ReportException().
static void ReportExceptionForModule(v8::Isolate*, static void ReportExceptionForModule(v8::Isolate*,
v8::Local<v8::Value> exception, v8::Local<v8::Value> exception,
const String& file_name); const String& file_name,
const TextPosition&);
static uint32_t TagForParserCache(CachedMetadataHandler*); static uint32_t TagForParserCache(CachedMetadataHandler*);
static uint32_t TagForCodeCache(CachedMetadataHandler*); static uint32_t TagForCodeCache(CachedMetadataHandler*);
......
...@@ -195,7 +195,7 @@ void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) { ...@@ -195,7 +195,7 @@ void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) {
ScriptModule::ReportException( ScriptModule::ReportException(
script_state_.Get(), script_state_.Get(),
module_script->CreateInstantiationErrorInternal(isolate), module_script->CreateInstantiationErrorInternal(isolate),
module_script->BaseURL().GetString()); module_script->BaseURL().GetString(), module_script->StartPosition());
return; return;
} }
......
...@@ -35,7 +35,7 @@ ModuleScript* ModuleScript::Create( ...@@ -35,7 +35,7 @@ ModuleScript* ModuleScript::Create(
return nullptr; return nullptr;
return CreateInternal(source_text, modulator, result, base_url, nonce, return CreateInternal(source_text, modulator, result, base_url, nonce,
parser_state, credentials_mode); parser_state, credentials_mode, start_position);
} }
ModuleScript* ModuleScript::CreateInternal( ModuleScript* ModuleScript::CreateInternal(
...@@ -45,7 +45,8 @@ ModuleScript* ModuleScript::CreateInternal( ...@@ -45,7 +45,8 @@ ModuleScript* ModuleScript::CreateInternal(
const KURL& base_url, const KURL& base_url,
const String& nonce, const String& nonce,
ParserDisposition parser_state, ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode) { WebURLRequest::FetchCredentialsMode credentials_mode,
const TextPosition& start_position) {
// https://html.spec.whatwg.org/#creating-a-module-script // https://html.spec.whatwg.org/#creating-a-module-script
// Step 7. Set script's module record to result. // Step 7. Set script's module record to result.
// Step 8. Set script's base URL to the script base URL provided. // Step 8. Set script's base URL to the script base URL provided.
...@@ -57,7 +58,7 @@ ModuleScript* ModuleScript::CreateInternal( ...@@ -57,7 +58,7 @@ ModuleScript* ModuleScript::CreateInternal(
// [not specced] |source_text| is saved for CSP checks. // [not specced] |source_text| is saved for CSP checks.
ModuleScript* module_script = ModuleScript* module_script =
new ModuleScript(modulator, result, base_url, nonce, parser_state, new ModuleScript(modulator, result, base_url, nonce, parser_state,
credentials_mode, source_text); credentials_mode, source_text, start_position);
// Step 5, a part of ParseModule(): Passing script as the last parameter // Step 5, a part of ParseModule(): Passing script as the last parameter
// here ensures result.[[HostDefined]] will be script. // here ensures result.[[HostDefined]] will be script.
...@@ -75,7 +76,8 @@ ModuleScript* ModuleScript::CreateForTest( ...@@ -75,7 +76,8 @@ ModuleScript* ModuleScript::CreateForTest(
WebURLRequest::FetchCredentialsMode credentials_mode) { WebURLRequest::FetchCredentialsMode credentials_mode) {
String dummy_source_text = ""; String dummy_source_text = "";
return CreateInternal(dummy_source_text, modulator, record, base_url, nonce, return CreateInternal(dummy_source_text, modulator, record, base_url, nonce,
parser_state, credentials_mode); parser_state, credentials_mode,
TextPosition::MinimumPosition());
} }
ModuleScript::ModuleScript(Modulator* settings_object, ModuleScript::ModuleScript(Modulator* settings_object,
...@@ -84,7 +86,8 @@ ModuleScript::ModuleScript(Modulator* settings_object, ...@@ -84,7 +86,8 @@ ModuleScript::ModuleScript(Modulator* settings_object,
const String& nonce, const String& nonce,
ParserDisposition parser_state, ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode, WebURLRequest::FetchCredentialsMode credentials_mode,
const String& source_text) const String& source_text,
const TextPosition& start_position)
: settings_object_(settings_object), : settings_object_(settings_object),
record_(this), record_(this),
base_url_(base_url), base_url_(base_url),
...@@ -92,7 +95,8 @@ ModuleScript::ModuleScript(Modulator* settings_object, ...@@ -92,7 +95,8 @@ ModuleScript::ModuleScript(Modulator* settings_object,
nonce_(nonce), nonce_(nonce),
parser_state_(parser_state), parser_state_(parser_state),
credentials_mode_(credentials_mode), credentials_mode_(credentials_mode),
source_text_(source_text) { source_text_(source_text),
start_position_(start_position) {
if (record.IsNull()) { if (record.IsNull()) {
// We allow empty records for module infra tests which never touch records. // We allow empty records for module infra tests which never touch records.
// This should never happen outside unit tests. // This should never happen outside unit tests.
......
...@@ -77,6 +77,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ...@@ -77,6 +77,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
} }
const String& Nonce() const { return nonce_; } const String& Nonce() const { return nonce_; }
const TextPosition& StartPosition() const { return start_position_; }
DECLARE_TRACE(); DECLARE_TRACE();
DECLARE_TRACE_WRAPPERS(); DECLARE_TRACE_WRAPPERS();
...@@ -87,7 +89,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ...@@ -87,7 +89,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
const String& nonce, const String& nonce,
ParserDisposition parser_state, ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode, WebURLRequest::FetchCredentialsMode credentials_mode,
const String& source_text); const String& source_text,
const TextPosition& start_position);
static ModuleScript* CreateInternal(const String& source_text, static ModuleScript* CreateInternal(const String& source_text,
Modulator*, Modulator*,
...@@ -95,7 +98,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ...@@ -95,7 +98,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
const KURL& base_url, const KURL& base_url,
const String& nonce, const String& nonce,
ParserDisposition, ParserDisposition,
WebURLRequest::FetchCredentialsMode); WebURLRequest::FetchCredentialsMode,
const TextPosition&);
ScriptType GetScriptType() const override { return ScriptType::kModule; } ScriptType GetScriptType() const override { return ScriptType::kModule; }
bool IsEmpty() const override; bool IsEmpty() const override;
...@@ -147,6 +151,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase { ...@@ -147,6 +151,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
// For CSP check. // For CSP check.
const String source_text_; const String source_text_;
const TextPosition start_position_;
}; };
} // namespace blink } // namespace blink
......
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