From 2b3381aec601a711e70518999ea17425df46a94c Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 2 Mar 2017 13:19:25 +0100 Subject: [PATCH] Revert "v8: drop v8::FunctionCallbackInfo::NewTarget()" See the commit log of the reverted commit: it's a semver-minor change that can land in the next minor release. This reverts commit 47cbb88ac5929ce6ba17f681785034dd019ce063. --- deps/v8/include/v8.h | 7 +++++++ deps/v8/test/cctest/test-api.cc | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/deps/v8/include/v8.h b/deps/v8/include/v8.h index c842b01587961d..ec45c91d77e728 100644 --- a/deps/v8/include/v8.h +++ b/deps/v8/include/v8.h @@ -3177,6 +3177,7 @@ class FunctionCallbackInfo { Local Callee() const); V8_INLINE Local This() const; V8_INLINE Local Holder() const; + V8_INLINE Local NewTarget() const; V8_INLINE bool IsConstructCall() const; V8_INLINE Local Data() const; V8_INLINE Isolate* GetIsolate() const; @@ -7903,6 +7904,12 @@ Local FunctionCallbackInfo::Holder() const { &implicit_args_[kHolderIndex])); } +template +Local FunctionCallbackInfo::NewTarget() const { + return Local( + reinterpret_cast(&implicit_args_[kNewTargetIndex])); +} + template Local FunctionCallbackInfo::Data() const { return Local(reinterpret_cast(&implicit_args_[kDataIndex])); diff --git a/deps/v8/test/cctest/test-api.cc b/deps/v8/test/cctest/test-api.cc index e27f469e0c0aef..a44239c244f4a5 100644 --- a/deps/v8/test/cctest/test-api.cc +++ b/deps/v8/test/cctest/test-api.cc @@ -13350,6 +13350,43 @@ THREADED_TEST(IsConstructCall) { CHECK(value->BooleanValue(context.local()).FromJust()); } +static void NewTargetHandler(const v8::FunctionCallbackInfo& args) { + ApiTestFuzzer::Fuzz(); + args.GetReturnValue().Set(args.NewTarget()); +} + +THREADED_TEST(NewTargetHandler) { + v8::Isolate* isolate = CcTest::isolate(); + v8::HandleScope scope(isolate); + + // Function template with call handler. + Local templ = v8::FunctionTemplate::New(isolate); + templ->SetCallHandler(NewTargetHandler); + + LocalContext context; + + Local function = + templ->GetFunction(context.local()).ToLocalChecked(); + CHECK(context->Global() + ->Set(context.local(), v8_str("f"), function) + .FromJust()); + Local value = CompileRun("f()"); + CHECK(value->IsUndefined()); + value = CompileRun("new f()"); + CHECK(value->IsFunction()); + CHECK(value == function); + Local subclass = CompileRun("var g = class extends f { }; g"); + CHECK(subclass->IsFunction()); + value = CompileRun("new g()"); + CHECK(value->IsFunction()); + CHECK(value == subclass); + value = CompileRun("Reflect.construct(f, [], Array)"); + CHECK(value->IsFunction()); + CHECK(value == + context->Global() + ->Get(context.local(), v8_str("Array")) + .ToLocalChecked()); +} THREADED_TEST(ObjectProtoToString) { v8::Isolate* isolate = CcTest::isolate();