• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/**
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16function runTest() {
17	const helper = requireNapiPreview('libinterop_test_helper.so', false);
18	const gtestAbcPath = helper.getEnvironmentVar('ARK_ETS_INTEROP_JS_GTEST_ABC_PATH');
19	const stdlibPath = helper.getEnvironmentVar('ARK_ETS_STDLIB_PATH');
20	const packageName = helper.getEnvironmentVar('PACKAGE_NAME');
21	if (!packageName) {
22		throw Error('PACKAGE_NAME is not set');
23	}
24	const globalName = 'L' + packageName + '/ETSGLOBAL;';
25
26	let test = 'toJsAndBack';
27	print('Running test ' + test);
28	let etsVm = requireNapiPreview('ets_interop_js_napi.so', false);
29	const etsOpts = {
30		'panda-files': gtestAbcPath,
31		'boot-panda-files': `${stdlibPath}:${gtestAbcPath}`,
32		'xgc-trigger-type': 'never',
33	};
34	if (!etsVm.createRuntime(etsOpts)) {
35		throw Error('Cannot create ETS runtime');
36	}
37	const getPromise = etsVm.getFunction(globalName, 'getPromise');
38	let promise = getPromise();
39	const setAndCheckPromise = etsVm.getFunction(globalName, 'setAndCheckPromise');
40	setAndCheckPromise(promise);
41}
42
43runTest();
44