Index: test/cctest/test-api.cc |
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc |
index 31a83f3e435e19b0c255cc95edf1523574734ffe..c445258388b43c28a861679060ac67e866a3492f 100644 |
--- a/test/cctest/test-api.cc |
+++ b/test/cctest/test-api.cc |
@@ -23436,7 +23436,9 @@ TEST(FunctionCallOptimization) { |
} |
-static void EmptyCallback(const v8::FunctionCallbackInfo<v8::Value>& info) {} |
+static void Returns42(const v8::FunctionCallbackInfo<v8::Value>& info) { |
+ info.GetReturnValue().Set(42); |
+} |
TEST(FunctionCallOptimizationMultipleArgs) { |
@@ -23445,7 +23447,7 @@ TEST(FunctionCallOptimizationMultipleArgs) { |
v8::Isolate* isolate = context->GetIsolate(); |
v8::HandleScope scope(isolate); |
Handle<Object> global = context->Global(); |
- Local<v8::Function> function = Function::New(isolate, EmptyCallback); |
+ Local<v8::Function> function = Function::New(isolate, Returns42); |
global->Set(v8_str("x"), function); |
CompileRun( |
"function x_wrap() {\n" |
@@ -23485,6 +23487,150 @@ TEST(ApiCallbackCanReturnSymbols) { |
} |
+TEST(EmptyApiCallback) { |
+ LocalContext context; |
+ auto isolate = context->GetIsolate(); |
+ v8::HandleScope scope(isolate); |
+ auto global = context->Global(); |
+ auto function = FunctionTemplate::New(isolate)->GetFunction(); |
+ global->Set(v8_str("x"), function); |
+ |
+ auto result = CompileRun("x()"); |
+ CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); |
+ |
+ result = CompileRun("x(1,2,3)"); |
+ CHECK(v8::Utils::OpenHandle(*result)->IsJSGlobalProxy()); |
+ |
+ result = CompileRun("7 + x.call(3) + 11"); |
+ CHECK(result->IsInt32()); |
+ CHECK_EQ(21, result->Int32Value()); |
+ |
+ result = CompileRun("7 + x.call(3, 101, 102, 103, 104) + 11"); |
+ CHECK(result->IsInt32()); |
+ CHECK_EQ(21, result->Int32Value()); |
+ |
+ result = CompileRun("var y = []; x.call(y)"); |
+ CHECK(result->IsArray()); |
+ |
+ result = CompileRun("x.call(y, 1, 2, 3, 4)"); |
+ CHECK(result->IsArray()); |
+} |
+ |
+ |
+TEST(SimpleSignatureCheck) { |
+ LocalContext context; |
+ auto isolate = context->GetIsolate(); |
+ v8::HandleScope scope(isolate); |
+ auto global = context->Global(); |
+ auto sig_obj = FunctionTemplate::New(isolate); |
+ auto sig = v8::Signature::New(isolate, sig_obj); |
+ auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); |
+ global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); |
+ global->Set(v8_str("x"), x->GetFunction()); |
+ CompileRun("var s = new sig_obj();"); |
+ { |
+ TryCatch try_catch(isolate); |
+ CompileRun("x()"); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ CompileRun("x.call(1)"); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ auto result = CompileRun("s.x = x; s.x()"); |
+ CHECK(!try_catch.HasCaught()); |
+ CHECK_EQ(42, result->Int32Value()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ auto result = CompileRun("x.call(s)"); |
+ CHECK(!try_catch.HasCaught()); |
+ CHECK_EQ(42, result->Int32Value()); |
+ } |
+} |
+ |
+ |
+TEST(ChainSignatureCheck) { |
+ LocalContext context; |
+ auto isolate = context->GetIsolate(); |
+ v8::HandleScope scope(isolate); |
+ auto global = context->Global(); |
+ auto sig_obj = FunctionTemplate::New(isolate); |
+ auto sig = v8::Signature::New(isolate, sig_obj); |
+ for (int i = 0; i < 4; ++i) { |
+ auto temp = FunctionTemplate::New(isolate); |
+ temp->Inherit(sig_obj); |
+ sig_obj = temp; |
+ } |
+ auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); |
+ global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); |
+ global->Set(v8_str("x"), x->GetFunction()); |
+ CompileRun("var s = new sig_obj();"); |
+ { |
+ TryCatch try_catch(isolate); |
+ CompileRun("x()"); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ CompileRun("x.call(1)"); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ auto result = CompileRun("s.x = x; s.x()"); |
+ CHECK(!try_catch.HasCaught()); |
+ CHECK_EQ(42, result->Int32Value()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ auto result = CompileRun("x.call(s)"); |
+ CHECK(!try_catch.HasCaught()); |
+ CHECK_EQ(42, result->Int32Value()); |
+ } |
+} |
+ |
+ |
+TEST(PrototypeSignatureCheck) { |
+ LocalContext context; |
+ auto isolate = context->GetIsolate(); |
+ v8::HandleScope scope(isolate); |
+ auto global = context->Global(); |
+ auto sig_obj = FunctionTemplate::New(isolate); |
+ sig_obj->SetHiddenPrototype(true); |
+ auto sig = v8::Signature::New(isolate, sig_obj); |
+ auto x = FunctionTemplate::New(isolate, Returns42, Handle<Value>(), sig); |
+ global->Set(v8_str("sig_obj"), sig_obj->GetFunction()); |
+ global->Set(v8_str("x"), x->GetFunction()); |
+ CompileRun("s = {}; s.__proto__ = new sig_obj();"); |
+ { |
+ TryCatch try_catch(isolate); |
+ CompileRun("x()"); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ CompileRun("x.call(1)"); |
+ CHECK(try_catch.HasCaught()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ auto result = CompileRun("s.x = x; s.x()"); |
+ CHECK(!try_catch.HasCaught()); |
+ CHECK_EQ(42, result->Int32Value()); |
+ } |
+ { |
+ TryCatch try_catch(isolate); |
+ auto result = CompileRun("x.call(s)"); |
+ CHECK(!try_catch.HasCaught()); |
+ CHECK_EQ(42, result->Int32Value()); |
+ } |
+} |
+ |
+ |
static const char* last_event_message; |
static int last_event_status; |
void StoringEventLoggerCallback(const char* message, int status) { |