MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / canCallFunctionWithDifferentOverloads

Function canCallFunctionWithDifferentOverloads

test/function_reference.js:58–85  ·  view source on GitHub ↗
(binding)

Source from the content-addressed store, hash-verified

56}
57
58function canCallFunctionWithDifferentOverloads (binding) {
59 let outsideRef = {};
60 const testFunc = (a, b) => a * a - b * b;
61 const testFuncB = (a, b, c) => a + b - c * c;
62 const testFuncC = (a, b, c) => {
63 outsideRef.a = a;
64 outsideRef.b = b;
65 outsideRef.c = c;
66 };
67 const testFuncD = (a, b, c, d) => {
68 outsideRef.result = a + b * c - d;
69 return outsideRef.result;
70 };
71
72 assert(binding.CallWithVec(testFunc, 5, 4) === testFunc(5, 4));
73 assert(binding.CallWithInitList(testFuncB, 2, 4, 5) === testFuncB(2, 4, 5));
74
75 binding.CallWithRecvVector(testFuncC, outsideRef, 1, 2, 4);
76 assert(outsideRef.a === 1 && outsideRef.b === 2 && outsideRef.c === 4);
77
78 outsideRef = {};
79 binding.CallWithRecvInitList(testFuncC, outsideRef, 1, 2, 4);
80 assert(outsideRef.a === 1 && outsideRef.b === 2 && outsideRef.c === 4);
81
82 outsideRef = {};
83 binding.CallWithRecvArgc(testFuncD, outsideRef, 2, 4, 5, 6);
84 assert(outsideRef.result === testFuncD(2, 4, 5, 6));
85}
86
87async function canCallAsyncFunctionWithDifferentOverloads (binding) {
88 const testFunc = () => 2100;

Callers 1

testFunction · 0.85

Calls 3

testFuncFunction · 0.85
testFuncBFunction · 0.85
testFuncDFunction · 0.85

Tested by 1

testFunction · 0.68