11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci// Flags: --expose-gc
31cb0ef41Sopenharmony_ci
41cb0ef41Sopenharmony_ciconst common = require('../../common');
51cb0ef41Sopenharmony_ciconst assert = require('assert');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci// Testing api calls for function
81cb0ef41Sopenharmony_ciconst test_function = require(`./build/${common.buildType}/test_function`);
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_cifunction func1() {
111cb0ef41Sopenharmony_ci  return 1;
121cb0ef41Sopenharmony_ci}
131cb0ef41Sopenharmony_ciassert.strictEqual(test_function.TestCall(func1), 1);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction func2() {
161cb0ef41Sopenharmony_ci  console.log('hello world!');
171cb0ef41Sopenharmony_ci  return null;
181cb0ef41Sopenharmony_ci}
191cb0ef41Sopenharmony_ciassert.strictEqual(test_function.TestCall(func2), null);
201cb0ef41Sopenharmony_ci
211cb0ef41Sopenharmony_cifunction func3(input) {
221cb0ef41Sopenharmony_ci  return input + 1;
231cb0ef41Sopenharmony_ci}
241cb0ef41Sopenharmony_ciassert.strictEqual(test_function.TestCall(func3, 1), 2);
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_cifunction func4(input) {
271cb0ef41Sopenharmony_ci  return func3(input);
281cb0ef41Sopenharmony_ci}
291cb0ef41Sopenharmony_ciassert.strictEqual(test_function.TestCall(func4, 1), 2);
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ciassert.strictEqual(test_function.TestName.name, 'Name');
321cb0ef41Sopenharmony_ciassert.strictEqual(test_function.TestNameShort.name, 'Name_');
331cb0ef41Sopenharmony_ci
341cb0ef41Sopenharmony_cilet tracked_function = test_function.MakeTrackedFunction(common.mustCall());
351cb0ef41Sopenharmony_ciassert(!!tracked_function);
361cb0ef41Sopenharmony_citracked_function = null;
371cb0ef41Sopenharmony_ciglobal.gc();
381cb0ef41Sopenharmony_ci
391cb0ef41Sopenharmony_ciassert.deepStrictEqual(test_function.TestCreateFunctionParameters(), {
401cb0ef41Sopenharmony_ci  envIsNull: 'Invalid argument',
411cb0ef41Sopenharmony_ci  nameIsNull: 'napi_ok',
421cb0ef41Sopenharmony_ci  cbIsNull: 'Invalid argument',
431cb0ef41Sopenharmony_ci  resultIsNull: 'Invalid argument',
441cb0ef41Sopenharmony_ci});
451cb0ef41Sopenharmony_ci
461cb0ef41Sopenharmony_ciassert.throws(
471cb0ef41Sopenharmony_ci  () => test_function.TestBadReturnExceptionPending(),
481cb0ef41Sopenharmony_ci  {
491cb0ef41Sopenharmony_ci    code: 'throwing exception',
501cb0ef41Sopenharmony_ci    name: 'Error',
511cb0ef41Sopenharmony_ci  },
521cb0ef41Sopenharmony_ci);
53