Skip to content

Commit

Permalink
test: CallbackInfo NewTarget() basic coverage (nodejs#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
petersandor committed May 10, 2022
1 parent d53843b commit 6bd67e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ void IsConstructCall(const CallbackInfo& info) {
callback({Napi::Boolean::New(info.Env(), isConstructCall)});
}

Value NewTargetCallback(const CallbackInfo& info) {
Value newTarget = info.NewTarget();
return newTarget;
}

void MakeCallbackWithArgs(const CallbackInfo& info) {
Env env = info.Env();
Function callback = info[0].As<Function>();
Expand Down Expand Up @@ -232,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"] =
Expand Down Expand Up @@ -265,6 +272,8 @@ Object InitFunction(Env env) {
exports["voidCallback"] = Function::New<VoidCallback>(env, "voidCallback");
exports["valueCallback"] =
Function::New<ValueCallback>(env, std::string("valueCallback"));
exports["newTargetCallback"] =
Function::New<NewTargetCallback>(env, std::string("newTargetCallback"));
exports["voidCallbackWithData"] =
Function::New<VoidCallbackWithData>(env, nullptr, &testData);
exports["valueCallbackWithData"] =
Expand Down
4 changes: 4 additions & 0 deletions test/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 6bd67e7

Please sign in to comment.