Revision: 20003
Author:   [email protected]
Date:     Mon Mar 17 15:06:33 2014 UTC
Log: Add tests which ensure that the data produced by the preparser is really used.

[email protected]
BUG=

Review URL: https://codereview.chromium.org/201133005
http://code.google.com/p/v8/source/detail?r=20003

Modified:
 /branches/bleeding_edge/test/cctest/test-parsing.cc

=======================================
--- /branches/bleeding_edge/test/cctest/test-parsing.cc Mon Mar 17 10:21:01 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-parsing.cc Mon Mar 17 15:06:33 2014 UTC
@@ -258,6 +258,86 @@
   i::DeleteArray(message);
   delete error_preparse;
 }
+
+
+TEST(PreparseFunctionDataIsUsed) {
+  // This tests that we actually do use the function data generated by the
+  // preparser.
+  v8::Isolate* isolate = CcTest::isolate();
+  v8::HandleScope handles(isolate);
+  v8::Local<v8::Context> context = v8::Context::New(isolate);
+  v8::Context::Scope context_scope(context);
+  int marker;
+  CcTest::i_isolate()->stack_guard()->SetStackLimit(
+      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
+
+  const char* good_source =
+ "function this_is_lazy() { var a; } function foo() { return 25; } foo();";
+
+  // Insert a syntax error inside the lazy function.
+  const char* bad_source =
+ "function this_is_lazy() { if ( } function foo() { return 25; } foo();";
+
+ v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source));
+  CHECK(!preparse->HasError());
+
+ // Now compile the erroneous code with the good preparse data. If the preparse
+  // data is used, the lazy function is skipped and it should compile fine.
+  v8::ScriptCompiler::Source source(
+      v8_str(bad_source),
+      v8::ScriptCompiler::CachedData(
+          reinterpret_cast<const uint8_t*>(preparse->Data()),
+          preparse->Length()));
+  v8::Local<v8::Value> result =
+      v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run();
+  CHECK(result->IsInt32());
+  CHECK_EQ(25, result->Int32Value());
+  delete preparse;
+}
+
+
+TEST(PreparseSymbolDataIsUsed) {
+  // This tests that we actually do use the symbol data generated by the
+  // preparser.
+
+  // Only do one compilation pass in this test (otherwise we will parse the
+  // source code again without preparse data and it will fail).
+  i::FLAG_crankshaft = false;
+
+  v8::Isolate* isolate = CcTest::isolate();
+  v8::HandleScope handles(isolate);
+  v8::Local<v8::Context> context = v8::Context::New(isolate);
+  v8::Context::Scope context_scope(context);
+  int marker;
+  CcTest::i_isolate()->stack_guard()->SetStackLimit(
+      reinterpret_cast<uintptr_t>(&marker) - 128 * 1024);
+
+  // Note that the ( before function makes the
+  const char* good_source =
+      "(function weird() { var foo = 26; return foo; })()";
+
+ // Insert an undefined identifier. If the preparser data is used, the symbol + // stream is used instead, and this identifier resolves correctly to"foo".
+  const char* bad_source =
+      "(function weird() { var foo = 26; return wut; })()";
+
+ v8::ScriptData* preparse = v8::ScriptData::PreCompile(v8_str(good_source));
+  CHECK(!preparse->HasError());
+
+ // Now compile the erroneous code with the good preparse data. If the preparse
+  // data is used, we will see a second occurrence of "foo" instead of the
+  // unknown "wut".
+  v8::ScriptCompiler::Source source(
+      v8_str(bad_source),
+      v8::ScriptCompiler::CachedData(
+          reinterpret_cast<const uint8_t*>(preparse->Data()),
+          preparse->Length()));
+  v8::Local<v8::Value> result =
+      v8::ScriptCompiler::Compile(CcTest::isolate(), source)->Run();
+  CHECK(result->IsInt32());
+  CHECK_EQ(26, result->Int32Value());
+  delete preparse;
+}


 TEST(StandAlonePreParser) {

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