• 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
16const helper = requireNapiPreview('libinterop_test_helper.so', false);
17let PROMISE_RESOLVE_VALUE = 'JS_PROMISE_RESULT';
18
19function sleep(ms) {
20    return new Promise((resolve) => {
21        setTimeout(() => { resolve(PROMISE_RESOLVE_VALUE) }, ms);
22    });
23}
24
25async function main() {
26    const gtestAbcPath = helper.getEnvironmentVar('ARK_ETS_INTEROP_JS_GTEST_ABC_PATH');
27    const stdlibPath = helper.getEnvironmentVar('ARK_ETS_STDLIB_PATH');
28    let etsVm = requireNapiPreview('ets_interop_js_napi.so', false);
29    const etsVmRes = etsVm.createRuntime({
30        'panda-files': gtestAbcPath,
31        'boot-panda-files': `${stdlibPath}:${gtestAbcPath}`,
32        'load-runtimes': 'ets',
33        'compiler-enable-jit': 'false',
34        'coroutine-workers-count': '8',
35        'xgc-trigger-type': 'never'
36    });
37
38    if (!etsVmRes) {
39        throw new Error('Failed to create ETS runtime');
40    }
41    let packageName = '';
42    if (helper.getEnvironmentVar('PACKAGE_NAME')) {
43        packageName = helper.getEnvironmentVar('PACKAGE_NAME') + '/';
44    } else {
45        throw Error('PACKAGE_NAME not set');
46    }
47
48    const testAwaitJsPromiseSimple = etsVm.getFunction('L' + packageName + 'ETSGLOBAL;', 'testAwaitJsPromiseSimple');
49    await testAwaitJsPromiseSimple(sleep(1000));
50    await testAwaitJsPromiseSimple(sleep(1000));
51}
52
53main();
54