2017-03-20 21:55:26 +00:00
|
|
|
'use strict';
|
2018-07-06 14:47:48 +00:00
|
|
|
// Flags: --expose-gc
|
|
|
|
|
2017-03-20 21:55:26 +00:00
|
|
|
const common = require('../../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2019-03-07 00:03:53 +00:00
|
|
|
// Testing api calls for function
|
2018-01-23 10:49:25 +00:00
|
|
|
const test_function = require(`./build/${common.buildType}/test_function`);
|
2017-03-20 21:55:26 +00:00
|
|
|
|
|
|
|
function func1() {
|
|
|
|
return 1;
|
|
|
|
}
|
2017-09-11 13:57:38 +00:00
|
|
|
assert.strictEqual(test_function.TestCall(func1), 1);
|
2017-03-20 21:55:26 +00:00
|
|
|
|
|
|
|
function func2() {
|
|
|
|
console.log('hello world!');
|
|
|
|
return null;
|
|
|
|
}
|
2017-09-11 13:57:38 +00:00
|
|
|
assert.strictEqual(test_function.TestCall(func2), null);
|
2017-03-20 21:55:26 +00:00
|
|
|
|
|
|
|
function func3(input) {
|
|
|
|
return input + 1;
|
|
|
|
}
|
2017-09-11 13:57:38 +00:00
|
|
|
assert.strictEqual(test_function.TestCall(func3, 1), 2);
|
2017-03-20 21:55:26 +00:00
|
|
|
|
|
|
|
function func4(input) {
|
|
|
|
return func3(input);
|
|
|
|
}
|
2017-09-11 13:57:38 +00:00
|
|
|
assert.strictEqual(test_function.TestCall(func4, 1), 2);
|
|
|
|
|
|
|
|
assert.strictEqual(test_function.TestName.name, 'Name');
|
|
|
|
assert.strictEqual(test_function.TestNameShort.name, 'Name_');
|
2018-07-06 14:47:48 +00:00
|
|
|
|
|
|
|
let tracked_function = test_function.MakeTrackedFunction(common.mustCall());
|
|
|
|
assert(!!tracked_function);
|
|
|
|
tracked_function = null;
|
|
|
|
global.gc();
|
2019-03-29 20:12:23 +00:00
|
|
|
|
|
|
|
assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
|
2019-07-28 00:42:19 +00:00
|
|
|
envIsNull: 'Invalid argument',
|
|
|
|
nameIsNull: 'napi_ok',
|
|
|
|
cbIsNull: 'Invalid argument',
|
2023-01-25 06:05:09 +00:00
|
|
|
resultIsNull: 'Invalid argument',
|
2019-03-29 20:12:23 +00:00
|
|
|
});
|
2021-07-21 01:41:58 +00:00
|
|
|
|
|
|
|
assert.throws(
|
|
|
|
() => test_function.TestBadReturnExceptionPending(),
|
|
|
|
{
|
|
|
|
code: 'throwing exception',
|
2023-01-25 06:05:09 +00:00
|
|
|
name: 'Error',
|
|
|
|
},
|
2021-07-21 01:41:58 +00:00
|
|
|
);
|