From 68271c1b3f0da6aca25e48e2e489615c87dbd49b Mon Sep 17 00:00:00 2001 From: lichenshuai Date: Thu, 14 Oct 2021 14:46:53 +0800 Subject: [PATCH 1/3] Add support for -m (module) parameter. Signed-off-by: lichenshuai --- test/moduletest/module/BUILD.gn | 3 +++ test/test_helper.gni | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/test/moduletest/module/BUILD.gn b/test/moduletest/module/BUILD.gn index fbf4dea604..5e9c5ddd63 100644 --- a/test/moduletest/module/BUILD.gn +++ b/test/moduletest/module/BUILD.gn @@ -15,10 +15,12 @@ import("//ark/js_runtime/test/test_helper.gni") host_moduletest_action("B") { deps = [] + is_module = true } host_moduletest_action("C") { deps = [] + is_module = true } host_moduletest_action("module") { @@ -26,4 +28,5 @@ host_moduletest_action("module") { ":gen_B_abc", ":gen_C_abc", ] + is_module = true } diff --git a/test/test_helper.gni b/test/test_helper.gni index 6fda2157a7..74c307151b 100644 --- a/test/test_helper.gni +++ b/test/test_helper.gni @@ -65,6 +65,10 @@ template("host_unittest_action") { template("host_moduletest_action") { _target_name_ = "${target_name}" _deps_ = invoker.deps + _is_module_ = false + if (defined(invoker.is_module) && invoker.is_module) { + _is_module_ = true + } _test_js_path_ = "./${_target_name_}.js" _test_abc_path_ = "$target_out_dir/${_target_name_}.abc" @@ -76,6 +80,9 @@ template("host_moduletest_action") { src_js = rebase_path(_test_js_path_) dst_file = rebase_path(_test_abc_path_) extra_args = [ "--debug" ] + if (_is_module_) { + extra_args += [ "--module" ] + } in_puts = [ _test_js_path_, -- Gitee From 7d667e38f0be6fb536e04af4ae2b793f428131db Mon Sep 17 00:00:00 2001 From: lichenshuai Date: Fri, 15 Oct 2021 17:20:37 +0800 Subject: [PATCH 2/3] Add support for relative path and enable moduleAction. Signed-off-by: lichenshuai --- ecmascript/ecma_vm.cpp | 15 +++++++++++++++ test/moduletest/BUILD.gn | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index e00c3723ca..0609e828c5 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -690,6 +690,21 @@ JSHandle EcmaVM::GetModuleByName(JSHandle moduleNa auto pos = scriptName.find_last_of('.'); CString abcPath = dirPath.append(scriptName.substr(0, pos == std::string::npos ? 0 : pos)).append(".abc"); + // handle relative path + if (abcPath.find("./") == 0) { // starts with "./" + std::string fullPath = std::get<1>(pandaFileWithProgram_.back())->GetFilename(); + auto lastSlash = fullPath.find_last_of('/'); + if (lastSlash != std::string::npos) { + abcPath = fullPath.substr(0, lastSlash).append(abcPath.substr(1)); // 1: ignore "." + } + } else if (abcPath.find("../") == 0) { // starts with "../" + std::string fullPath = std::get<1>(pandaFileWithProgram_.back())->GetFilename(); + auto lastSlash = fullPath.find_last_of('/'); + if (lastSlash != std::string::npos) { + abcPath = fullPath.substr(0, lastSlash + 1).append(abcPath); // 1: with "/" + } + } + // Uniform module name JSHandle abcModuleName = factory_->NewFromString(abcPath); diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index a2fe10f762..0648fb4b0d 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -25,7 +25,7 @@ group("ark_js_moduletest") { "helloworld:helloworldAction", "lexicalenv:lexicalenvAction", - # "module:moduleAction", + "module:moduleAction", "multiargs:multiargsAction", "newobjdynrange:newobjdynrangeAction", "promise:promiseAction", -- Gitee From 7dd6afa6b2131c5c3bf5e014fdc5a087d9032bc1 Mon Sep 17 00:00:00 2001 From: lichenshuai Date: Mon, 18 Oct 2021 09:32:22 +0800 Subject: [PATCH 3/3] Modified for codeCheck. Signed-off-by: lichenshuai --- ecmascript/ecma_vm.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 0609e828c5..006fcda4c8 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -689,7 +689,6 @@ JSHandle EcmaVM::GetModuleByName(JSHandle moduleNa // need to check abc file auto pos = scriptName.find_last_of('.'); CString abcPath = dirPath.append(scriptName.substr(0, pos == std::string::npos ? 0 : pos)).append(".abc"); - // handle relative path if (abcPath.find("./") == 0) { // starts with "./" std::string fullPath = std::get<1>(pandaFileWithProgram_.back())->GetFilename(); -- Gitee