Reviewers: yurys,
Message:
On 2014/12/23 12:32:22, yurys wrote:
Looks fine but needs a test.
Tests were added
Description:
Fix sourceURL & sourceMapURL handling in case of background parsing
BUG=
Please review this at https://codereview.chromium.org/821723002/
Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+39, -7 lines):
M src/api.cc
M src/parser.h
M test/cctest/test-api.cc
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
dfb452b2a2707f1a697cc248bcff8b8a3c995b84..4c7c4b9bbedd62453d4d3a1874b6ed9b2fd62109
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -1820,6 +1820,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();
Index: src/parser.h
diff --git a/src/parser.h b/src/parser.h
index
1650cba52123278ef9a61affa38e4890ce57ea89..fad70cf680c7fce055e3bbb6d4d0025eb52c8942
100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -639,6 +639,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;
@@ -823,8 +824,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();
Scanner scanner_;
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index
98c17dea2d860948cc6c5b7b8c7842fe12640f78..1b6c13348eccc7c17697f52496607792a58a5497
100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -23678,10 +23678,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);
@@ -23697,6 +23695,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;
@@ -23888,7 +23892,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);
@@ -23917,6 +23923,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());
@@ -24207,3 +24215,27 @@
TEST(StreamingUtf8ScriptWithMultipleMultibyteCharactersSomeSplit2) {
const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
}
+
+
+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");
+}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.