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 {
void ScriptModule::ReportException(ScriptState* script_state,
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.
// https://crbug.com/715376
CHECK(RuntimeEnabledFeatures::moduleScriptsEnabled());
......@@ -111,7 +112,8 @@ void ScriptModule::ReportException(ScriptState* script_state,
v8::TryCatch try_catch(isolate);
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) {
......
......@@ -46,7 +46,8 @@ class CORE_EXPORT ScriptModule final {
void Evaluate(ScriptState*) const;
static void ReportException(ScriptState*,
v8::Local<v8::Value> exception,
const String& file_name);
const String& file_name,
const TextPosition& start_position);
Vector<String> ModuleRequests(ScriptState*);
......
......@@ -521,17 +521,19 @@ v8::MaybeLocal<v8::Module> V8ScriptRunner::CompileModule(
return v8::ScriptCompiler::CompileModule(isolate, &script_source);
}
void V8ScriptRunner::ReportExceptionForModule(v8::Isolate* isolate,
v8::Local<v8::Value> exception,
const String& file_name) {
void V8ScriptRunner::ReportExceptionForModule(
v8::Isolate* isolate,
v8::Local<v8::Value> exception,
const String& file_name,
const TextPosition& start_position) {
// |origin| is for compiling a fragment that throws |exception|.
// Therefore |is_module| is false and |access_control_status| is
// kSharableCrossOrigin.
AccessControlStatus access_control_status = kSharableCrossOrigin;
v8::ScriptOrigin origin(
V8String(isolate, file_name),
v8::Integer::New(isolate, 0), // line_offset
v8::Integer::New(isolate, 0), // col_offset
v8::Integer::New(isolate, start_position.line_.ZeroBasedInt()),
v8::Integer::New(isolate, start_position.column_.ZeroBasedInt()),
v8::Boolean::New(isolate, access_control_status == kSharableCrossOrigin),
v8::Local<v8::Integer>(), // script id
v8::String::Empty(isolate), // source_map_url
......
......@@ -120,7 +120,8 @@ class CORE_EXPORT V8ScriptRunner final {
// Only to be used from ScriptModule::ReportException().
static void ReportExceptionForModule(v8::Isolate*,
v8::Local<v8::Value> exception,
const String& file_name);
const String& file_name,
const TextPosition&);
static uint32_t TagForParserCache(CachedMetadataHandler*);
static uint32_t TagForCodeCache(CachedMetadataHandler*);
......
......@@ -195,7 +195,7 @@ void ModulatorImpl::ExecuteModule(const ModuleScript* module_script) {
ScriptModule::ReportException(
script_state_.Get(),
module_script->CreateInstantiationErrorInternal(isolate),
module_script->BaseURL().GetString());
module_script->BaseURL().GetString(), module_script->StartPosition());
return;
}
......
......@@ -35,7 +35,7 @@ ModuleScript* ModuleScript::Create(
return nullptr;
return CreateInternal(source_text, modulator, result, base_url, nonce,
parser_state, credentials_mode);
parser_state, credentials_mode, start_position);
}
ModuleScript* ModuleScript::CreateInternal(
......@@ -45,7 +45,8 @@ ModuleScript* ModuleScript::CreateInternal(
const KURL& base_url,
const String& nonce,
ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode) {
WebURLRequest::FetchCredentialsMode credentials_mode,
const TextPosition& start_position) {
// https://html.spec.whatwg.org/#creating-a-module-script
// Step 7. Set script's module record to result.
// Step 8. Set script's base URL to the script base URL provided.
......@@ -57,7 +58,7 @@ ModuleScript* ModuleScript::CreateInternal(
// [not specced] |source_text| is saved for CSP checks.
ModuleScript* module_script =
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
// here ensures result.[[HostDefined]] will be script.
......@@ -75,7 +76,8 @@ ModuleScript* ModuleScript::CreateForTest(
WebURLRequest::FetchCredentialsMode credentials_mode) {
String dummy_source_text = "";
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,
......@@ -84,7 +86,8 @@ ModuleScript::ModuleScript(Modulator* settings_object,
const String& nonce,
ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode,
const String& source_text)
const String& source_text,
const TextPosition& start_position)
: settings_object_(settings_object),
record_(this),
base_url_(base_url),
......@@ -92,7 +95,8 @@ ModuleScript::ModuleScript(Modulator* settings_object,
nonce_(nonce),
parser_state_(parser_state),
credentials_mode_(credentials_mode),
source_text_(source_text) {
source_text_(source_text),
start_position_(start_position) {
if (record.IsNull()) {
// We allow empty records for module infra tests which never touch records.
// This should never happen outside unit tests.
......
......@@ -77,6 +77,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
}
const String& Nonce() const { return nonce_; }
const TextPosition& StartPosition() const { return start_position_; }
DECLARE_TRACE();
DECLARE_TRACE_WRAPPERS();
......@@ -87,7 +89,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
const String& nonce,
ParserDisposition parser_state,
WebURLRequest::FetchCredentialsMode credentials_mode,
const String& source_text);
const String& source_text,
const TextPosition& start_position);
static ModuleScript* CreateInternal(const String& source_text,
Modulator*,
......@@ -95,7 +98,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
const KURL& base_url,
const String& nonce,
ParserDisposition,
WebURLRequest::FetchCredentialsMode);
WebURLRequest::FetchCredentialsMode,
const TextPosition&);
ScriptType GetScriptType() const override { return ScriptType::kModule; }
bool IsEmpty() const override;
......@@ -147,6 +151,8 @@ class CORE_EXPORT ModuleScript final : public Script, public TraceWrapperBase {
// For CSP check.
const String source_text_;
const TextPosition start_position_;
};
} // 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