Commit cedc11ba authored by sergeyv's avatar sergeyv Committed by Commit bot

Fix sourceURL & sourceMapURL handling in case of background parsing

BUG=

Review URL: https://codereview.chromium.org/821723002

Cr-Commit-Position: refs/heads/master@{#25980}
parent d1c1a3c4
......@@ -1780,6 +1780,7 @@ Local<Script> ScriptCompiler::Compile(Isolate* v8_isolate,
// Do the parsing tasks which need to be done on the main thread. This will
// also handle parse errors.
source->parser->Internalize();
source->parser->HandleSourceURLComments();
i::Handle<i::SharedFunctionInfo> result =
i::Handle<i::SharedFunctionInfo>::null();
......
......@@ -682,6 +682,7 @@ class Parser : public ParserBase<ParserTraits> {
// Handle errors detected during parsing, move statistics to Isolate,
// internalize strings (move them to the heap).
void Internalize();
void HandleSourceURLComments();
private:
friend class ParserTraits;
......@@ -879,8 +880,6 @@ class Parser : public ParserBase<ParserTraits> {
const AstRawString* function_name, int pos, Variable* fvar,
Token::Value fvar_init_op, bool is_generator, bool* ok);
void HandleSourceURLComments();
void ThrowPendingError();
TemplateLiteralState OpenTemplateLiteral(int pos);
......
......@@ -23999,10 +23999,8 @@ TEST(ScriptNameAndLineNumber) {
CHECK_EQ(13, line_number);
}
void SourceURLHelper(const char* source, const char* expected_source_url,
const char* expected_source_mapping_url) {
Local<Script> script = v8_compile(source);
void CheckMagicComments(Handle<Script> script, const char* expected_source_url,
const char* expected_source_mapping_url) {
if (expected_source_url != NULL) {
v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL());
CHECK_EQ(expected_source_url, *url);
......@@ -24018,6 +24016,12 @@ void SourceURLHelper(const char* source, const char* expected_source_url,
}
}
void SourceURLHelper(const char* source, const char* expected_source_url,
const char* expected_source_mapping_url) {
Local<Script> script = v8_compile(source);
CheckMagicComments(script, expected_source_url, expected_source_mapping_url);
}
TEST(ScriptSourceURLAndSourceMappingURL) {
LocalContext env;
......@@ -24209,7 +24213,9 @@ class TestSourceStream : public v8::ScriptCompiler::ExternalSourceStream {
void RunStreamingTest(const char** chunks,
v8::ScriptCompiler::StreamedSource::Encoding encoding =
v8::ScriptCompiler::StreamedSource::ONE_BYTE,
bool expected_success = true) {
bool expected_success = true,
const char* expected_source_url = NULL,
const char* expected_source_mapping_url = NULL) {
LocalContext env;
v8::Isolate* isolate = env->GetIsolate();
v8::HandleScope scope(isolate);
......@@ -24238,6 +24244,8 @@ void RunStreamingTest(const char** chunks,
v8::Handle<Value> result(script->Run());
// All scripts are supposed to return the fixed value 13 when ran.
CHECK_EQ(13, result->Int32Value());
CheckMagicComments(script, expected_source_url,
expected_source_mapping_url);
} else {
CHECK(script.IsEmpty());
CHECK(try_catch.HasCaught());
......@@ -24727,3 +24735,27 @@ TEST(ClassPrototypeCreationContext) {
CompileRun("'use strict'; class Example { }; Example.prototype"));
CHECK(env.local() == result->CreationContext());
}
TEST(SimpleStreamingScriptWithSourceURL) {
const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo();\n",
"//# sourceURL=bar2.js\n", NULL};
RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true,
"bar2.js");
}
TEST(StreamingScriptWithSplitSourceURL) {
const char* chunks[] = {"function foo() { ret", "urn 13; } f",
"oo();\n//# sourceURL=b", "ar2.js\n", NULL};
RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true,
"bar2.js");
}
TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#",
" sourceMappingURL=bar2.js\n", "foo();", NULL};
RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL,
"bar2.js");
}
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