From: dcarney Date: Wed, 21 Jan 2015 13:42:35 +0000 (-0800) Subject: add some tests for HandleApiCall builtin X-Git-Tag: upstream/4.7.83~4850 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8521caba24679df2ec41d5885092e26b142c52eb;p=platform%2Fupstream%2Fv8.git add some tests for HandleApiCall builtin BUG= Review URL: https://codereview.chromium.org/861053003 Cr-Commit-Position: refs/heads/master@{#26190} --- diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index 59b39e1..3d06176 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -23435,7 +23435,9 @@ TEST(FunctionCallOptimization) { } -static void EmptyCallback(const v8::FunctionCallbackInfo& info) {} +static void Returns42(const v8::FunctionCallbackInfo& info) { + info.GetReturnValue().Set(42); +} TEST(FunctionCallOptimizationMultipleArgs) { @@ -23444,7 +23446,7 @@ TEST(FunctionCallOptimizationMultipleArgs) { v8::Isolate* isolate = context->GetIsolate(); v8::HandleScope scope(isolate); Handle global = context->Global(); - Local function = Function::New(isolate, EmptyCallback); + Local function = Function::New(isolate, Returns42); global->Set(v8_str("x"), function); CompileRun( "function x_wrap() {\n" @@ -23484,6 +23486,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(), 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(), 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(), 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) {