Skip to content

Commit

Permalink
test: CallbackInfo NewTarget() basic coverage (#1048)
Browse files Browse the repository at this point in the history
  • Loading branch information
petersandor authored and JckXia committed Jul 31, 2022
1 parent 1dfd03b commit 134961d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<Function>();
Expand Down Expand Up @@ -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"] =
Expand Down Expand Up @@ -271,6 +277,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 134961d

Please sign in to comment.