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

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

Issue 925433002: Make it possible to define arguments for CompileFunctionInContext (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 6efab9963f5d1bc4afc23fc433896a47f11d382f..faf533239e504b0b411c49b6f97175b50653faf6 100644
--- a/test/cctest/test-compiler.cc
+++ b/test/cctest/test-compiler.cc
@@ -416,7 +416,7 @@ TEST(CompileFunctionInContext) {
"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);
+ CcTest::isolate(), &script_source, env.local(), 0, NULL, 1, &math);
CHECK(!fun.IsEmpty());
fun->Call(env->Global(), 0, NULL);
CHECK(env->Global()->Has(v8_str("a")));
@@ -449,7 +449,7 @@ TEST(CompileFunctionInContextComplex) {
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);
+ CcTest::isolate(), &script_source, env.local(), 0, NULL, 2, ext);
CHECK(!fun.IsEmpty());
fun->Call(env->Global(), 0, NULL);
CHECK(env->Global()->Has(v8_str("result")));
@@ -459,6 +459,61 @@ TEST(CompileFunctionInContextComplex) {
}
+TEST(CompileFunctionInContextArgs) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ CompileRun("var a = {x: 23};");
+ v8::Local<v8::Object> ext[1];
+ ext[0] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
+ v8::ScriptCompiler::Source script_source(v8_str("result = x + b"));
+ v8::Local<v8::String> arg = v8_str("b");
+ v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 1, &arg, 1, ext);
+ CHECK(!fun.IsEmpty());
+ v8::Local<v8::Value> b_value = v8::Number::New(CcTest::isolate(), 42.0);
+ fun->Call(env->Global(), 1, &b_value);
+ CHECK(env->Global()->Has(v8_str("result")));
+ v8::Local<v8::Value> result = env->Global()->Get(v8_str("result"));
+ CHECK(result->IsNumber());
+ CHECK_EQ(65.0, result->NumberValue());
+}
+
+
+TEST(CompileFunctionInContextComments) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ CompileRun("var a = {x: 23, y: 1, z: 2};");
+ v8::Local<v8::Object> ext[1];
+ ext[0] = v8::Local<v8::Object>::Cast(env->Global()->Get(v8_str("a")));
+ v8::ScriptCompiler::Source script_source(
+ v8_str("result = /* y + */ x + b // + z"));
+ v8::Local<v8::String> arg = v8_str("b");
+ v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 1, &arg, 1, ext);
+ CHECK(!fun.IsEmpty());
+ v8::Local<v8::Value> b_value = v8::Number::New(CcTest::isolate(), 42.0);
+ fun->Call(env->Global(), 1, &b_value);
+ CHECK(env->Global()->Has(v8_str("result")));
+ v8::Local<v8::Value> result = env->Global()->Get(v8_str("result"));
+ CHECK(result->IsNumber());
+ CHECK_EQ(65.0, result->NumberValue());
+}
+
+
+TEST(CompileFunctionInContextNonIdentifierArgs) {
+ CcTest::InitializeVM();
+ v8::HandleScope scope(CcTest::isolate());
+ LocalContext env;
+ v8::ScriptCompiler::Source script_source(v8_str("result = 1"));
+ v8::Local<v8::String> arg = v8_str("b }");
+ v8::Local<v8::Function> fun = v8::ScriptCompiler::CompileFunctionInContext(
+ CcTest::isolate(), &script_source, env.local(), 1, &arg, 0, NULL);
+ CHECK(fun.IsEmpty());
+}
+
+
#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