Reviewers: Dmitry Lomov (chromium),

Message:
dslomov, ptal


https://codereview.chromium.org/871893002/diff/1/test/cctest/test-api.cc
File test/cctest/test-api.cc (right):

https://codereview.chromium.org/871893002/diff/1/test/cctest/test-api.cc#newcode24159
test/cctest/test-api.cc:24159: // Possible errors are only produced
while compiling.
Cleanup: moved these lines because it's logical to introduce full_source
right before it's needed.

Description:
Script streaming: Test that streaming <-> harmony scopes interaction is correct.

BUG=

Please review this at https://codereview.chromium.org/871893002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+45, -4 lines):
  M test/cctest/test-api.cc


Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 4d39aa543d6f79e96d1e5879f94d53638e1eebc4..017d3223c0c3943a7b4f261d799a7ce146d8a89d 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -24156,12 +24156,11 @@ void RunStreamingTest(const char** chunks,
   task->Run();
   delete task;

-  v8::ScriptOrigin origin(v8_str("http://foo.com";));
-  char* full_source = TestSourceStream::FullSourceString(chunks);
-
-  // The possible errors are only produced while compiling.
+  // Possible errors are only produced while compiling.
   CHECK_EQ(false, try_catch.HasCaught());

+  v8::ScriptOrigin origin(v8_str("http://foo.com";));
+  char* full_source = TestSourceStream::FullSourceString(chunks);
   v8::Handle<Script> script = v8::ScriptCompiler::Compile(
       isolate, &source, v8_str(full_source), origin);
   if (expected_success) {
@@ -24503,6 +24502,48 @@ TEST(StreamingUtf8ScriptWithMultipleMultibyteCharactersSomeSplit2) {
 }


+TEST(StreamingWithHarmonyScopes) {
+ // Don't use RunStreamingTest here so that both scripts get to use the same
+  // LocalContext and HandleScope.
+  LocalContext env;
+  v8::Isolate* isolate = env->GetIsolate();
+  v8::HandleScope scope(isolate);
+
+  // First, run a script with a let variable.
+  CompileRun("\"use strict\"; let x = 1;");
+
+  // Then stream a script which (erroneously) tries to introduce the same
+  // variable again.
+  const char* chunks[] = {"\"use strict\"; let x = 2;", NULL};
+
+  v8::TryCatch try_catch;
+  v8::ScriptCompiler::StreamedSource source(
+      new TestSourceStream(chunks),
+      v8::ScriptCompiler::StreamedSource::ONE_BYTE);
+  v8::ScriptCompiler::ScriptStreamingTask* task =
+      v8::ScriptCompiler::StartStreamingScript(isolate, &source);
+  task->Run();
+  delete task;
+
+ // Parsing should succeed (the script will be parsed and compiled in a context
+  // independent way, so the error is not detected).
+  CHECK_EQ(false, try_catch.HasCaught());
+
+  v8::ScriptOrigin origin(v8_str("http://foo.com";));
+  char* full_source = TestSourceStream::FullSourceString(chunks);
+  v8::Handle<Script> script = v8::ScriptCompiler::Compile(
+      isolate, &source, v8_str(full_source), origin);
+  CHECK(!script.IsEmpty());
+  CHECK_EQ(false, try_catch.HasCaught());
+
+  // Running the script exposes the error.
+  v8::Handle<Value> result(script->Run());
+  CHECK(result.IsEmpty());
+  CHECK(try_catch.HasCaught());
+  delete[] full_source;
+}
+
+
 void TestInvalidCacheData(v8::ScriptCompiler::CompileOptions option) {
   const char* garbage = "garbage garbage garbage garbage.";
   const uint8_t* data = reinterpret_cast<const uint8_t*>(garbage);


--
--
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.

Reply via email to