Index: test/cctest/test-compiler.cc |
diff --git a/test/cctest/test-compiler.cc b/test/cctest/test-compiler.cc |
index e19c979d32a6f680f10e2cb8f5a0390879f3ed57..290b4802bb47b856575355e011e5f01f1173040a 100644 |
--- a/test/cctest/test-compiler.cc |
+++ b/test/cctest/test-compiler.cc |
@@ -404,6 +404,36 @@ 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); |
Yang
2015/02/09 10:21:19
Would be nicer to have more than one extension obj
|
+ 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()); |
+} |
+ |
+ |
#ifdef ENABLE_DISASSEMBLER |
static Handle<JSFunction> GetJSFunction(v8::Handle<v8::Object> obj, |
const char* property_name) { |