diff --git a/test/function.cc b/test/function.cc index be5b3b9d6..5c1c6e163 100644 --- a/test/function.cc +++ b/test/function.cc @@ -167,6 +167,10 @@ void IsConstructCall(const CallbackInfo& info) { callback({Napi::Boolean::New(info.Env(), isConstructCall)}); } +Value NewTargetCallback(const CallbackInfo& info) { + return info.NewTarget(); +} + void MakeCallbackWithArgs(const CallbackInfo& info) { Env env = info.Env(); Function callback = info[0].As(); @@ -233,6 +237,8 @@ Object InitFunction(Env env) { Function::New(env, VoidCallbackWithData, nullptr, &testData); exports["valueCallbackWithData"] = Function::New(env, ValueCallbackWithData, nullptr, &testData); + exports["newTargetCallback"] = + Function::New(env, NewTargetCallback, std::string("newTargetCallback")); exports["callWithArgs"] = Function::New(env, CallWithArgs); exports["callWithVector"] = Function::New(env, CallWithVector); exports["callWithVectorUsingCppWrapper"] = @@ -271,6 +277,8 @@ Object InitFunction(Env env) { exports["voidCallback"] = Function::New(env, "voidCallback"); exports["valueCallback"] = Function::New(env, std::string("valueCallback")); + exports["newTargetCallback"] = + Function::New(env, std::string("newTargetCallback")); exports["voidCallbackWithData"] = Function::New(env, nullptr, &testData); exports["valueCallbackWithData"] = diff --git a/test/function.js b/test/function.js index bb5ed681b..04b020394 100644 --- a/test/function.js +++ b/test/function.js @@ -18,6 +18,10 @@ function test (binding) { assert.deepStrictEqual(binding.valueCallback(), { foo: 'bar' }); + /* eslint-disable-next-line no-new, new-cap */ + assert.strictEqual(new binding.newTargetCallback(), binding.newTargetCallback); + assert.strictEqual(binding.newTargetCallback(), undefined); + let args = null; let ret = null; let receiver = null;