From c65799e7c509bd21ce8e2817827ddf51d71e8c94 Mon Sep 17 00:00:00 2001 From: jochen Date: Wed, 14 Jan 2015 06:43:58 -0800 Subject: [PATCH] Remove support for signatures with arguments Support for it is slow and difficult to implement, and it's not used in Blink. An embedder that uses this feature will have to check the argument types itself. BUG=none R=dcarney@chromium.org LOG=y Review URL: https://codereview.chromium.org/848173002 Cr-Commit-Position: refs/heads/master@{#26058} --- include/v8.h | 16 +++++----- src/api.cc | 21 ++++++++++--- test/cctest/test-api.cc | 81 ------------------------------------------------- 3 files changed, 26 insertions(+), 92 deletions(-) diff --git a/include/v8.h b/include/v8.h index e3d5254..ca19e05 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4099,16 +4099,18 @@ class V8_EXPORT ObjectTemplate : public Template { /** - * A Signature specifies which receivers and arguments are valid - * parameters to a function. + * A Signature specifies which receiver is valid for a function. */ class V8_EXPORT Signature : public Data { public: - static Local New(Isolate* isolate, - Handle receiver = - Handle(), - int argc = 0, - Handle argv[] = 0); + V8_DEPRECATED("An embedder needs to check the arguments itself", + static Local New( + Isolate* isolate, Handle receiver, + int argc, Handle argv[] = 0)); + + static Local New( + Isolate* isolate, + Handle receiver = Handle()); private: Signature(); diff --git a/src/api.cc b/src/api.cc index 03d79a5..3f6e109 100644 --- a/src/api.cc +++ b/src/api.cc @@ -856,11 +856,8 @@ Local Signature::New(Isolate* isolate, i::Isolate* i_isolate = reinterpret_cast(isolate); LOG_API(i_isolate, "Signature::New"); ENTER_V8(i_isolate); - i::Handle struct_obj = - i_isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); i::Handle obj = - i::Handle::cast(struct_obj); - if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); + Utils::OpenHandle(*Signature::New(isolate, receiver)); if (argc > 0) { i::Handle args = i_isolate->factory()->NewFixedArray(argc); for (int i = 0; i < argc; i++) { @@ -873,6 +870,22 @@ Local Signature::New(Isolate* isolate, } +Local Signature::New(Isolate* isolate, + Handle receiver) { + i::Isolate* i_isolate = reinterpret_cast(isolate); + LOG_API(i_isolate, "Signature::New"); + ENTER_V8(i_isolate); + i::Handle struct_obj = + i_isolate->factory()->NewStruct(i::SIGNATURE_INFO_TYPE); + // TODO(jochen): Replace SignatureInfo with FunctionTemplateInfo once the + // deprecated API is deleted. + i::Handle obj = + i::Handle::cast(struct_obj); + if (!receiver.IsEmpty()) obj->set_receiver(*Utils::OpenHandle(*receiver)); + return Utils::ToLocal(obj); +} + + Local AccessorSignature::New( Isolate* isolate, Handle receiver) { diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc index e62b0ed..dac6935 100644 --- a/test/cctest/test-api.cc +++ b/test/cctest/test-api.cc @@ -117,18 +117,6 @@ static void IncrementingSignatureCallback( } -static void SignatureCallback( - const v8::FunctionCallbackInfo& args) { - ApiTestFuzzer::Fuzz(); - v8::Handle result = - v8::Array::New(args.GetIsolate(), args.Length()); - for (int i = 0; i < args.Length(); i++) { - result->Set(v8::Integer::New(args.GetIsolate(), i), args[i]); - } - args.GetReturnValue().Set(result); -} - - // Tests that call v8::V8::Dispose() cannot be threaded. UNINITIALIZED_TEST(InitializeAndDisposeOnce) { CHECK(v8::V8::Initialize()); @@ -283,75 +271,6 @@ THREADED_TEST(ReceiverSignature) { } -THREADED_TEST(ArgumentSignature) { - LocalContext env; - v8::Isolate* isolate = env->GetIsolate(); - v8::HandleScope scope(isolate); - v8::Handle cons = v8::FunctionTemplate::New(isolate); - cons->SetClassName(v8_str("Cons")); - v8::Handle sig = v8::Signature::New( - isolate, v8::Handle(), 1, &cons); - v8::Handle fun = - v8::FunctionTemplate::New(isolate, - SignatureCallback, - v8::Handle(), - sig); - env->Global()->Set(v8_str("Cons"), cons->GetFunction()); - env->Global()->Set(v8_str("Fun1"), fun->GetFunction()); - - v8::Handle value1 = CompileRun("Fun1(4) == '';"); - CHECK(value1->IsTrue()); - - v8::Handle value2 = CompileRun("Fun1(new Cons()) == '[object Cons]';"); - CHECK(value2->IsTrue()); - - v8::Handle value3 = CompileRun("Fun1() == '';"); - CHECK(value3->IsTrue()); - - v8::Handle cons1 = v8::FunctionTemplate::New(isolate); - cons1->SetClassName(v8_str("Cons1")); - v8::Handle cons2 = v8::FunctionTemplate::New(isolate); - cons2->SetClassName(v8_str("Cons2")); - v8::Handle cons3 = v8::FunctionTemplate::New(isolate); - cons3->SetClassName(v8_str("Cons3")); - - v8::Handle args[3] = { cons1, cons2, cons3 }; - v8::Handle wsig = v8::Signature::New( - isolate, v8::Handle(), 3, args); - v8::Handle fun2 = - v8::FunctionTemplate::New(isolate, - SignatureCallback, - v8::Handle(), - wsig); - - env->Global()->Set(v8_str("Cons1"), cons1->GetFunction()); - env->Global()->Set(v8_str("Cons2"), cons2->GetFunction()); - env->Global()->Set(v8_str("Cons3"), cons3->GetFunction()); - env->Global()->Set(v8_str("Fun2"), fun2->GetFunction()); - v8::Handle value4 = CompileRun( - "Fun2(new Cons1(), new Cons2(), new Cons3()) ==" - "'[object Cons1],[object Cons2],[object Cons3]'"); - CHECK(value4->IsTrue()); - - v8::Handle value5 = CompileRun( - "Fun2(new Cons1(), new Cons2(), 5) == '[object Cons1],[object Cons2],'"); - CHECK(value5->IsTrue()); - - v8::Handle value6 = CompileRun( - "Fun2(new Cons3(), new Cons2(), new Cons1()) == ',[object Cons2],'"); - CHECK(value6->IsTrue()); - - v8::Handle value7 = CompileRun( - "Fun2(new Cons1(), new Cons2(), new Cons3(), 'd') == " - "'[object Cons1],[object Cons2],[object Cons3],d';"); - CHECK(value7->IsTrue()); - - v8::Handle value8 = CompileRun( - "Fun2(new Cons1(), new Cons2()) == '[object Cons1],[object Cons2]'"); - CHECK(value8->IsTrue()); -} - - THREADED_TEST(HulIgennem) { LocalContext env; v8::Isolate* isolate = env->GetIsolate(); -- 2.7.4