Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: test/cctest/test-api.cc

Issue 821723002: Fix sourceURL & sourceMapURL handling in case of background parsing (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebase Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 23981 matching lines...) Expand 10 before | Expand all | Expand 10 after
23992 isolate, &script_source); 23992 isolate, &script_source);
23993 Local<Value> script_name = script->GetUnboundScript()->GetScriptName(); 23993 Local<Value> script_name = script->GetUnboundScript()->GetScriptName();
23994 CHECK(!script_name.IsEmpty()); 23994 CHECK(!script_name.IsEmpty());
23995 CHECK(script_name->IsString()); 23995 CHECK(script_name->IsString());
23996 String::Utf8Value utf8_name(script_name); 23996 String::Utf8Value utf8_name(script_name);
23997 CHECK_EQ(url, *utf8_name); 23997 CHECK_EQ(url, *utf8_name);
23998 int line_number = script->GetUnboundScript()->GetLineNumber(0); 23998 int line_number = script->GetUnboundScript()->GetLineNumber(0);
23999 CHECK_EQ(13, line_number); 23999 CHECK_EQ(13, line_number);
24000 } 24000 }
24001 24001
24002 24002 void CheckMagicComments(Handle<Script> script, const char* expected_source_url,
24003 void SourceURLHelper(const char* source, const char* expected_source_url, 24003 const char* expected_source_mapping_url) {
24004 const char* expected_source_mapping_url) {
24005 Local<Script> script = v8_compile(source);
24006 if (expected_source_url != NULL) { 24004 if (expected_source_url != NULL) {
24007 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL()); 24005 v8::String::Utf8Value url(script->GetUnboundScript()->GetSourceURL());
24008 CHECK_EQ(expected_source_url, *url); 24006 CHECK_EQ(expected_source_url, *url);
24009 } else { 24007 } else {
24010 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined()); 24008 CHECK(script->GetUnboundScript()->GetSourceURL()->IsUndefined());
24011 } 24009 }
24012 if (expected_source_mapping_url != NULL) { 24010 if (expected_source_mapping_url != NULL) {
24013 v8::String::Utf8Value url( 24011 v8::String::Utf8Value url(
24014 script->GetUnboundScript()->GetSourceMappingURL()); 24012 script->GetUnboundScript()->GetSourceMappingURL());
24015 CHECK_EQ(expected_source_mapping_url, *url); 24013 CHECK_EQ(expected_source_mapping_url, *url);
24016 } else { 24014 } else {
24017 CHECK(script->GetUnboundScript()->GetSourceMappingURL()->IsUndefined()); 24015 CHECK(script->GetUnboundScript()->GetSourceMappingURL()->IsUndefined());
24018 } 24016 }
24019 } 24017 }
24020 24018
24019 void SourceURLHelper(const char* source, const char* expected_source_url,
24020 const char* expected_source_mapping_url) {
24021 Local<Script> script = v8_compile(source);
24022 CheckMagicComments(script, expected_source_url, expected_source_mapping_url);
24023 }
24024
24021 24025
24022 TEST(ScriptSourceURLAndSourceMappingURL) { 24026 TEST(ScriptSourceURLAndSourceMappingURL) {
24023 LocalContext env; 24027 LocalContext env;
24024 v8::Isolate* isolate = env->GetIsolate(); 24028 v8::Isolate* isolate = env->GetIsolate();
24025 v8::HandleScope scope(isolate); 24029 v8::HandleScope scope(isolate);
24026 SourceURLHelper("function foo() {}\n" 24030 SourceURLHelper("function foo() {}\n"
24027 "//# sourceURL=bar1.js\n", "bar1.js", NULL); 24031 "//# sourceURL=bar1.js\n", "bar1.js", NULL);
24028 SourceURLHelper("function foo() {}\n" 24032 SourceURLHelper("function foo() {}\n"
24029 "//# sourceMappingURL=bar2.js\n", NULL, "bar2.js"); 24033 "//# sourceMappingURL=bar2.js\n", NULL, "bar2.js");
24030 24034
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
24202 private: 24206 private:
24203 const char** chunks_; 24207 const char** chunks_;
24204 unsigned index_; 24208 unsigned index_;
24205 }; 24209 };
24206 24210
24207 24211
24208 // Helper function for running streaming tests. 24212 // Helper function for running streaming tests.
24209 void RunStreamingTest(const char** chunks, 24213 void RunStreamingTest(const char** chunks,
24210 v8::ScriptCompiler::StreamedSource::Encoding encoding = 24214 v8::ScriptCompiler::StreamedSource::Encoding encoding =
24211 v8::ScriptCompiler::StreamedSource::ONE_BYTE, 24215 v8::ScriptCompiler::StreamedSource::ONE_BYTE,
24212 bool expected_success = true) { 24216 bool expected_success = true,
24217 const char* expected_source_url = NULL,
24218 const char* expected_source_mapping_url = NULL) {
24213 LocalContext env; 24219 LocalContext env;
24214 v8::Isolate* isolate = env->GetIsolate(); 24220 v8::Isolate* isolate = env->GetIsolate();
24215 v8::HandleScope scope(isolate); 24221 v8::HandleScope scope(isolate);
24216 v8::TryCatch try_catch; 24222 v8::TryCatch try_catch;
24217 24223
24218 v8::ScriptCompiler::StreamedSource source(new TestSourceStream(chunks), 24224 v8::ScriptCompiler::StreamedSource source(new TestSourceStream(chunks),
24219 encoding); 24225 encoding);
24220 v8::ScriptCompiler::ScriptStreamingTask* task = 24226 v8::ScriptCompiler::ScriptStreamingTask* task =
24221 v8::ScriptCompiler::StartStreamingScript(isolate, &source); 24227 v8::ScriptCompiler::StartStreamingScript(isolate, &source);
24222 24228
24223 // TestSourceStream::GetMoreData won't block, so it's OK to just run the 24229 // TestSourceStream::GetMoreData won't block, so it's OK to just run the
24224 // task here in the main thread. 24230 // task here in the main thread.
24225 task->Run(); 24231 task->Run();
24226 delete task; 24232 delete task;
24227 24233
24228 v8::ScriptOrigin origin(v8_str("http://foo.com")); 24234 v8::ScriptOrigin origin(v8_str("http://foo.com"));
24229 char* full_source = TestSourceStream::FullSourceString(chunks); 24235 char* full_source = TestSourceStream::FullSourceString(chunks);
24230 24236
24231 // The possible errors are only produced while compiling. 24237 // The possible errors are only produced while compiling.
24232 CHECK_EQ(false, try_catch.HasCaught()); 24238 CHECK_EQ(false, try_catch.HasCaught());
24233 24239
24234 v8::Handle<Script> script = v8::ScriptCompiler::Compile( 24240 v8::Handle<Script> script = v8::ScriptCompiler::Compile(
24235 isolate, &source, v8_str(full_source), origin); 24241 isolate, &source, v8_str(full_source), origin);
24236 if (expected_success) { 24242 if (expected_success) {
24237 CHECK(!script.IsEmpty()); 24243 CHECK(!script.IsEmpty());
24238 v8::Handle<Value> result(script->Run()); 24244 v8::Handle<Value> result(script->Run());
24239 // All scripts are supposed to return the fixed value 13 when ran. 24245 // All scripts are supposed to return the fixed value 13 when ran.
24240 CHECK_EQ(13, result->Int32Value()); 24246 CHECK_EQ(13, result->Int32Value());
24247 CheckMagicComments(script, expected_source_url,
24248 expected_source_mapping_url);
24241 } else { 24249 } else {
24242 CHECK(script.IsEmpty()); 24250 CHECK(script.IsEmpty());
24243 CHECK(try_catch.HasCaught()); 24251 CHECK(try_catch.HasCaught());
24244 } 24252 }
24245 delete[] full_source; 24253 delete[] full_source;
24246 } 24254 }
24247 24255
24248 24256
24249 TEST(StreamingSimpleScript) { 24257 TEST(StreamingSimpleScript) {
24250 // This script is unrealistically small, since no one chunk is enough to fill 24258 // This script is unrealistically small, since no one chunk is enough to fill
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
24720 TEST(ClassPrototypeCreationContext) { 24728 TEST(ClassPrototypeCreationContext) {
24721 i::FLAG_harmony_classes = true; 24729 i::FLAG_harmony_classes = true;
24722 v8::Isolate* isolate = CcTest::isolate(); 24730 v8::Isolate* isolate = CcTest::isolate();
24723 v8::HandleScope handle_scope(isolate); 24731 v8::HandleScope handle_scope(isolate);
24724 LocalContext env; 24732 LocalContext env;
24725 24733
24726 Handle<Object> result = Handle<Object>::Cast( 24734 Handle<Object> result = Handle<Object>::Cast(
24727 CompileRun("'use strict'; class Example { }; Example.prototype")); 24735 CompileRun("'use strict'; class Example { }; Example.prototype"));
24728 CHECK(env.local() == result->CreationContext()); 24736 CHECK(env.local() == result->CreationContext());
24729 } 24737 }
24738
24739
24740 TEST(SimpleStreamingScriptWithSourceURL) {
24741 const char* chunks[] = {"function foo() { ret", "urn 13; } f", "oo();\n",
24742 "//# sourceURL=bar2.js\n", NULL};
24743 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true,
24744 "bar2.js");
24745 }
24746
24747
24748 TEST(StreamingScriptWithSplitSourceURL) {
24749 const char* chunks[] = {"function foo() { ret", "urn 13; } f",
24750 "oo();\n//# sourceURL=b", "ar2.js\n", NULL};
24751 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true,
24752 "bar2.js");
24753 }
24754
24755
24756 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
24757 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#",
24758 " sourceMappingURL=bar2.js\n", "foo();", NULL};
24759 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL,
24760 "bar2.js");
24761 }
OLDNEW
« no previous file with comments | « src/parser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698