Skip to content

Commit 2b3381a

Browse files
bnoordhuisMylesBorins
authored andcommitted
Revert "v8: drop v8::FunctionCallbackInfo<T>::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 47cbb88.
1 parent 875674b commit 2b3381a

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

deps/v8/include/v8.h

+7
Original file line numberDiff line numberDiff line change
@@ -3177,6 +3177,7 @@ class FunctionCallbackInfo {
31773177
Local<Function> Callee() const);
31783178
V8_INLINE Local<Object> This() const;
31793179
V8_INLINE Local<Object> Holder() const;
3180+
V8_INLINE Local<Value> NewTarget() const;
31803181
V8_INLINE bool IsConstructCall() const;
31813182
V8_INLINE Local<Value> Data() const;
31823183
V8_INLINE Isolate* GetIsolate() const;
@@ -7903,6 +7904,12 @@ Local<Object> FunctionCallbackInfo<T>::Holder() const {
79037904
&implicit_args_[kHolderIndex]));
79047905
}
79057906

7907+
template<typename T>
7908+
Local<Value> FunctionCallbackInfo<T>::NewTarget() const {
7909+
return Local<Value>(
7910+
reinterpret_cast<Value*>(&implicit_args_[kNewTargetIndex]));
7911+
}
7912+
79067913
template<typename T>
79077914
Local<Value> FunctionCallbackInfo<T>::Data() const {
79087915
return Local<Value>(reinterpret_cast<Value*>(&implicit_args_[kDataIndex]));

deps/v8/test/cctest/test-api.cc

+37
Original file line numberDiff line numberDiff line change
@@ -13350,6 +13350,43 @@ THREADED_TEST(IsConstructCall) {
1335013350
CHECK(value->BooleanValue(context.local()).FromJust());
1335113351
}
1335213352

13353+
static void NewTargetHandler(const v8::FunctionCallbackInfo<v8::Value>& args) {
13354+
ApiTestFuzzer::Fuzz();
13355+
args.GetReturnValue().Set(args.NewTarget());
13356+
}
13357+
13358+
THREADED_TEST(NewTargetHandler) {
13359+
v8::Isolate* isolate = CcTest::isolate();
13360+
v8::HandleScope scope(isolate);
13361+
13362+
// Function template with call handler.
13363+
Local<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
13364+
templ->SetCallHandler(NewTargetHandler);
13365+
13366+
LocalContext context;
13367+
13368+
Local<Function> function =
13369+
templ->GetFunction(context.local()).ToLocalChecked();
13370+
CHECK(context->Global()
13371+
->Set(context.local(), v8_str("f"), function)
13372+
.FromJust());
13373+
Local<Value> value = CompileRun("f()");
13374+
CHECK(value->IsUndefined());
13375+
value = CompileRun("new f()");
13376+
CHECK(value->IsFunction());
13377+
CHECK(value == function);
13378+
Local<Value> subclass = CompileRun("var g = class extends f { }; g");
13379+
CHECK(subclass->IsFunction());
13380+
value = CompileRun("new g()");
13381+
CHECK(value->IsFunction());
13382+
CHECK(value == subclass);
13383+
value = CompileRun("Reflect.construct(f, [], Array)");
13384+
CHECK(value->IsFunction());
13385+
CHECK(value ==
13386+
context->Global()
13387+
->Get(context.local(), v8_str("Array"))
13388+
.ToLocalChecked());
13389+
}
1335313390

1335413391
THREADED_TEST(ObjectProtoToString) {
1335513392
v8::Isolate* isolate = CcTest::isolate();

0 commit comments

Comments
 (0)