• 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
16// NOTE(kurnevichstanislav):
17// This file is neccessary, because of specific execution of imports in ArkJSVM
18// Imports executes first of all in the program.
19// This file aim is to workaround this execution order.
20// Since code from this file must be executed first all in the program,
21// main.ts must cotain `import './ets_vm_launcher.ts'` at the beggining.
22// Using of './ets_vm_launcher.ts' is not intuitive, but ets_vm_launcher.abc file
23// will be located in the same directory as other .abc files, so the `./` relative path will be right.
24const launcherName = 'ets_vm_launcher.ts';
25
26// @ts-ignore
27export const helper = requireNapiPreview('libinterop_test_helper.so', false);
28if (helper === undefined) {
29	throw new Error(`${launcherName}: Failed to load libinterop_test_helper.so`);
30}
31
32const gtestAbcPath = helper.getEnvironmentVar('ARK_ETS_INTEROP_JS_GTEST_ABC_PATH');
33const stdlibPath = helper.getEnvironmentVar('ARK_ETS_STDLIB_PATH');
34
35// @ts-ignore
36export const etsVm = requireNapiPreview('ets_interop_js_napi.so', false);
37if (etsVm === undefined) {
38	throw new Error(`${launcherName}: Failed to load ets_interop_js_napi.so`);
39}
40
41const etsOpts = {
42	'panda-files': gtestAbcPath,
43	'boot-panda-files': `${stdlibPath}:${gtestAbcPath}`,
44	'load-runtimes': 'ets',
45};
46
47if (!etsVm.createRuntime(etsOpts)) {
48	throw new Error('Cannot create ETS runtime');
49}
50
51/* CC-OFFNXT(no_explicit_any) std lib */
52// Handle comment directive '@ts-nocheck'
53(globalThis as any).Panda = etsVm;
54