Add an API test for v8::ScriptData::PreCompile() to make sure
authoriposva@chromium.org <iposva@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 18 Nov 2008 07:32:38 +0000 (07:32 +0000)
committeriposva@chromium.org <iposva@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 18 Nov 2008 07:32:38 +0000 (07:32 +0000)
that v8::V8::Initialize() does not have to be called to allow
pre-compilation. Currently this test would fail, which is
why a workaround has been applied and a bug filed.

Review URL: http://codereview.chromium.org/11441

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@779 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

test/cctest/test-api.cc

index 6b44dda..82dac25 100644 (file)
@@ -5274,3 +5274,17 @@ THREADED_TEST(ExternalSymbols) {
   value = CompileRun("obj.externalSymbol722 = 42");
   v8::V8::SetExternalSymbolCallback(NULL);
 }
+
+
+// This test verifies that pre-compilation (aka preparsing) can be called
+// without initializing the whole VM. Thus we cannot run this test in a
+// multi-threaded setup.
+TEST(PreCompile) {
+  // TODO(155): This test would break without the initialization of V8. This is
+  // a workaround for now to make this test not fail.
+  v8::V8::Initialize();
+  const char *script = "function foo(a) { return a+1; }";
+  v8::ScriptData *sd = v8::ScriptData::PreCompile(script, strlen(script));
+  CHECK_NE(sd->Length(), 0);
+  CHECK_NE(sd->Data(), NULL);
+}