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

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

Issue 871893002: Script streaming: Test that streaming <-> harmony scopes interaction is correct. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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
« no previous file with comments | « no previous file | 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 24138 matching lines...) Expand 10 before | Expand all | Expand 10 after
24149 v8::ScriptCompiler::StreamedSource source(new TestSourceStream(chunks), 24149 v8::ScriptCompiler::StreamedSource source(new TestSourceStream(chunks),
24150 encoding); 24150 encoding);
24151 v8::ScriptCompiler::ScriptStreamingTask* task = 24151 v8::ScriptCompiler::ScriptStreamingTask* task =
24152 v8::ScriptCompiler::StartStreamingScript(isolate, &source); 24152 v8::ScriptCompiler::StartStreamingScript(isolate, &source);
24153 24153
24154 // TestSourceStream::GetMoreData won't block, so it's OK to just run the 24154 // TestSourceStream::GetMoreData won't block, so it's OK to just run the
24155 // task here in the main thread. 24155 // task here in the main thread.
24156 task->Run(); 24156 task->Run();
24157 delete task; 24157 delete task;
24158 24158
24159 // Possible errors are only produced while compiling.
marja 2015/01/23 09:49:51 Cleanup: moved these lines because it's logical to
24160 CHECK_EQ(false, try_catch.HasCaught());
24161
24159 v8::ScriptOrigin origin(v8_str("http://foo.com")); 24162 v8::ScriptOrigin origin(v8_str("http://foo.com"));
24160 char* full_source = TestSourceStream::FullSourceString(chunks); 24163 char* full_source = TestSourceStream::FullSourceString(chunks);
24161
24162 // The possible errors are only produced while compiling.
24163 CHECK_EQ(false, try_catch.HasCaught());
24164
24165 v8::Handle<Script> script = v8::ScriptCompiler::Compile( 24164 v8::Handle<Script> script = v8::ScriptCompiler::Compile(
24166 isolate, &source, v8_str(full_source), origin); 24165 isolate, &source, v8_str(full_source), origin);
24167 if (expected_success) { 24166 if (expected_success) {
24168 CHECK(!script.IsEmpty()); 24167 CHECK(!script.IsEmpty());
24169 v8::Handle<Value> result(script->Run()); 24168 v8::Handle<Value> result(script->Run());
24170 // All scripts are supposed to return the fixed value 13 when ran. 24169 // All scripts are supposed to return the fixed value 13 when ran.
24171 CHECK_EQ(13, result->Int32Value()); 24170 CHECK_EQ(13, result->Int32Value());
24172 CheckMagicComments(script, expected_source_url, 24171 CheckMagicComments(script, expected_source_url,
24173 expected_source_mapping_url); 24172 expected_source_mapping_url);
24174 } else { 24173 } else {
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
24496 " return foob\xec\x92\x81\xec\x92\x81r;\n" 24495 " return foob\xec\x92\x81\xec\x92\x81r;\n"
24497 "}\n"; 24496 "}\n";
24498 chunk1[strlen(chunk1) - 1] = reference[0]; 24497 chunk1[strlen(chunk1) - 1] = reference[0];
24499 chunk2[0] = reference[1]; 24498 chunk2[0] = reference[1];
24500 chunk2[1] = reference[2]; 24499 chunk2[1] = reference[2];
24501 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 24500 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
24502 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 24501 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
24503 } 24502 }
24504 24503
24505 24504
24505 TEST(StreamingWithHarmonyScopes) {
24506 // Don't use RunStreamingTest here so that both scripts get to use the same
24507 // LocalContext and HandleScope.
24508 LocalContext env;
24509 v8::Isolate* isolate = env->GetIsolate();
24510 v8::HandleScope scope(isolate);
24511
24512 // First, run a script with a let variable.
24513 CompileRun("\"use strict\"; let x = 1;");
24514
24515 // Then stream a script which (erroneously) tries to introduce the same
24516 // variable again.
24517 const char* chunks[] = {"\"use strict\"; let x = 2;", NULL};
24518
24519 v8::TryCatch try_catch;
24520 v8::ScriptCompiler::StreamedSource source(
24521 new TestSourceStream(chunks),
24522 v8::ScriptCompiler::StreamedSource::ONE_BYTE);
24523 v8::ScriptCompiler::ScriptStreamingTask* task =
24524 v8::ScriptCompiler::StartStreamingScript(isolate, &source);
24525 task->Run();
24526 delete task;
24527
24528 // Parsing should succeed (the script will be parsed and compiled in a context
24529 // independent way, so the error is not detected).
24530 CHECK_EQ(false, try_catch.HasCaught());
24531
24532 v8::ScriptOrigin origin(v8_str("http://foo.com"));
24533 char* full_source = TestSourceStream::FullSourceString(chunks);
24534 v8::Handle<Script> script = v8::ScriptCompiler::Compile(
24535 isolate, &source, v8_str(full_source), origin);
24536 CHECK(!script.IsEmpty());
24537 CHECK_EQ(false, try_catch.HasCaught());
24538
24539 // Running the script exposes the error.
24540 v8::Handle<Value> result(script->Run());
24541 CHECK(result.IsEmpty());
24542 CHECK(try_catch.HasCaught());
24543 delete[] full_source;
24544 }
24545
24546
24506 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) { 24547 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) {
24507 const char* garbage = "garbage garbage garbage garbage."; 24548 const char* garbage = "garbage garbage garbage garbage.";
24508 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage); 24549 const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage);
24509 int length = 16; 24550 int length = 16;
24510 v8::ScriptCompiler::CachedData* cached_data = 24551 v8::ScriptCompiler::CachedData* cached_data =
24511 new v8::ScriptCompiler::CachedData(data, length); 24552 new v8::ScriptCompiler::CachedData(data, length);
24512 DCHECK(!cached_data->rejected); 24553 DCHECK(!cached_data->rejected);
24513 v8::ScriptOrigin origin(v8_str("origin")); 24554 v8::ScriptOrigin origin(v8_str("origin"));
24514 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data); 24555 v8::ScriptCompiler::Source source(v8_str("42"), origin, cached_data);
24515 v8::Handle<v8::Script> script = 24556 v8::Handle<v8::Script> script =
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
24716 "bar2.js"); 24757 "bar2.js");
24717 } 24758 }
24718 24759
24719 24760
24720 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) { 24761 TEST(StreamingScriptWithSourceMappingURLInTheMiddle) {
24721 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#", 24762 const char* chunks[] = {"function foo() { ret", "urn 13; }\n//#",
24722 " sourceMappingURL=bar2.js\n", "foo();", NULL}; 24763 " sourceMappingURL=bar2.js\n", "foo();", NULL};
24723 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL, 24764 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8, true, NULL,
24724 "bar2.js"); 24765 "bar2.js");
24725 } 24766 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698