From 1a362a2784f44544ed126b795c49671b0a975eb5 Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 07:37:07 +0100 Subject: [PATCH 1/9] Add tests for Function constructors --- test/function.cc | 16 ++++++++++++++++ test/function.js | 3 +++ 2 files changed, 19 insertions(+) diff --git a/test/function.cc b/test/function.cc index b0ae92c7d..947a66d9a 100644 --- a/test/function.cc +++ b/test/function.cc @@ -6,6 +6,18 @@ namespace { int testData = 1; +Boolean EmptyConstructor(const CallbackInfo& info) { + auto env = info.Env(); + Function function = Function(); + return Boolean::New(env, function.IsEmpty()); +} + +Boolean NonEmptyConstructor(const CallbackInfo& info) { + auto env = info.Env(); + Function function = Function(env, Object::New(env)); + return Boolean::New(env, !function.IsEmpty()); +} + void VoidCallback(const CallbackInfo& info) { auto env = info.Env(); Object obj = info[0].As(); @@ -107,6 +119,8 @@ void IsConstructCall(const CallbackInfo& info) { Object InitFunction(Env env) { Object result = Object::New(env); Object exports = Object::New(env); + exports["emptyConstructor"] = Function::New(env, EmptyConstructor); + exports["nonEmptyConstructor"] = Function::New(env, NonEmptyConstructor); exports["voidCallback"] = Function::New(env, VoidCallback, "voidCallback"); exports["valueCallback"] = Function::New(env, ValueCallback, std::string("valueCallback")); exports["voidCallbackWithData"] = @@ -124,6 +138,8 @@ Object InitFunction(Env env) { result["plain"] = exports; exports = Object::New(env); + exports["emptyConstructor"] = Function::New(env, EmptyConstructor); + exports["nonEmptyConstructor"] = Function::New(env, NonEmptyConstructor); exports["voidCallback"] = Function::New(env, "voidCallback"); exports["valueCallback"] = Function::New(env, std::string("valueCallback")); diff --git a/test/function.js b/test/function.js index 8ab742c27..74a222a7c 100644 --- a/test/function.js +++ b/test/function.js @@ -8,6 +8,9 @@ test(require(`./build/${buildType}/binding.node`).function.templated); test(require(`./build/${buildType}/binding_noexcept.node`).function.templated); function test(binding) { + assert.strictEqual(binding.emptyConstructor(), true); + assert.strictEqual(binding.nonEmptyConstructor(), true); + let obj = {}; assert.deepStrictEqual(binding.voidCallback(obj), undefined); assert.deepStrictEqual(obj, { "foo": "bar" }); From 080aa8585e348fd273756731b69cac5a9ba3fac8 Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 07:48:10 +0100 Subject: [PATCH 2/9] Rename operator() test and add call with args test --- test/function.cc | 14 ++++++++++++-- test/function.js | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/test/function.cc b/test/function.cc index 947a66d9a..5793ef4cb 100644 --- a/test/function.cc +++ b/test/function.cc @@ -57,8 +57,9 @@ Value ValueCallbackWithData(const CallbackInfo& info) { } Value CallWithArgs(const CallbackInfo& info) { - Function func = info[0].As(); - return func({ info[1], info[2], info[3] }); + Function func = info[0].As(); + return func.Call( + std::initializer_list{info[1], info[2], info[3]}); } Value CallWithVector(const CallbackInfo& info) { @@ -114,6 +115,11 @@ void IsConstructCall(const CallbackInfo& info) { callback({Napi::Boolean::New(info.Env(), isConstructCall)}); } +Value CallWithFunctionOperator(const CallbackInfo& info) { + Function func = info[0].As(); + return func({ info[1], info[2], info[3] }); +} + } // end anonymous namespace Object InitFunction(Env env) { @@ -135,6 +141,8 @@ Object InitFunction(Env env) { exports["callConstructorWithArgs"] = Function::New(env, CallConstructorWithArgs); exports["callConstructorWithVector"] = Function::New(env, CallConstructorWithVector); exports["isConstructCall"] = Function::New(env, IsConstructCall); + exports["callWithFunctionOperator"] = + Function::New(env, CallWithFunctionOperator); result["plain"] = exports; exports = Object::New(env); @@ -160,6 +168,8 @@ Object InitFunction(Env env) { exports["callConstructorWithVector"] = Function::New(env); exports["isConstructCall"] = Function::New(env); + exports["callWithFunctionOperator"] = + Function::New(env); result["templated"] = exports; return result; } diff --git a/test/function.js b/test/function.js index 74a222a7c..0f7e0505c 100644 --- a/test/function.js +++ b/test/function.js @@ -49,6 +49,11 @@ function test(binding) { assert.deepStrictEqual(receiver, obj); assert.deepStrictEqual(args, [ 4, 5, 6 ]); + ret = 10; + assert.strictEqual(binding.callWithFunctionOperator(testFunction, 7, 8, 9), ret); + assert.strictEqual(receiver, undefined); + assert.deepStrictEqual(args, [ 7, 8, 9 ]); + assert.throws(() => { binding.callWithInvalidReceiver(); }, /Invalid (pointer passed as )?argument/); From b5006149a011faf57eb1b35b6e00ed1955533d88 Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 07:48:10 +0100 Subject: [PATCH 3/9] Rename Function::operator() test and add tests for Function::Call with args --- test/function.cc | 14 ++++++++++++-- test/function.js | 5 +++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/test/function.cc b/test/function.cc index 947a66d9a..042ab36f6 100644 --- a/test/function.cc +++ b/test/function.cc @@ -57,8 +57,9 @@ Value ValueCallbackWithData(const CallbackInfo& info) { } Value CallWithArgs(const CallbackInfo& info) { - Function func = info[0].As(); - return func({ info[1], info[2], info[3] }); + Function func = info[0].As(); + return func.Call( + std::initializer_list{info[1], info[2], info[3]}); } Value CallWithVector(const CallbackInfo& info) { @@ -114,6 +115,11 @@ void IsConstructCall(const CallbackInfo& info) { callback({Napi::Boolean::New(info.Env(), isConstructCall)}); } +Value CallWithFunctionOperator(const CallbackInfo& info) { + Function func = info[0].As(); + return func({info[1], info[2], info[3]}); +} + } // end anonymous namespace Object InitFunction(Env env) { @@ -135,6 +141,8 @@ Object InitFunction(Env env) { exports["callConstructorWithArgs"] = Function::New(env, CallConstructorWithArgs); exports["callConstructorWithVector"] = Function::New(env, CallConstructorWithVector); exports["isConstructCall"] = Function::New(env, IsConstructCall); + exports["callWithFunctionOperator"] = + Function::New(env, CallWithFunctionOperator); result["plain"] = exports; exports = Object::New(env); @@ -160,6 +168,8 @@ Object InitFunction(Env env) { exports["callConstructorWithVector"] = Function::New(env); exports["isConstructCall"] = Function::New(env); + exports["callWithFunctionOperator"] = + Function::New(env); result["templated"] = exports; return result; } diff --git a/test/function.js b/test/function.js index 74a222a7c..0f7e0505c 100644 --- a/test/function.js +++ b/test/function.js @@ -49,6 +49,11 @@ function test(binding) { assert.deepStrictEqual(receiver, obj); assert.deepStrictEqual(args, [ 4, 5, 6 ]); + ret = 10; + assert.strictEqual(binding.callWithFunctionOperator(testFunction, 7, 8, 9), ret); + assert.strictEqual(receiver, undefined); + assert.deepStrictEqual(args, [ 7, 8, 9 ]); + assert.throws(() => { binding.callWithInvalidReceiver(); }, /Invalid (pointer passed as )?argument/); From 46b38f55bca1f151a9d98f22d809838835b10bbb Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 08:01:22 +0100 Subject: [PATCH 4/9] Add tests for Function::Call with C style array --- test/function.cc | 12 ++++++++++++ test/function.js | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/test/function.cc b/test/function.cc index 042ab36f6..bc10c00b0 100644 --- a/test/function.cc +++ b/test/function.cc @@ -72,6 +72,16 @@ Value CallWithVector(const CallbackInfo& info) { return func.Call(args); } +Value CallWithCStyleArray(const CallbackInfo& info) { + Function func = info[0].As(); + std::vector args; + args.reserve(3); + args.push_back(info[1]); + args.push_back(info[2]); + args.push_back(info[3]); + return func.Call(args.size(), args.data()); +} + Value CallWithReceiverAndArgs(const CallbackInfo& info) { Function func = info[0].As(); Value receiver = info[1]; @@ -135,6 +145,7 @@ Object InitFunction(Env env) { Function::New(env, ValueCallbackWithData, nullptr, &testData); exports["callWithArgs"] = Function::New(env, CallWithArgs); exports["callWithVector"] = Function::New(env, CallWithVector); + exports["callWithCStyleArray"] = Function::New(env, CallWithCStyleArray); exports["callWithReceiverAndArgs"] = Function::New(env, CallWithReceiverAndArgs); exports["callWithReceiverAndVector"] = Function::New(env, CallWithReceiverAndVector); exports["callWithInvalidReceiver"] = Function::New(env, CallWithInvalidReceiver); @@ -157,6 +168,7 @@ Object InitFunction(Env env) { Function::New(env, nullptr, &testData); exports["callWithArgs"] = Function::New(env); exports["callWithVector"] = Function::New(env); + exports["callWithCStyleArray"] = Function::New(env); exports["callWithReceiverAndArgs"] = Function::New(env); exports["callWithReceiverAndVector"] = diff --git a/test/function.js b/test/function.js index 0f7e0505c..89b6b9d28 100644 --- a/test/function.js +++ b/test/function.js @@ -49,6 +49,11 @@ function test(binding) { assert.deepStrictEqual(receiver, obj); assert.deepStrictEqual(args, [ 4, 5, 6 ]); + ret = 8; + assert.strictEqual(binding.callWithCStyleArray(testFunction, 5, 6, 7), ret); + assert.deepStrictEqual(receiver, undefined); + assert.deepStrictEqual(args, [ 5, 6, 7 ]); + ret = 10; assert.strictEqual(binding.callWithFunctionOperator(testFunction, 7, 8, 9), ret); assert.strictEqual(receiver, undefined); From 25b5b6a02e6c881e5fc587f1e15a8d70d072dd8c Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 08:05:51 +0100 Subject: [PATCH 5/9] Add tests for Function::Call with receiver and C style array --- test/function.cc | 15 +++++++++++++++ test/function.js | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/test/function.cc b/test/function.cc index bc10c00b0..b446f0f00 100644 --- a/test/function.cc +++ b/test/function.cc @@ -82,6 +82,17 @@ Value CallWithCStyleArray(const CallbackInfo& info) { return func.Call(args.size(), args.data()); } +Value CallWithReceiverAndCStyleArray(const CallbackInfo& info) { + Function func = info[0].As(); + Value receiver = info[1]; + std::vector args; + args.reserve(3); + args.push_back(info[2]); + args.push_back(info[3]); + args.push_back(info[4]); + return func.Call(receiver, args.size(), args.data()); +} + Value CallWithReceiverAndArgs(const CallbackInfo& info) { Function func = info[0].As(); Value receiver = info[1]; @@ -146,6 +157,8 @@ Object InitFunction(Env env) { exports["callWithArgs"] = Function::New(env, CallWithArgs); exports["callWithVector"] = Function::New(env, CallWithVector); exports["callWithCStyleArray"] = Function::New(env, CallWithCStyleArray); + exports["callWithReceiverAndCStyleArray"] = + Function::New(env, CallWithReceiverAndCStyleArray); exports["callWithReceiverAndArgs"] = Function::New(env, CallWithReceiverAndArgs); exports["callWithReceiverAndVector"] = Function::New(env, CallWithReceiverAndVector); exports["callWithInvalidReceiver"] = Function::New(env, CallWithInvalidReceiver); @@ -169,6 +182,8 @@ Object InitFunction(Env env) { exports["callWithArgs"] = Function::New(env); exports["callWithVector"] = Function::New(env); exports["callWithCStyleArray"] = Function::New(env); + exports["callWithReceiverAndCStyleArray"] = + Function::New(env); exports["callWithReceiverAndArgs"] = Function::New(env); exports["callWithReceiverAndVector"] = diff --git a/test/function.js b/test/function.js index 89b6b9d28..8e9b0e4f8 100644 --- a/test/function.js +++ b/test/function.js @@ -54,6 +54,11 @@ function test(binding) { assert.deepStrictEqual(receiver, undefined); assert.deepStrictEqual(args, [ 5, 6, 7 ]); + ret = 9; + assert.strictEqual(binding.callWithReceiverAndCStyleArray(testFunction, obj, 6, 7, 8), ret); + assert.deepStrictEqual(receiver, obj); + assert.deepStrictEqual(args, [ 6, 7, 8 ]); + ret = 10; assert.strictEqual(binding.callWithFunctionOperator(testFunction, 7, 8, 9), ret); assert.strictEqual(receiver, undefined); From f333e523296b5868097f742965aeb3f9a52efcf4 Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 08:10:14 +0100 Subject: [PATCH 6/9] Add tests for Function::New with C style array --- test/function.cc | 14 ++++++++++++++ test/function.js | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/test/function.cc b/test/function.cc index b446f0f00..f99a5b684 100644 --- a/test/function.cc +++ b/test/function.cc @@ -130,6 +130,16 @@ Value CallConstructorWithVector(const CallbackInfo& info) { return func.New(args); } +Value CallConstructorWithCStyleArray(const CallbackInfo& info) { + Function func = info[0].As(); + std::vector args; + args.reserve(3); + args.push_back(info[1]); + args.push_back(info[2]); + args.push_back(info[3]); + return func.New(args.size(), args.data()); +} + void IsConstructCall(const CallbackInfo& info) { Function callback = info[0].As(); bool isConstructCall = info.IsConstructCall(); @@ -164,6 +174,8 @@ Object InitFunction(Env env) { exports["callWithInvalidReceiver"] = Function::New(env, CallWithInvalidReceiver); exports["callConstructorWithArgs"] = Function::New(env, CallConstructorWithArgs); exports["callConstructorWithVector"] = Function::New(env, CallConstructorWithVector); + exports["callConstructorWithCStyleArray"] = + Function::New(env, CallConstructorWithCStyleArray); exports["isConstructCall"] = Function::New(env, IsConstructCall); exports["callWithFunctionOperator"] = Function::New(env, CallWithFunctionOperator); @@ -194,6 +206,8 @@ Object InitFunction(Env env) { Function::New(env); exports["callConstructorWithVector"] = Function::New(env); + exports["callConstructorWithCStyleArray"] = + Function::New(env); exports["isConstructCall"] = Function::New(env); exports["callWithFunctionOperator"] = Function::New(env); diff --git a/test/function.js b/test/function.js index 8e9b0e4f8..785b2d5c3 100644 --- a/test/function.js +++ b/test/function.js @@ -76,6 +76,10 @@ function test(binding) { assert(obj instanceof testConstructor); assert.deepStrictEqual(args, [ 6, 7, 8 ]); + obj = binding.callConstructorWithCStyleArray(testConstructor, 7, 8, 9); + assert(obj instanceof testConstructor); + assert.deepStrictEqual(args, [ 7, 8, 9 ]); + obj = {}; assert.deepStrictEqual(binding.voidCallbackWithData(obj), undefined); assert.deepStrictEqual(obj, { "foo": "bar", "data": 1 }); From 218af6d64aca65859095378bb8704637d4afd4b5 Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 08:32:51 +0100 Subject: [PATCH 7/9] Add tests for Function::MakeCallback --- test/function.cc | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ test/function.js | 17 ++++++++++++- 2 files changed, 78 insertions(+), 1 deletion(-) diff --git a/test/function.cc b/test/function.cc index f99a5b684..e0485a66b 100644 --- a/test/function.cc +++ b/test/function.cc @@ -146,6 +146,54 @@ void IsConstructCall(const CallbackInfo& info) { callback({Napi::Boolean::New(info.Env(), isConstructCall)}); } +void MakeCallbackWithArgs(const CallbackInfo& info) { + Env env = info.Env(); + Function callback = info[0].As(); + Object resource = info[1].As(); + + AsyncContext context(env, "async_context_test", resource); + + callback.MakeCallback( + resource, + std::initializer_list{info[2], info[3], info[4]}, + context); +} + +void MakeCallbackWithVector(const CallbackInfo& info) { + Env env = info.Env(); + Function callback = info[0].As(); + Object resource = info[1].As(); + + AsyncContext context(env, "async_context_test", resource); + + std::vector args; + args.reserve(3); + args.push_back(info[2]); + args.push_back(info[3]); + args.push_back(info[4]); + callback.MakeCallback(resource, args, context); +} + +void MakeCallbackWithCStyleArray(const CallbackInfo& info) { + Env env = info.Env(); + Function callback = info[0].As(); + Object resource = info[1].As(); + + AsyncContext context(env, "async_context_test", resource); + + std::vector args; + args.reserve(3); + args.push_back(info[2]); + args.push_back(info[3]); + args.push_back(info[4]); + callback.MakeCallback(resource, args.size(), args.data(), context); +} + +void MakeCallbackWithInvalidReceiver(const CallbackInfo& info) { + Function callback = info[0].As(); + callback.MakeCallback(Value(), std::initializer_list{}); +} + Value CallWithFunctionOperator(const CallbackInfo& info) { Function func = info[0].As(); return func({info[1], info[2], info[3]}); @@ -177,6 +225,13 @@ Object InitFunction(Env env) { exports["callConstructorWithCStyleArray"] = Function::New(env, CallConstructorWithCStyleArray); exports["isConstructCall"] = Function::New(env, IsConstructCall); + exports["makeCallbackWithArgs"] = Function::New(env, MakeCallbackWithArgs); + exports["makeCallbackWithVector"] = + Function::New(env, MakeCallbackWithVector); + exports["makeCallbackWithCStyleArray"] = + Function::New(env, MakeCallbackWithCStyleArray); + exports["makeCallbackWithInvalidReceiver"] = + Function::New(env, MakeCallbackWithInvalidReceiver); exports["callWithFunctionOperator"] = Function::New(env, CallWithFunctionOperator); result["plain"] = exports; @@ -209,6 +264,13 @@ Object InitFunction(Env env) { exports["callConstructorWithCStyleArray"] = Function::New(env); exports["isConstructCall"] = Function::New(env); + exports["makeCallbackWithArgs"] = Function::New(env); + exports["makeCallbackWithVector"] = + Function::New(env); + exports["makeCallbackWithCStyleArray"] = + Function::New(env); + exports["makeCallbackWithInvalidReceiver"] = + Function::New(env); exports["callWithFunctionOperator"] = Function::New(env); result["templated"] = exports; diff --git a/test/function.js b/test/function.js index 785b2d5c3..13dacc8cd 100644 --- a/test/function.js +++ b/test/function.js @@ -29,6 +29,15 @@ function test(binding) { args = [].slice.call(arguments); } + function makeCallbackTestFunction(receiver, expectedOne, expectedTwo, expectedThree) { + return function callback(one, two, three) { + assert.strictEqual(this, receiver); + assert.strictEqual(one, expectedOne); + assert.strictEqual(two, expectedTwo); + assert.strictEqual(three, expectedThree); + } + } + ret = 4; assert.equal(binding.callWithArgs(testFunction, 1, 2, 3), 4); assert.strictEqual(receiver, undefined); @@ -95,5 +104,11 @@ function test(binding) { new binding.isConstructCall((result) => { testConstructCall = result; }); assert.ok(testConstructCall); - // TODO: Function::MakeCallback tests + obj = {}; + binding.makeCallbackWithArgs(makeCallbackTestFunction(obj, "1", "2", "3"), obj, "1", "2", "3"); + binding.makeCallbackWithVector(makeCallbackTestFunction(obj, 4, 5, 6), obj, 4, 5, 6); + binding.makeCallbackWithCStyleArray(makeCallbackTestFunction(obj, 7, 8, 9), obj, 7, 8, 9); + assert.throws(() => { + binding.makeCallbackWithInvalidReceiver(() => {}); + }); } From 1167ab3a9b91b262dafd0ae9e5d56b5c1edca75a Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Wed, 10 Mar 2021 08:47:26 +0100 Subject: [PATCH 8/9] Replace deprecated assert.equal with assert.strictEqual in Function tests --- test/function.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/function.js b/test/function.js index 13dacc8cd..2a4a389f3 100644 --- a/test/function.js +++ b/test/function.js @@ -39,22 +39,22 @@ function test(binding) { } ret = 4; - assert.equal(binding.callWithArgs(testFunction, 1, 2, 3), 4); + assert.strictEqual(binding.callWithArgs(testFunction, 1, 2, 3), 4); assert.strictEqual(receiver, undefined); assert.deepStrictEqual(args, [ 1, 2, 3 ]); ret = 5; - assert.equal(binding.callWithVector(testFunction, 2, 3, 4), 5); + assert.strictEqual(binding.callWithVector(testFunction, 2, 3, 4), 5); assert.strictEqual(receiver, undefined); assert.deepStrictEqual(args, [ 2, 3, 4 ]); ret = 6; - assert.equal(binding.callWithReceiverAndArgs(testFunction, obj, 3, 4, 5), 6); + assert.strictEqual(binding.callWithReceiverAndArgs(testFunction, obj, 3, 4, 5), 6); assert.deepStrictEqual(receiver, obj); assert.deepStrictEqual(args, [ 3, 4, 5 ]); ret = 7; - assert.equal(binding.callWithReceiverAndVector(testFunction, obj, 4, 5, 6), 7); + assert.strictEqual(binding.callWithReceiverAndVector(testFunction, obj, 4, 5, 6), 7); assert.deepStrictEqual(receiver, obj); assert.deepStrictEqual(args, [ 4, 5, 6 ]); @@ -95,8 +95,8 @@ function test(binding) { assert.deepStrictEqual(binding.valueCallbackWithData(), { "foo": "bar", "data": 1 }); - assert.equal(binding.voidCallback.name, 'voidCallback'); - assert.equal(binding.valueCallback.name, 'valueCallback'); + assert.strictEqual(binding.voidCallback.name, 'voidCallback'); + assert.strictEqual(binding.valueCallback.name, 'valueCallback'); let testConstructCall = undefined; binding.isConstructCall((result) => { testConstructCall = result; }); From da75b85dee3deec54a535f1264ca93156e65387c Mon Sep 17 00:00:00 2001 From: JoseExposito Date: Sat, 13 Mar 2021 14:51:38 +0100 Subject: [PATCH 9/9] Unify EmptyConstructor and NonEmptyConstructor tests --- test/function.cc | 11 ++--------- test/function.js | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/test/function.cc b/test/function.cc index e0485a66b..4d2d2bd0e 100644 --- a/test/function.cc +++ b/test/function.cc @@ -8,16 +8,11 @@ int testData = 1; Boolean EmptyConstructor(const CallbackInfo& info) { auto env = info.Env(); - Function function = Function(); + bool isEmpty = info[0].As(); + Function function = isEmpty ? Function() : Function(env, Object::New(env)); return Boolean::New(env, function.IsEmpty()); } -Boolean NonEmptyConstructor(const CallbackInfo& info) { - auto env = info.Env(); - Function function = Function(env, Object::New(env)); - return Boolean::New(env, !function.IsEmpty()); -} - void VoidCallback(const CallbackInfo& info) { auto env = info.Env(); Object obj = info[0].As(); @@ -205,7 +200,6 @@ Object InitFunction(Env env) { Object result = Object::New(env); Object exports = Object::New(env); exports["emptyConstructor"] = Function::New(env, EmptyConstructor); - exports["nonEmptyConstructor"] = Function::New(env, NonEmptyConstructor); exports["voidCallback"] = Function::New(env, VoidCallback, "voidCallback"); exports["valueCallback"] = Function::New(env, ValueCallback, std::string("valueCallback")); exports["voidCallbackWithData"] = @@ -238,7 +232,6 @@ Object InitFunction(Env env) { exports = Object::New(env); exports["emptyConstructor"] = Function::New(env, EmptyConstructor); - exports["nonEmptyConstructor"] = Function::New(env, NonEmptyConstructor); exports["voidCallback"] = Function::New(env, "voidCallback"); exports["valueCallback"] = Function::New(env, std::string("valueCallback")); diff --git a/test/function.js b/test/function.js index 2a4a389f3..d98b1944d 100644 --- a/test/function.js +++ b/test/function.js @@ -8,8 +8,8 @@ test(require(`./build/${buildType}/binding.node`).function.templated); test(require(`./build/${buildType}/binding_noexcept.node`).function.templated); function test(binding) { - assert.strictEqual(binding.emptyConstructor(), true); - assert.strictEqual(binding.nonEmptyConstructor(), true); + assert.strictEqual(binding.emptyConstructor(true), true); + assert.strictEqual(binding.emptyConstructor(false), false); let obj = {}; assert.deepStrictEqual(binding.voidCallback(obj), undefined);