11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci// Test that `napi_call_function()` returns `napi_cannot_run_js` in experimental
41cb0ef41Sopenharmony_ci// mode and `napi_pending_exception` otherwise. This test calls the add-on's
51cb0ef41Sopenharmony_ci// `createRef()` method, which creates a strong reference to a JS function. When
61cb0ef41Sopenharmony_ci// the process exits, it calls all reference finalizers. The finalizer for the
71cb0ef41Sopenharmony_ci// strong reference created herein will attempt to call `napi_get_property()` on
81cb0ef41Sopenharmony_ci// a property of the global object and will abort the process if the API doesn't
91cb0ef41Sopenharmony_ci// return the correct status.
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ciconst { buildType, mustNotCall } = require('../../common');
121cb0ef41Sopenharmony_ciconst addon_v8 = require(`./build/${buildType}/test_pending_exception`);
131cb0ef41Sopenharmony_ciconst addon_new = require(`./build/${buildType}/test_cannot_run_js`);
141cb0ef41Sopenharmony_ci
151cb0ef41Sopenharmony_cifunction runTests(addon, isVersion8) {
161cb0ef41Sopenharmony_ci  addon.createRef(mustNotCall());
171cb0ef41Sopenharmony_ci}
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_cifunction runAllTests() {
201cb0ef41Sopenharmony_ci  runTests(addon_v8, /* isVersion8 */ true);
211cb0ef41Sopenharmony_ci  runTests(addon_new, /* isVersion8 */ false);
221cb0ef41Sopenharmony_ci}
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_cirunAllTests();
25