@@ -13350,6 +13350,43 @@ THREADED_TEST(IsConstructCall) {
13350
13350
CHECK(value->BooleanValue(context.local()).FromJust());
13351
13351
}
13352
13352
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
+ }
13353
13390
13354
13391
THREADED_TEST(ObjectProtoToString) {
13355
13392
v8::Isolate* isolate = CcTest::isolate();
0 commit comments