0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-25 08:19:38 +01:00
nodejs/test/js-native-api/test_function/test.js
Octavian Soldea 1ee47d550c n-api: refactoring napi_create_function testing
This is a refactoring of https://github.com/nodejs/node/pull/26998
following https://github.com/nodejs/node/pull/28505.

The functions `add_last_status()` and `add_returned_status()` are now
reused, see also https://github.com/nodejs/node/pull/28848.

PR-URL: https://github.com/nodejs/node/pull/28894
Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
2019-07-31 23:19:41 -07:00

45 lines
1.1 KiB
JavaScript

'use strict';
// Flags: --expose-gc
const common = require('../../common');
const assert = require('assert');
// Testing api calls for function
const test_function = require(`./build/${common.buildType}/test_function`);
function func1() {
return 1;
}
assert.strictEqual(test_function.TestCall(func1), 1);
function func2() {
console.log('hello world!');
return null;
}
assert.strictEqual(test_function.TestCall(func2), null);
function func3(input) {
return input + 1;
}
assert.strictEqual(test_function.TestCall(func3, 1), 2);
function func4(input) {
return func3(input);
}
assert.strictEqual(test_function.TestCall(func4, 1), 2);
assert.strictEqual(test_function.TestName.name, 'Name');
assert.strictEqual(test_function.TestNameShort.name, 'Name_');
let tracked_function = test_function.MakeTrackedFunction(common.mustCall());
assert(!!tracked_function);
tracked_function = null;
global.gc();
assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
envIsNull: 'Invalid argument',
nameIsNull: 'napi_ok',
cbIsNull: 'Invalid argument',
resultIsNull: 'Invalid argument'
});