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); 17 18function init() { 19 const gtestAbcPath = helper.getEnvironmentVar('ARK_ETS_INTEROP_JS_GTEST_ABC_PATH'); 20 const stdlibPath = helper.getEnvironmentVar('ARK_ETS_STDLIB_PATH'); 21 if (!helper.getEnvironmentVar('PACKAGE_NAME')) { 22 throw Error('PACKAGE_NAME is not set'); 23 } 24 25 let etsVm = requireNapiPreview('ets_interop_js_napi.so', false); 26 const etsOpts = { 27 'panda-files': gtestAbcPath, 28 'boot-panda-files': `${stdlibPath}:${gtestAbcPath}`, 29 'xgc-trigger-type': 'never', 30 }; 31 if (!etsVm.createRuntime(etsOpts)) { 32 throw Error('Cannot create ETS runtime'); 33 } 34 return etsVm; 35} 36 37function runTest() { 38 let etsVm = init(); 39 let tId = 0; 40 const globalName = 'L' + helper.getEnvironmentVar('PACKAGE_NAME') + '/ETSGLOBAL;'; 41 let waitForSchedule = () => { 42 const isWasScheduled = etsVm.getFunction(globalName, 'wasScheduled'); 43 let wasSchedulded = isWasScheduled(); 44 if (wasSchedulded) { 45 clearInterval(tId); 46 } 47 }; 48 49 const waitUntillJsIsReady = etsVm.getFunction(globalName, 'waitUntillJsIsReady'); 50 waitUntillJsIsReady(); 51 const jsIsReady = etsVm.getFunction(globalName, 'jsIsReady'); 52 jsIsReady(); 53 tId = setInterval(waitForSchedule, 0); 54} 55 56runTest(); 57