Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(487)

Unified Diff: test/cctest/test-api.cc

Issue 1910253005: [api] Expose FunctionCallbackInfo::NewTarget (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Added a TODO Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/x64/code-stubs-x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-api.cc
diff --git a/test/cctest/test-api.cc b/test/cctest/test-api.cc
index 86a2ddd9cdf932f55355d376753a4dab6afedf67..5d8d5b50e553683e1f99ade0ea75d23b1c03531f 100644
--- a/test/cctest/test-api.cc
+++ b/test/cctest/test-api.cc
@@ -13221,6 +13221,43 @@ THREADED_TEST(IsConstructCall) {
CHECK(value->BooleanValue(context.local()).FromJust());
}
+static void NewTargetHandler(const v8::FunctionCallbackInfo<v8::Value>& 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<v8::FunctionTemplate> templ = v8::FunctionTemplate::New(isolate);
+ templ->SetCallHandler(NewTargetHandler);
+
+ LocalContext context;
+
+ Local<Function> function =
+ templ->GetFunction(context.local()).ToLocalChecked();
+ CHECK(context->Global()
+ ->Set(context.local(), v8_str("f"), function)
+ .FromJust());
+ Local<Value> value = CompileRun("f()");
+ CHECK(value->IsUndefined());
+ value = CompileRun("new f()");
+ CHECK(value->IsFunction());
+ CHECK(value == function);
+ Local<Value> 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();
« no previous file with comments | « src/x64/code-stubs-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698