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 = 'toEtsAndBack'; 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 let jsPromise = Promise.resolve(); 38 const getTheSamePromise = etsVm.getFunction(globalName, 'getTheSamePromise'); 39 let etsPromise = getTheSamePromise(jsPromise); 40 if (jsPromise !== etsPromise) { 41 throw Error('Test ' + test + ' failed: expected jsPromise and etsPromise are the same but actually they differs'); 42 } 43} 44 45runTest(); 46