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

Unified Diff: test/cctest/test-compiler.cc

Issue 910683002: Introduce a compile method that takes context extensions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: updates Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-compiler.cc
diff --git a/test/cctest/test-compiler.cc b/test/cctest/test-compiler.cc
index e19c979d32a6f680f10e2cb8f5a0390879f3ed57..6efab9963f5d1bc4afc23fc433896a47f11d382f 100644
--- a/test/cctest/test-compiler.cc
+++ b/test/cctest/test-compiler.cc
@@ -404,6 +404,61 @@ TEST(OptimizedCodeSharing) {
}
+TEST(CompileFunctionInContext) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ CompileRun("var r = 10;");
+ v8::Local<v8::Object> math =
+ v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("Math")));
+ v8::ScriptCompiler::Source script_source(v8_str(
+ "a = PI * r * r;"
+ "x = r * cos(PI);"
+ "y = r * sin(PI / 2);"));
+ v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 1, &math);
+ CHECK(!fun.IsEmpty());
+ fun->Call(env->Global(), 0, NULL);
+ CHECK(env->Global()->Has(v8_str("a")));
+ v8::Local<v8::Value> a = env->Global()->Get(v8_str("a"));
+ CHECK(a->IsNumber());
+ CHECK(env->Global()->Has(v8_str("x")));
+ v8::Local<v8::Value> x = env->Global()->Get(v8_str("x"));
+ CHECK(x->IsNumber());
+ CHECK(env->Global()->Has(v8_str("y")));
+ v8::Local<v8::Value> y = env->Global()->Get(v8_str("y"));
+ CHECK(y->IsNumber());
+ CHECK_EQ(314.1592653589793, a->NumberValue());
+ CHECK_EQ(-10.0, x->NumberValue());
+ CHECK_EQ(10.0, y->NumberValue());
+}
+
+
+TEST(CompileFunctionInContextComplex) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ CompileRun(
+ "var x = 1;"
+ "var y = 2;"
+ "var z = 4;"
+ "var a = {x: 8, y: 16};"
+ "var b = {x: 32};");
+ v8::Local<v8::Object> ext[2];
+ ext[0] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
+ ext[1] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("b")));
+ v8::ScriptCompiler::Source script_source(v8_str("result = x + y + z"));
+ v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 2, ext);
+ CHECK(!fun.IsEmpty());
+ fun->Call(env->Global(), 0, NULL);
+ CHECK(env->Global()->Has(v8_str("result")));
+ v8::Local<v8::Value> result = env->Global()->Get(v8_str("result"));
+ CHECK(result->IsNumber());
+ CHECK_EQ(52.0, result->NumberValue());
+}
+
+
#ifdef ENABLE_DISASSEMBLER
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj,
const char* property_name) {
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698