1'use strict'; 2// Flags: --expose-gc 3 4const common = require('../../common'); 5const assert = require('assert'); 6 7// Testing api calls for function 8const test_function = require(`./build/${common.buildType}/test_function`); 9 10function func1() { 11 return 1; 12} 13assert.strictEqual(test_function.TestCall(func1), 1); 14 15function func2() { 16 console.log('hello world!'); 17 return null; 18} 19assert.strictEqual(test_function.TestCall(func2), null); 20 21function func3(input) { 22 return input + 1; 23} 24assert.strictEqual(test_function.TestCall(func3, 1), 2); 25 26function func4(input) { 27 return func3(input); 28} 29assert.strictEqual(test_function.TestCall(func4, 1), 2); 30 31assert.strictEqual(test_function.TestName.name, 'Name'); 32assert.strictEqual(test_function.TestNameShort.name, 'Name_'); 33 34let tracked_function = test_function.MakeTrackedFunction(common.mustCall()); 35assert(!!tracked_function); 36tracked_function = null; 37global.gc(); 38 39assert.deepStrictEqual(test_function.TestCreateFunctionParameters(), { 40 envIsNull: 'Invalid argument', 41 nameIsNull: 'napi_ok', 42 cbIsNull: 'Invalid argument', 43 resultIsNull: 'Invalid argument', 44}); 45 46assert.throws( 47 () => test_function.TestBadReturnExceptionPending(), 48 { 49 code: 'throwing exception', 50 name: 'Error', 51 }, 52); 53