diff --git a/BUILD.gn b/BUILD.gn index 32901a7d010bdc1f659bba0546bd658aedbc8975..c5090b493ad23431fffccf29b488c60eeba8db17 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (defined(ark_independent_build)) { +if (defined(ark_standalone_build)) { import("//js_runtime/js_runtime_config.gni") import("$build_root/ark.gni") } else { @@ -39,7 +39,11 @@ if (defined(ark_independent_build)) { group("ark_js_host_mac_tools_packages") { deps = [] if (host_os == "mac") { - deps += [ "//ark/js_runtime/ecmascript/js_vm:ark_js_vm(//build/toolchain/mac:clang_x64)" ] + if (host_cpu == "arm64") { + deps += [ "//ark/js_runtime/ecmascript/js_vm:ark_js_vm(//build/toolchain/mac:clang_arm64)" ] + } else { + deps += [ "//ark/js_runtime/ecmascript/js_vm:ark_js_vm(//build/toolchain/mac:clang_x64)" ] + } } } @@ -52,7 +56,6 @@ if (defined(ark_independent_build)) { deps += [ "//ark/js_runtime/ecmascript/compiler:ark_aot_compiler(${host_toolchain})", "//ark/js_runtime/ecmascript/compiler:ark_stub_compiler(${host_toolchain})", - "//ark/js_runtime/ecmascript/compiler:gen_stub_file(${host_toolchain})", ] } } @@ -121,7 +124,6 @@ config("ark_jsruntime_public_config") { "$ark_root/libpandafile:arkfile_public_config", "$third_party_gn_path/icu/icu4c:icu_config", sdk_libc_secshared_config, - "$js_root/ecmascript/compiler:gen_stub_file_dir_config", ] defines = [] @@ -137,7 +139,6 @@ config("ark_jsruntime_public_config") { "$js_root", # Dependent on runtime_core include - "$ark_root/runtime", "$ark_root", ] } @@ -184,7 +185,7 @@ config("ark_jsruntime_common_config") { "-Wdate-time", "-Wformat=2", ] - if (defined(ark_independent_build)) { + if (defined(ark_standalone_build)) { cflags_cc += [ "-std=c++17", "-fno-rtti", @@ -230,7 +231,7 @@ config("ark_jsruntime_common_config") { } } - if (!defined(ark_independent_build)) { + if (!defined(ark_standalone_build)) { if (!use_libfuzzer) { cflags_cc += [ "-flto" ] ldflags = [ "-flto" ] @@ -348,6 +349,8 @@ ecma_source = [ "ecmascript/builtins/builtins_weak_set.cpp", "ecmascript/containers/containers_arraylist.cpp", "ecmascript/containers/containers_deque.cpp", + "ecmascript/containers/containers_lightweightmap.cpp", + "ecmascript/containers/containers_lightweightset.cpp", "ecmascript/containers/containers_linked_list.cpp", "ecmascript/containers/containers_list.cpp", "ecmascript/containers/containers_plainarray.cpp", @@ -364,8 +367,10 @@ ecma_source = [ "ecmascript/ecma_string.cpp", "ecmascript/ecma_string_table.cpp", "ecmascript/ecma_vm.cpp", + "ecmascript/frames.cpp", "ecmascript/free_object.cpp", "ecmascript/file_loader.cpp", + "ecmascript/llvm_stackmap_parser.cpp", "ecmascript/generator_helper.cpp", "ecmascript/global_env.cpp", "ecmascript/global_env_constants.cpp", @@ -395,6 +400,10 @@ ecma_source = [ "ecmascript/js_api_arraylist_iterator.cpp", "ecmascript/js_api_deque.cpp", "ecmascript/js_api_deque_iterator.cpp", + "ecmascript/js_api_lightweightmap.cpp", + "ecmascript/js_api_lightweightmap_iterator.cpp", + "ecmascript/js_api_lightweightset.cpp", + "ecmascript/js_api_lightweightset_iterator.cpp", "ecmascript/js_api_linked_list.cpp", "ecmascript/js_api_linked_list_iterator.cpp", "ecmascript/js_api_list.cpp", @@ -490,16 +499,15 @@ ecma_source = [ "ecmascript/template_string.cpp", "ecmascript/waiter_list.cpp", "ecmascript/weak_vector.cpp", - "ecmascript/compiler/llvm/llvm_stackmap_parser.cpp", "ecmascript/stubs/runtime_stubs.cpp", "ecmascript/ts_types/ts_type.cpp", "ecmascript/ts_types/ts_type_table.cpp", "ecmascript/ts_types/ts_loader.cpp", "ecmascript/ts_types/ts_obj_layout_info.cpp", "ecmascript/stubs/test_runtime_stubs.cpp", - "ecmascript/builtins/builtin_cjs_module.cpp", - "ecmascript/builtins/builtin_cjs_require.cpp", - "ecmascript/builtins/builtin_cjs_exports.cpp", + "ecmascript/builtins/builtins_cjs_module.cpp", + "ecmascript/builtins/builtins_cjs_require.cpp", + "ecmascript/builtins/builtins_cjs_exports.cpp", "ecmascript/require/js_cjs_module_cache.cpp", "ecmascript/require/js_cjs_module.cpp", "ecmascript/require/js_require_manager.cpp", @@ -510,6 +518,11 @@ if (!is_mingw && !is_mac) { ecma_source += [ "ecmascript/tooling/interface/file_stream.cpp" ] } +hitrace_scope_source = [] +if (is_ohos && is_standard_system && enable_hitrace) { + hitrace_scope_source += [ "ecmascript/jobs/hitrace_scope.cpp" ] +} + ecma_debugger_source = [] if (!is_mingw && !is_mac) { ecma_debugger_source += [ @@ -541,6 +554,7 @@ source_set("libark_jsruntime_set") { sources = ecma_source sources += ecma_profiler_source sources += ecma_debugger_source + sources += hitrace_scope_source public_configs = [ "$js_root:ark_jsruntime_common_config", @@ -575,10 +589,20 @@ source_set("libark_jsruntime_set") { include_dirs += [ "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include/hitrace_meter" ] cflags_cc += [ "-Wno-gnu-zero-variadic-macro-arguments" ] } + if (enable_hitrace) { + defines += [ "ENABLE_HITRACE" ] + include_dirs += + [ "//base/hiviewdfx/hitrace/interfaces/native/innerkits/include" ] + } if (enable_dump_in_faultlog) { defines += [ "ENABLE_DUMP_IN_FAULTLOG" ] include_dirs += [ "//base/hiviewdfx/faultloggerd/interfaces/innerkits/faultloggerd_client" ] } + if (enable_hilog) { + defines += [ "ENABLE_HILOG" ] + include_dirs += + [ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include" ] + } } } @@ -613,6 +637,13 @@ source_set("libark_jsruntime_test_set") { sdk_libc_secshared_dep, ] + if ((is_linux && current_cpu == "x64") || + (is_ohos && current_cpu == "arm64")) { + deps += [ "$js_root/ecmascript/compiler:libark_stub_set" ] + } else { + deps += [ "$js_root/ecmascript/compiler:libark_mock_stub_set" ] + } + if (is_debug && is_linux && (current_cpu == "x86" || current_cpu == "x64") && run_with_asan) { deps += [ ":copy_asan_runtime" ] @@ -623,37 +654,52 @@ source_set("libark_jsruntime_test_set") { "$js_root:ark_jsruntime_public_config", ] } -if (!defined(ark_independent_build)) { - ohos_shared_library("libark_jsruntime") { - deps = [ - ":libark_js_intl_set", - ":libark_jsruntime_set", - ] - if (is_ohos && is_standard_system) { - if (enable_dump_in_faultlog || enable_bytrace) { - external_deps = [] - } - if (enable_dump_in_faultlog) { - external_deps += [ "faultloggerd:libfaultloggerd" ] - } - if (enable_bytrace) { - external_deps += [ "hitrace_native:hitrace_meter" ] - } - } +ohos_shared_library("libark_jsruntime") { + deps = [ + ":libark_js_intl_set", + ":libark_jsruntime_set", + ] - install_enable = true + if ((is_linux && current_cpu == "x64") || + (is_ohos && current_cpu == "arm64")) { + deps += [ "$js_root/ecmascript/compiler:libark_stub_set" ] + } else { + deps += [ "$js_root/ecmascript/compiler:libark_mock_stub_set" ] + } - if (!is_mingw && !is_mac) { - output_extension = "so" + if (is_ohos && is_standard_system) { + if (enable_dump_in_faultlog || enable_bytrace || enable_hitrace || + enable_hilog) { + external_deps = [] + } + if (enable_dump_in_faultlog) { + external_deps += [ "faultloggerd:libfaultloggerd" ] + } + if (enable_bytrace) { + external_deps += [ "hitrace_native:hitrace_meter" ] } - if (!is_standard_system) { - relative_install_dir = "ark" + if (enable_hitrace) { + external_deps += [ "hitrace_native:libhitrace" ] } - part_name = "ark_js_runtime" - subsystem_name = "ark" + if (enable_hilog) { + external_deps += [ "hiviewdfx_hilog_native:libhilog" ] + } + } + + install_enable = true + + if (!is_mingw && !is_mac) { + output_extension = "so" + } + if (!is_standard_system) { + relative_install_dir = "ark" } + part_name = "ark_js_runtime" + subsystem_name = "ark" +} +if (!defined(ark_standalone_build)) { ohos_shared_library("libark_jsruntime_test") { deps = [ ":libark_jsruntime_test_set" ] @@ -671,14 +717,4 @@ if (!defined(ark_independent_build)) { outputs = [ "${root_out_dir}/ark/ark_js_runtime/{{source_file_part}}" ] } } -} else { - ark_shared_library("libark_jsruntime") { - deps = [ - ":libark_js_intl_set", - ":libark_jsruntime_set", - ] - if (!is_mingw && !is_mac) { - output_extension = "so" - } - } } diff --git a/README.md b/README.md index 49559d09c7e5c1514ba66770a5c883ec39887af0..901b52c35fea885eb97e056830ba513a0eb924eb 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ For more information, see: [ARK Runtime Subsystem](https://gitee.com/openharmony ## Build ``` -./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages +./build.sh --product-name hispark_taurus_standard --build-target ark_js_host_linux_tools_packages ``` ### Available APIs @@ -68,7 +68,7 @@ For details about how to generate JS bytecodes, see [Using the Toolchain](docs/ To run bytecodes: ``` -LD_LIBRARY_PATH=out/rk3568/clang_x64/ark/ark:out/rk3568/clang_x64/ark/ark_js_runtime:out/rk3568/clang_x64/thirdparty/icu:prebuilts/clang/ohos/linux-x86_64/llvm/lib ./out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm helloworld.abc +LD_LIBRARY_PATH=out/hispark_taurus/clang_x64/ark/ark:out/hispark_taurus/clang_x64/ark/ark_js_runtime:out/hispark_taurus/clang_x64/thirdparty/icu:prebuilts/clang/ohos/linux-x86_64/llvm/lib ./out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm helloworld.abc ``` For more information, please see: [ARK-Runtime-Usage-Guide](https://gitee.com/openharmony/ark_js_runtime/blob/master/docs/ARK-Runtime-Usage-Guide.md). diff --git a/README_zh.md b/README_zh.md index 3dce8938ba19c05da483587eb7151693c6f57f28..4b108eb476726045f18a1ff45bed746b26561515 100644 --- a/README_zh.md +++ b/README_zh.md @@ -57,7 +57,7 @@ ## 编译构建 ``` -$./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages +$./build.sh --product-name hispark_taurus_standard --build-target ark_js_host_linux_tools_packages ``` ### 接口说明 @@ -70,7 +70,7 @@ JS生成字节码参考[工具链使用](docs/using-the-toolchain-zh.md) 字节码执行: ``` -LD_LIBRARY_PATH=out/rk3568/clang_x64/ark/ark:out/rk3568/clang_x64/ark/ark_js_runtime:out/rk3568/clang_x64/thirdparty/icu:prebuilts/clang/ohos/linux-x86_64/llvm/lib ./out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm helloworld.abc +LD_LIBRARY_PATH=out/hispark_taurus/clang_x64/ark/ark:out/hispark_taurus/clang_x64/ark/ark_js_runtime:out/hispark_taurus/clang_x64/thirdparty/icu:prebuilts/clang/ohos/linux-x86_64/llvm/lib ./out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm helloworld.abc ``` diff --git a/build/README.md b/build/README.md index 29550638384b7a599d633f7d1dcf3ab0fbc61f23..42ef943d28841dcdf9c35efb4a943ca508a34ac1 100644 --- a/build/README.md +++ b/build/README.md @@ -1,4 +1,5 @@ # ark_build +注意:目前版本部分内容还需完善,后续入库后会做具体说明 #### 介绍 方舟独立编译构建build @@ -16,18 +17,20 @@ ├── ts2abc -├── third_patry #从openharmony开源项目下载 +├── third_patry + +#所有仓库需从openharmony开源项目下载 #### 安装教程 -1. 独立编译拉取ark_js_runtime、ark_runtime_core、ark_ts2abc,执行./build/prebuilts_download.sh 下载相关的编译所需工具。 -2. 之后执行./js_runtime/build/compile_script/gen.sh ark将.gn、.sh文件拿出来。 +1. 独立编译拉取ark_js_runtime、ark_runtime_core、ark_ts2abc三个仓,执行[./build/prebuilts_download.sh] 下载相关的编译所需工具。 +2. 之后执行[./js_runtime/build/compile_script/gen.sh ark]将.gn与.sh文件拿出来。 3. 执行[./gen.sh]命令编译目前独立编译支持的所有目标,执行[./gen.sh abc]命令生成abc文件,执行[./gen.sh .]命令执行abc文件 #### 使用说明 -1. 独立编译build目录放在ark_js_runtime仓下 +1. 独立编译build目录放在ark_js_runtime仓下,它和build仓不一样,是独立编译特有的 2. 所需三方库从openharmony开源项目下载,包含 : https://gitee.com/openharmony/third_party_bounds_checking_function, https://gitee.com/openharmony/third_party_icu, diff --git a/build/config/BUILDCONFIG.gn b/build/config/BUILDCONFIG.gn index d142df1fad761a675f9f82dcdc7e00463ed1460e..da0814fc113fcdf4580a4cd32beb23d79dccbc79 100644 --- a/build/config/BUILDCONFIG.gn +++ b/build/config/BUILDCONFIG.gn @@ -12,8 +12,8 @@ # limitations under the License. declare_args() { - ark_independent_build = true - root_core_gn = "//build/core/gn" + another_path = true + ark_standalone_build = true build_root = "//js_runtime/build" } diff --git a/build/core/gn/BUILD.gn b/build/core/gn/BUILD.gn index fbcdc948d0db8b2f289e0fc9a4f4281ad8d7c70f..b30806d0d941ba187a39ca5204c7e157a1fbdc7e 100644 --- a/build/core/gn/BUILD.gn +++ b/build/core/gn/BUILD.gn @@ -27,7 +27,7 @@ print() # /js_runtime/ecmascript/js_vm/BUILD.gn -ark_executable("ark_js_vm") { +ohos_executable("ark_js_vm") { deps = [ "//js_runtime/ecmascript/js_vm:ark_js_vm_set" ] ldflags = [ "-pie", @@ -40,8 +40,20 @@ ark_executable("ark_js_vm") { output_name = "ark_js_vm" } -ark_executable("ts2abc") { - deps = [ "//ts2abc/ts2panda/ts2abc:ts2abc_static" ] +enable_bytecode_optimizer = false +ohos_executable("ts2abc") { + sources = [ + "//ts2abc/ts2panda/ts2abc/main.cpp", + "//ts2abc/ts2panda/ts2abc/ts2abc.cpp", + ] + + configs = [ "//ts2abc/ts2panda/ts2abc:ts2abc_config" ] + + cflags = [ + "-Wno-c++20-designator", + "-Wno-c99-extensions", + "-Wno-unknown-warning-option", + ] ldflags = [ "-fPIE", "-ldl", @@ -50,6 +62,38 @@ ark_executable("ts2abc") { "-lc++", "-latomic", ] + deps = [ sdk_libc_secshared_dep ] + + if (is_linux || is_mingw || is_mac) { + deps += [ + "$ark_root/assembler:libarkassembler_frontend_static", + "$ark_root/libpandabase:libarkbase_frontend_static", + "$ark_root/libpandafile:libarkfile_frontend_static", + "$ark_root/libziparchive:libarkziparchive_frontend_static", + "$third_party_gn_path/jsoncpp:jsoncpp_static", + ] + if (enable_bytecode_optimizer) { + deps += [ + "ark_root/bytecode_optimizer:libarkbytecodeopt_frontend_static", + "ark_root/compiler:libarkcompiler_frontend_static", + ] + } + } else { + deps += [ + "$ark_root/assembler:libarkassembler", + "$ark_root/libpandabase:libarkbase", + "$ark_root/libpandafile:libarkfile", + "$ark_root/libziparchive:libarkziparchive", + "$third_party_gn_path/jsoncpp:jsoncpp", + ] + if (enable_bytecode_optimizer) { + deps += [ + "$ark_root/bytecode_optimizer:libarkbytecodeopt", + "$ark_root/compiler:libarkcompiler", + ] + } + } + if (is_linux) { if (build_public_version) { ldflags += [ "-static-libstdc++" ] @@ -57,6 +101,7 @@ ark_executable("ts2abc") { libs = [ libcpp_static_lib ] } } + output_dir = "${root_out_dir}/ark/ark/" output_name = "js2abc" } @@ -65,18 +110,18 @@ ark_executable("ts2abc") { src_dir = target_out_dir + "/src" -ark_copy("ts2abc_src") { +ohos_copy("ts2abc_src") { sources = [ "${ts2abc_root}/src" ] outputs = [ src_dir ] } -ark_copy("node_modules") { +ohos_copy("node_modules") { sources = [ rebase_path("${node_modules}") ] print("sources=$sources") outputs = [ target_out_dir + "/node_modules" ] } -ark_copy("config_files") { +ohos_copy("config_files") { sources = [ "${ts2abc_root}/package-lock.json", "${ts2abc_root}/package.json", @@ -188,13 +233,13 @@ action("npm_run_build") { } } -ark_copy("ts2abc_build") { +ohos_copy("ts2abc_build") { deps = [ ":npm_run_build" ] sources = [ "${root_out_dir}/ark/ark/build" ] outputs = [ "${target_out_dir}/build-tmp" ] } -ark_copy("ts2abc_build_ets") { +ohos_copy("ts2abc_build_ets") { deps = [ ":npm_run_build" ] sources = [ "${root_out_dir}/ark/ark/build" ] outputs = [ "${root_out_dir}/ark/ark/build-ets" ] diff --git a/build/prebuilts_download.sh b/build/prebuilts_download.sh index 4a6b8e2ed4ea1c8aab88d1c1d38ae0e54751f8b9..a0465298a8e6be23c839afeff98b45f29af2dc64 100755 --- a/build/prebuilts_download.sh +++ b/build/prebuilts_download.sh @@ -1,10 +1,10 @@ #!/bin/bash -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-2022 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -14,12 +14,13 @@ set -e for i in "$@"; do case "$i" in - -skip-ssl|--skip-ssl) # wget、npm跳过ssl检查,如使用此参数: - # 黑客等不法分子可以篡改或窃取客户端和服务器之间传输的信息和数据,从而影响用户的数据安全! + -skip-ssl|--skip-ssl) # wget、npm skip ssl check, which will allow + # hacker to get and modify data stream between server and client! SKIP_SSL=YES ;; esac done + if [ "X${SKIP_SSL}" == "XYES" ];then wget_ssl_check='--no-check-certificate' else @@ -43,12 +44,13 @@ echo "npm_registry=$npm_registry" sha256_result=0 check_sha256='' local_sha256='' -function check_sha256(){ + +function check_sha256() { success_color='\033[1;42mSuccess\033[0m' failed_color='\033[1;41mFailed\033[0m' - check_url=$1 #来源URL - local_file=$2 #本地文件绝对路径 - check_sha256=$(curl -s -k ${check_url}.sha256) # 当前使用华为云,URL固定,所以写死了,后续如果有变动,此处需要修改 + check_url=$1 # source URL + local_file=$2 # local absolute path + check_sha256=$(curl -s -k ${check_url}.sha256) local_sha256=$(sha256sum ${local_file} |awk '{print $1}') if [ "X${check_sha256}" == "X${local_sha256}" ];then echo -e "${success_color},${check_url} Sha256 check OK." @@ -56,13 +58,28 @@ function check_sha256(){ else echo -e "${failed_color},${check_url} Sha256 check Failed.Retry!" sha256_result=1 - #exit 1 # 默认退出,必须保证sha256一致,如有特殊需要,请自行注释 fi } -function hwcloud_download(){ - # 代理不需要鉴权: wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://domain.com:port" ${huaweicloud_url} - # 代理需要鉴权(账号密码特殊字符均需要URL转义): wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://username:password@domain.com:port" ${huaweicloud_url} - # 不需要代理 + +function check_sha256_by_mark() { + success_color='\033[1;42mSuccess\033[0m' + check_url=$1 # source URL + check_sha256=$(curl -s -k ${check_url}.sha256) + echo $1 + if [ -f "${code_dir}/${unzip_dir}/${check_sha256}.mark" ];then + echo -e "${success_color},${check_url} Sha256 markword check OK." + sha256_result=0 + else + echo -e "${check_url} Sha256 mismatch or files not downloaded yet." + sha256_result=1 + fi +} + +function hwcloud_download() { + # when proxy certfication not required : wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://domain.com:port" ${huaweicloud_url} + # when proxy certfication required (special char need URL translate, e.g '!' -> '%21'git + # wget -t3 -T10 -O ${bin_dir} -e "https_proxy=http://username:password@domain.com:port" ${huaweicloud_url} + download_local_file=$1 download_source_url=$2 for((i=1;i<=3;i++)); @@ -70,10 +87,8 @@ function hwcloud_download(){ if [ -f "${download_local_file}" ];then check_sha256 "${download_source_url}" "${download_local_file}" if [ ${sha256_result} -gt 0 ];then - # 设置变量默认值,防止误删除 rm -rf "${download_local_file:-/tmp/20210721_not_exit_file}" else - i=999 return 0 fi fi @@ -81,7 +96,7 @@ function hwcloud_download(){ wget -t3 -T10 ${wget_ssl_check} -O "${download_local_file}" "${download_source_url}" fi done - # 连续三次失败后报错退出 + # three times error, exit echo -e """Sha256 check failed! Download URL: ${download_source_url} Local file: ${download_local_file} @@ -90,6 +105,37 @@ Local sha256: ${local_sha256}""" exit 1 } +function npm_install() { + full_code_path=${code_dir}/$1 + if [ ! -d ${full_code_path} ]; then + echo "${full_code_path} not exist, it shouldn't happen, pls check..." + else + cd ${full_code_path} + export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH + npm config set registry ${npm_registry} + if [ "X${SKIP_SSL}" == "XYES" ];then + npm config set strict-ssl false + fi + # npm cache clean -f + npm install + fi +} + +function node_modules_copy() { + full_code_path=${code_dir}/$1 + tool_path=$2 + if [ -d "${full_code_path}" ] & [ ! -z ${tool_path} ]; then + if [ -d "${code_dir}/${tool_path}" ]; then + echo -e "\n" + echo "${code_dir}/${tool_path} already exist, it will be replaced with node-${node_js_ver}" + /bin/rm -rf ${code_dir}/${tool_path} + echo -e "\n" + fi + mkdir -p ${code_dir}/${tool_path} + /bin/cp -R ${full_code_path}/node_modules ${code_dir}/${tool_path} + fi +} + case $(uname -s) in Linux) host_platform=linux @@ -102,45 +148,41 @@ case $(uname -s) in exit 1 esac -# 代码下载目录 +# sync code directory script_path=$(cd $(dirname $0);pwd) -code_dir=$(dirname ${script_path}) -# 二进制所在目录,用于临时存放二进制,需要约7G空间 -# 下载的压缩包会自动解压到代码目录,压缩包会一直保留在该目录下 -bin_dir=${code_dir}/../OpenHarmony_2.0_canary_prebuilts +code_dir=$(dirname ${script_path})/.. +# "prebuilts" directory will be generated under project root which is used to saved binary (arround 9.5GB) +# downloaded files will be automatically unziped under this path +bin_dir=${code_dir}/OpenHarmony_2.0_canary_prebuilts + +# download file list +# todo: add product related config -# 二进制关系 copy_config=""" -prebuilts/sdk/js-loader/build-tools,${tool_repo}/harmonyos/compiler/ace-loader/1.0/ace-loader-1.0.tar.gz -prebuilts/build-tools/common,${tool_repo}/harmonyos/compiler/restool/2.007/restool-2.007.tar.gz -prebuilts/cmake,${tool_repo}/harmonyos/compiler/cmake/3.16.5/${host_platform}/cmake-${host_platform}-x86-3.16.5.tar.gz -prebuilts/build-tools/${host_platform}-x86/bin,${tool_repo}/harmonyos/compiler/gn/1717/${host_platform}/gn-${host_platform}-x86-1717.tar.gz -prebuilts/build-tools/${host_platform}-x86/bin,${tool_repo}/harmonyos/compiler/ninja/1.10.1/${host_platform}/ninja-${host_platform}-x86-1.10.1.tar.gz -prebuilts/python,${tool_repo}/harmonyos/compiler/python/3.8.5/${host_platform}/python-${host_platform}-x86-3.8.5.tar.gz -prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/clang-480513-${host_platform}-x86_64.tar.bz2 -prebuilts/,${tool_repo}/harmonyos/compiler/llvm_prebuilt_libs/ark_js_prebuilts_20220301.tar.gz +prebuilts/build-tools/common,${tool_repo}/openharmony/compiler/restool/2.007/restool-2.007.tar.gz +prebuilts/build-tools/${host_platform}-x86/bin,${tool_repo}/openharmony/compiler/gn/1717/${host_platform}/gn-${host_platform}-x86-1717.tar.gz +prebuilts/build-tools/${host_platform}-x86/bin,${tool_repo}/openharmony/compiler/ninja/1.10.1/${host_platform}/ninja-${host_platform}-x86-1.10.1.tar.gz +prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/openharmony/compiler/clang/10.0.1-480513/${host_platform}/clang-480513-${host_platform}-x86_64.tar.bz2 +prebuilts/ark_tools,${tool_repo}/openharmony/compiler/llvm_prebuilt_libs/ark_js_prebuilts_20220425.tar.gz +""" + +linux_copy_config=""" +prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/openharmony/compiler/clang/10.0.1-480513/${host_platform}/libcxx-ndk-480513-${host_platform}-x86_64.tar.bz2 +""" + +darwin_copy_config=""" +prebuilts/previewer/darwin,${tool_repo}/openharmony/develop_tools/previewer/3.1.5.6/previewer-3.1.5.6.mac.tar.gz +prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/openharmony/compiler/clang/10.0.1-480513/${host_platform}/libcxx-ndk-480513-${host_platform}-x86_64.tar.bz2 +prebuilts/python,${tool_repo}/openharmony/compiler/python/3.9.2/${host_platform}/python-${host_platform}-x86-3.9.2_202205071615.tar.gz """ if [[ "${host_platform}" == "linux" ]]; then - copy_config+=""" - prebuilts/cmake,${tool_repo}/harmonyos/compiler/cmake/3.16.5/windows/cmake-windows-x86-3.16.5.tar.gz - prebuilts/mingw-w64/ohos/linux-x86_64,${tool_repo}/harmonyos/compiler/mingw-w64/7.0.0/clang-mingw.tar.gz - prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi,${tool_repo}/harmonyos/compiler/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/1.0/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi.tar.gz - prebuilts/gcc/linux-x86/aarch64,${tool_repo}/harmonyos/compiler/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi/1.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu.tar.xz - prebuilts/previewer/windows,${tool_repo}/harmonyos/develop_tools/previewer/3.1.5.4/previewer-3.1.5.4.win.tar.gz - prebuilts/clang/ohos/windows-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/windows/clang-480513-windows-x86_64.tar.bz2 - prebuilts/clang/ohos/windows-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/windows/libcxx-ndk-480513-windows-x86_64.tar.bz2 - prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/libcxx-ndk-480513-${host_platform}-x86_64.tar.bz2 - prebuilts/gcc/linux-x86/esp,${tool_repo}/harmonyos/compiler/gcc_esp/2019r2-8.2.0/linux/esp-2019r2-8.2.0.zip - prebuilts/gcc/linux-x86/csky,${tool_repo}/harmonyos/compiler/gcc_csky/v3.10.29/linux/csky-v3.10.29.tar.gz - """ + copy_config+=${linux_copy_config} elif [[ "${host_platform}" == "darwin" ]]; then - copy_config+=""" - prebuilts/previewer/darwin,${tool_repo}/harmonyos/develop_tools/previewer/3.1.5.4/previewer-3.1.5.4.mac.tar.gz - prebuilts/clang/ohos/${host_platform}-x86_64,${tool_repo}/harmonyos/compiler/clang/10.0.1-480513/${host_platform}/libcxx-ndk-480513-${host_platform}-x86_64.tar.bz2 - """ + copy_config+=${darwin_copy_config} fi +# download and initialize prebuild files if [ ! -d "${bin_dir}" ];then mkdir -p "${bin_dir}" fi @@ -157,41 +199,50 @@ do if [ ! -d "${code_dir}/${unzip_dir}" ];then mkdir -p "${code_dir}/${unzip_dir}" fi - hwcloud_download "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}" "${huaweicloud_url}" - if [ "X${bin_file_suffix:0-3}" = "Xzip" ];then - unzip -o "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}" -d "${code_dir}/${unzip_dir}/" - elif [ "X${bin_file_suffix:0-6}" = "Xtar.gz" ];then - tar -xvzf "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}" -C "${code_dir}/${unzip_dir}" - else - tar -xvf "${bin_dir}/${md5_huaweicloud_url}.${bin_file_suffix}" -C "${code_dir}/${unzip_dir}" - fi - # 由于部分压缩包包含了目录,用于专门处理多余目录 - if [ -d "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" ];then - mv "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi2/" - rm -rf "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi" - mv "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi2/" "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/" - fi - if [ -d "${code_dir}/prebuilts/clang/ohos/windows-x86_64/clang-480513" ];then - rm -rf "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm" - mv "${code_dir}/prebuilts/clang/ohos/windows-x86_64/clang-480513" "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm" - ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm/lib/clang/current" - fi - if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-480513" ];then - rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" - mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-480513" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" - ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/current" - fi - if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-480513" ];then - rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" - mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-480513" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" - ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm/lib/clang/current" - fi - if [ -d "${code_dir}/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0/xtensa-esp32-elf" ];then - chmod 755 "${code_dir}/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0" -R + + check_sha256_by_mark ${huaweicloud_url} + if [ ${sha256_result} -gt 0 ]; then + hwcloud_download "${bin_dir}/${md5_huaweicloud_url}.${bin_file}" "${huaweicloud_url}" + if [ "X${bin_file:0-3}" = "Xzip" ];then + unzip -o "${bin_dir}/${md5_huaweicloud_url}.${bin_file}" -d "${code_dir}/${unzip_dir}/" + elif [ "X${bin_file:0-6}" = "Xtar.gz" ];then + tar -xvzf "${bin_dir}/${md5_huaweicloud_url}.${bin_file}" -C "${code_dir}/${unzip_dir}" + else + tar -xvf "${bin_dir}/${md5_huaweicloud_url}.${bin_file}" -C "${code_dir}/${unzip_dir}" + fi + # it is used to handle some redundant files under prebuilts path + # todo: remove redundant files before prebuilts_download + if [ -d "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" ];then + mv "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/prebuilts_gcc_linux-x86_arm_gcc-linaro-7.5.0-arm-linux-gnueabi" "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi2/" + rm -rf "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi" + mv "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi2/" "${code_dir}/prebuilts/gcc/linux-x86/arm/gcc-linaro-7.5.0-arm-linux-gnueabi/" + fi + if [ -d "${code_dir}/prebuilts/clang/ohos/windows-x86_64/clang-480513" ];then + rm -rf "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm" + mv "${code_dir}/prebuilts/clang/ohos/windows-x86_64/clang-480513" "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm" + ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/windows-x86_64/llvm/lib/clang/current" + fi + if [ -d "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-480513" ];then + rm -rf "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" + mv "${code_dir}/prebuilts/clang/ohos/linux-x86_64/clang-480513" "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm" + ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/linux-x86_64/llvm/lib/clang/current" + fi + if [ -d "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-480513" ];then + rm -rf "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" + mv "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/clang-480513" "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm" + ln -snf 10.0.1 "${code_dir}/prebuilts/clang/ohos/darwin-x86_64/llvm/lib/clang/current" + fi + if [ -d "${code_dir}/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0/xtensa-esp32-elf" ];then + chmod 755 "${code_dir}/prebuilts/gcc/linux-x86/esp/esp-2019r2-8.2.0" -R + fi + echo 0 > "${code_dir}/${unzip_dir}/${check_sha256}.mark" fi + echo "k" done +# npm env setup and install + node_js_ver=v12.18.4 node_js_name=node-${node_js_ver}-${host_platform}-x64 node_js_pkg=${node_js_name}.tar.gz @@ -202,80 +253,19 @@ if [ ! -f "${node_js_pkg}" ]; then tar zxf ${node_js_pkg} fi -if [ ! -d "${code_dir}/third_party/jsframework" ]; then - echo "${code_dir}/third_party/jsframework not exist, it shouldn't happen, pls check..." -else - cd ${code_dir}/third_party/jsframework/ - export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH - npm config set registry ${npm_registry} - if [ "X${SKIP_SSL}" == "XYES" ];then - npm config set strict-ssl false - fi - npm cache clean -f - npm install - - cd ${code_dir} - if [ -d "${code_dir}/prebuilts/build-tools/common/js-framework" ]; then - echo -e "\n" - echo "${code_dir}/prebuilts/build-tools/common/js-framework already exist, it will be replaced with node-${node_js_ver}" - /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/js-framework - echo -e "\n" - fi - - mkdir -p ${code_dir}/prebuilts/build-tools/common/js-framework - /bin/cp -R ${code_dir}/third_party/jsframework/node_modules ${code_dir}/prebuilts/build-tools/common/js-framework/ -fi - -if [ ! -d "${code_dir}/developtools/ace-ets2bundle/compiler" ]; then - echo "${code_dir}/developtools/ace-ets2bundle/compiler not exist, it shouldn't happen, pls check..." -else - cd ${code_dir}/developtools/ace-ets2bundle/compiler - export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH - npm config set registry ${npm_registry} - if [ "X${SKIP_SSL}" == "XYES" ];then - npm config set strict-ssl false - fi - npm cache clean -f - npm install -fi - - -if [ ! -d "${code_dir}/developtools/ace-js2bundle/ace-loader" ]; then - echo "${code_dir}/developtools/ace-js2bundle/ace-loader not exist, it shouldn't happen, pls check..." -else - cd ${code_dir}/developtools/ace-js2bundle/ace-loader - export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH - npm config set registry ${npm_registry} - if [ "X${SKIP_SSL}" == "XYES" ];then - npm config set strict-ssl false - fi - npm cache clean -f - npm install -fi - - -if [ -d "${code_dir}/ark/ts2abc/ts2panda" ]; then - cd ${code_dir}/ark/ts2abc/ts2panda - export PATH=${code_dir}/prebuilts/build-tools/common/nodejs/${node_js_name}/bin:$PATH - npm config set registry ${npm_registry} - if [ "X${SKIP_SSL}" == "XYES" ];then - npm config set strict-ssl false - fi - npm cache clean -f - npm install - - cd ${code_dir} - if [ -d "${code_dir}/prebuilts/build-tools/common/ts2abc" ]; then - echo -e "\n" - echo "${code_dir}/prebuilts/build-tools/common/ts2abc already exist, it will be replaced with node-${node_js_ver}" - /bin/rm -rf ${code_dir}/prebuilts/build-tools/common/ts2abc - echo -e "\n" - fi - - mkdir -p ${code_dir}/prebuilts/build-tools/common/ts2abc - /bin/cp -rf ${code_dir}/ark/ts2abc/ts2panda/node_modules ${code_dir}/prebuilts/build-tools/common/ts2abc/ -fi +npm_install_config=""" +ts2abc/ts2panda,prebuilts/build-tools/common/ts2abc +""" +for i in $(echo ${npm_install_config}) +do + code_path=$(echo $i|awk -F ',' '{print $1}') + modules_path=$(echo $i|awk -F ',' '{print $2}') + npm_install ${code_path} + echo ${code_path} + echo ${modules_path} + node_modules_copy ${code_path} ${modules_path} +done cd ${code_dir} echo -e "\n" diff --git a/build/templates/cxx/cxx.gni b/build/templates/cxx/cxx.gni index e7d6b61197e3d202892f812a5a91429bd53e5101..f060706bf83e56c0f228a7caecea8f87a02d8aac 100755 --- a/build/templates/cxx/cxx.gni +++ b/build/templates/cxx/cxx.gni @@ -11,22 +11,42 @@ # See the License for the specific language governing permissions and # limitations under the License. -template("ark_executable") { +template("ohos_executable") { executable(target_name) { - forward_variables_from(invoker, "*") + forward_variables_from(invoker, + "*", + [ + "subsystem_name", + "install_enable", + ]) } } -template("ark_static_library") { +template("ohos_static_library") { static_library(target_name) { - forward_variables_from(invoker, "*") + forward_variables_from(invoker, + "*", + [ + "subsystem_name", + "part_name", + "use_exceptions", + ]) } } -template("ark_shared_library") { +template("ohos_shared_library") { shared_library(target_name) { - forward_variables_from(invoker, "*") + forward_variables_from(invoker, + "*", + [ + "relative_install_dir", + "subsystem_name", + "install_enable", + "part_name", + "use_exceptions", + ]) } } -template("ark_copy") { + +template("ohos_copy") { copy(target_name) { forward_variables_from(invoker, "*") } diff --git a/build/third_party_gn/icu/icu4c/BUILD.gn b/build/third_party_gn/icu/icu4c/BUILD.gn deleted file mode 100644 index 198fd94cd6005fa2a04ce2570c3751692e9f66b8..0000000000000000000000000000000000000000 --- a/build/third_party_gn/icu/icu4c/BUILD.gn +++ /dev/null @@ -1,659 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("$build_root/ark.gni") -config("icu_config") { - visibility = [ ":*" ] - include_dirs = [ - "//third_party/icu/icu4c/source/common", - "//third_party/icu/icu4c/source/i18n", - "//third_party/icu/icu4c/source", - ] - cflags_cc = [ "-fPIC" ] -} - -ark_static_library("static_icustubdata") { - configs = [ - ":icu_config", - "$build_root/config/compiler:rtti", - ] - sources = [ "//third_party/icu/icu4c/source/stubdata/stubdata.cpp" ] - - cflags_cc = [ - "-O3", - "-W", - "-Wall", - "-pedantic", - "-Wpointer-arith", - "-Wwrite-strings", - "-std=c++11", - "-Wno-ignored-attributes", - ] - output_dir = "${root_out_dir}/third_party/icu/stubdata" - output_name = "stubdata" -} - -icu_common_source = [ - "//third_party/icu/icu4c/source/common/ubiditransform.cpp", - "//third_party/icu/icu4c/source/common/locutil.cpp", - "//third_party/icu/icu4c/source/common/cstring.cpp", - "//third_party/icu/icu4c/source/common/rbbiscan.cpp", - "//third_party/icu/icu4c/source/common/utrie.cpp", - "//third_party/icu/icu4c/source/common/cwchar.cpp", - "//third_party/icu/icu4c/source/common/bytestriebuilder.cpp", - "//third_party/icu/icu4c/source/common/umapfile.cpp", - "//third_party/icu/icu4c/source/common/uenum.cpp", - "//third_party/icu/icu4c/source/common/putil.cpp", - "//third_party/icu/icu4c/source/common/bytestrieiterator.cpp", - "//third_party/icu/icu4c/source/common/unifunct.cpp", - "//third_party/icu/icu4c/source/common/rbbistbl.cpp", - "//third_party/icu/icu4c/source/common/bytestrie.cpp", - "//third_party/icu/icu4c/source/common/ucptrie.cpp", - "//third_party/icu/icu4c/source/common/errorcode.cpp", - "//third_party/icu/icu4c/source/common/unames.cpp", - "//third_party/icu/icu4c/source/common/restrace.cpp", - "//third_party/icu/icu4c/source/common/util.cpp", - "//third_party/icu/icu4c/source/common/sharedobject.cpp", - "//third_party/icu/icu4c/source/common/bmpset.cpp", - "//third_party/icu/icu4c/source/common/servlk.cpp", - "//third_party/icu/icu4c/source/common/ustrcase_locale.cpp", - "//third_party/icu/icu4c/source/common/localeprioritylist.cpp", - "//third_party/icu/icu4c/source/common/ucnvbocu.cpp", - "//third_party/icu/icu4c/source/common/ucharstrieiterator.cpp", - "//third_party/icu/icu4c/source/common/unisetspan.cpp", - "//third_party/icu/icu4c/source/common/locavailable.cpp", - "//third_party/icu/icu4c/source/common/unistr.cpp", - "//third_party/icu/icu4c/source/common/ustr_wcs.cpp", - "//third_party/icu/icu4c/source/common/ucnv_err.cpp", - "//third_party/icu/icu4c/source/common/ucnv_lmb.cpp", - "//third_party/icu/icu4c/source/common/rbbidata.cpp", - "//third_party/icu/icu4c/source/common/uarrsort.cpp", - "//third_party/icu/icu4c/source/common/ucnv2022.cpp", - "//third_party/icu/icu4c/source/common/uresbund.cpp", - "//third_party/icu/icu4c/source/common/ucnvsel.cpp", - "//third_party/icu/icu4c/source/common/unistr_titlecase_brkiter.cpp", - "//third_party/icu/icu4c/source/common/loadednormalizer2impl.cpp", - "//third_party/icu/icu4c/source/common/ustring.cpp", - "//third_party/icu/icu4c/source/common/unifilt.cpp", - "//third_party/icu/icu4c/source/common/ubrk.cpp", - "//third_party/icu/icu4c/source/common/bytesinkutil.cpp", - "//third_party/icu/icu4c/source/common/localebuilder.cpp", - "//third_party/icu/icu4c/source/common/rbbi_cache.cpp", - "//third_party/icu/icu4c/source/common/ucnvhz.cpp", - "//third_party/icu/icu4c/source/common/uniset_closure.cpp", - "//third_party/icu/icu4c/source/common/uloc.cpp", - "//third_party/icu/icu4c/source/common/utypes.cpp", - "//third_party/icu/icu4c/source/common/ucnv_u16.cpp", - "//third_party/icu/icu4c/source/common/uniset_props.cpp", - "//third_party/icu/icu4c/source/common/locbased.cpp", - "//third_party/icu/icu4c/source/common/unistr_cnv.cpp", - "//third_party/icu/icu4c/source/common/ucnv_ct.cpp", - "//third_party/icu/icu4c/source/common/unormcmp.cpp", - "//third_party/icu/icu4c/source/common/wintz.cpp", - "//third_party/icu/icu4c/source/common/ruleiter.cpp", - "//third_party/icu/icu4c/source/common/utrie2.cpp", - "//third_party/icu/icu4c/source/common/locresdata.cpp", - "//third_party/icu/icu4c/source/common/ucnv_u8.cpp", - "//third_party/icu/icu4c/source/common/uscript_props.cpp", - "//third_party/icu/icu4c/source/common/locdspnm.cpp", - "//third_party/icu/icu4c/source/common/locid.cpp", - "//third_party/icu/icu4c/source/common/rbbitblb.cpp", - "//third_party/icu/icu4c/source/common/icudataver.cpp", - "//third_party/icu/icu4c/source/common/ubidi.cpp", - "//third_party/icu/icu4c/source/common/brkiter.cpp", - "//third_party/icu/icu4c/source/common/uvectr32.cpp", - "//third_party/icu/icu4c/source/common/usc_impl.cpp", - "//third_party/icu/icu4c/source/common/normlzr.cpp", - "//third_party/icu/icu4c/source/common/icuplug.cpp", - "//third_party/icu/icu4c/source/common/uvector.cpp", - "//third_party/icu/icu4c/source/common/ucnv_set.cpp", - "//third_party/icu/icu4c/source/common/udataswp.cpp", - "//third_party/icu/icu4c/source/common/uhash_us.cpp", - "//third_party/icu/icu4c/source/common/rbbisetb.cpp", - "//third_party/icu/icu4c/source/common/ubidi_props.cpp", - "//third_party/icu/icu4c/source/common/ucmndata.cpp", - "//third_party/icu/icu4c/source/common/locdistance.cpp", - "//third_party/icu/icu4c/source/common/serv.cpp", - "//third_party/icu/icu4c/source/common/utrie_swap.cpp", - "//third_party/icu/icu4c/source/common/uchar.cpp", - "//third_party/icu/icu4c/source/common/uloc_tag.cpp", - "//third_party/icu/icu4c/source/common/ustr_titlecase_brkiter.cpp", - "//third_party/icu/icu4c/source/common/pluralmap.cpp", - "//third_party/icu/icu4c/source/common/lsr.cpp", - "//third_party/icu/icu4c/source/common/uhash.cpp", - "//third_party/icu/icu4c/source/common/propname.cpp", - "//third_party/icu/icu4c/source/common/ucnvlat1.cpp", - "//third_party/icu/icu4c/source/common/ucnv_ext.cpp", - "//third_party/icu/icu4c/source/common/ubidiln.cpp", - "//third_party/icu/icu4c/source/common/ucnv_cb.cpp", - "//third_party/icu/icu4c/source/common/static_unicode_sets.cpp", - "//third_party/icu/icu4c/source/common/dictbe.cpp", - "//third_party/icu/icu4c/source/common/stringtriebuilder.cpp", - "//third_party/icu/icu4c/source/common/uvectr64.cpp", - "//third_party/icu/icu4c/source/common/patternprops.cpp", - "//third_party/icu/icu4c/source/common/propsvec.cpp", - "//third_party/icu/icu4c/source/common/ustrenum.cpp", - "//third_party/icu/icu4c/source/common/ucnv_u32.cpp", - "//third_party/icu/icu4c/source/common/ustr_cnv.cpp", - "//third_party/icu/icu4c/source/common/edits.cpp", - "//third_party/icu/icu4c/source/common/loclikely.cpp", - "//third_party/icu/icu4c/source/common/parsepos.cpp", - "//third_party/icu/icu4c/source/common/loclikelysubtags.cpp", - "//third_party/icu/icu4c/source/common/uloc_keytype.cpp", - "//third_party/icu/icu4c/source/common/appendable.cpp", - "//third_party/icu/icu4c/source/common/filteredbrk.cpp", - "//third_party/icu/icu4c/source/common/ucharstrie.cpp", - "//third_party/icu/icu4c/source/common/uiter.cpp", - "//third_party/icu/icu4c/source/common/messagepattern.cpp", - "//third_party/icu/icu4c/source/common/servrbf.cpp", - "//third_party/icu/icu4c/source/common/rbbirb.cpp", - "//third_party/icu/icu4c/source/common/uinit.cpp", - "//third_party/icu/icu4c/source/common/stringpiece.cpp", - "//third_party/icu/icu4c/source/common/normalizer2impl.cpp", - "//third_party/icu/icu4c/source/common/ucharstriebuilder.cpp", - "//third_party/icu/icu4c/source/common/uobject.cpp", - "//third_party/icu/icu4c/source/common/ushape.cpp", - "//third_party/icu/icu4c/source/common/ucasemap.cpp", - "//third_party/icu/icu4c/source/common/uinvchar.cpp", - "//third_party/icu/icu4c/source/common/utf_impl.cpp", - "//third_party/icu/icu4c/source/common/ustack.cpp", - "//third_party/icu/icu4c/source/common/characterproperties.cpp", - "//third_party/icu/icu4c/source/common/rbbi.cpp", - "//third_party/icu/icu4c/source/common/ucasemap_titlecase_brkiter.cpp", - "//third_party/icu/icu4c/source/common/caniter.cpp", - "//third_party/icu/icu4c/source/common/ucnv_bld.cpp", - "//third_party/icu/icu4c/source/common/ucln_cmn.cpp", - "//third_party/icu/icu4c/source/common/chariter.cpp", - "//third_party/icu/icu4c/source/common/punycode.cpp", - "//third_party/icu/icu4c/source/common/ustrtrns.cpp", - "//third_party/icu/icu4c/source/common/ucnvmbcs.cpp", - "//third_party/icu/icu4c/source/common/bytestream.cpp", - "//third_party/icu/icu4c/source/common/servlkf.cpp", - "//third_party/icu/icu4c/source/common/udatamem.cpp", - "//third_party/icu/icu4c/source/common/ucnv_io.cpp", - "//third_party/icu/icu4c/source/common/dtintrv.cpp", - "//third_party/icu/icu4c/source/common/cstr.cpp", - "//third_party/icu/icu4c/source/common/ulist.cpp", - "//third_party/icu/icu4c/source/common/ucnvisci.cpp", - "//third_party/icu/icu4c/source/common/brkeng.cpp", - "//third_party/icu/icu4c/source/common/localematcher.cpp", - "//third_party/icu/icu4c/source/common/umutablecptrie.cpp", - "//third_party/icu/icu4c/source/common/locdispnames.cpp", - "//third_party/icu/icu4c/source/common/uchriter.cpp", - "//third_party/icu/icu4c/source/common/uresdata.cpp", - "//third_party/icu/icu4c/source/common/unifiedcache.cpp", - "//third_party/icu/icu4c/source/common/dictionarydata.cpp", - "//third_party/icu/icu4c/source/common/uscript.cpp", - "//third_party/icu/icu4c/source/common/ucnv_u7.cpp", - "//third_party/icu/icu4c/source/common/unistr_case.cpp", - "//third_party/icu/icu4c/source/common/ucat.cpp", - "//third_party/icu/icu4c/source/common/resource.cpp", - "//third_party/icu/icu4c/source/common/usprep.cpp", - "//third_party/icu/icu4c/source/common/ucnvdisp.cpp", - "//third_party/icu/icu4c/source/common/uniset.cpp", - "//third_party/icu/icu4c/source/common/ucnv.cpp", - "//third_party/icu/icu4c/source/common/ucnvscsu.cpp", - "//third_party/icu/icu4c/source/common/uset_props.cpp", - "//third_party/icu/icu4c/source/common/umutex.cpp", - "//third_party/icu/icu4c/source/common/ucnv_cnv.cpp", - "//third_party/icu/icu4c/source/common/locmap.cpp", - "//third_party/icu/icu4c/source/common/resbund.cpp", - "//third_party/icu/icu4c/source/common/filterednormalizer2.cpp", - "//third_party/icu/icu4c/source/common/uprops.cpp", - "//third_party/icu/icu4c/source/common/schriter.cpp", - "//third_party/icu/icu4c/source/common/simpleformatter.cpp", - "//third_party/icu/icu4c/source/common/uts46.cpp", - "//third_party/icu/icu4c/source/common/ucol_swp.cpp", - "//third_party/icu/icu4c/source/common/udata.cpp", - "//third_party/icu/icu4c/source/common/ustrfmt.cpp", - "//third_party/icu/icu4c/source/common/servslkf.cpp", - "//third_party/icu/icu4c/source/common/servls.cpp", - "//third_party/icu/icu4c/source/common/unistr_props.cpp", - "//third_party/icu/icu4c/source/common/utrace.cpp", - "//third_party/icu/icu4c/source/common/utrie2_builder.cpp", - "//third_party/icu/icu4c/source/common/ucase.cpp", - "//third_party/icu/icu4c/source/common/cmemory.cpp", - "//third_party/icu/icu4c/source/common/uset.cpp", - "//third_party/icu/icu4c/source/common/unistr_case_locale.cpp", - "//third_party/icu/icu4c/source/common/ures_cnv.cpp", - "//third_party/icu/icu4c/source/common/charstr.cpp", - "//third_party/icu/icu4c/source/common/uidna.cpp", - "//third_party/icu/icu4c/source/common/normalizer2.cpp", - "//third_party/icu/icu4c/source/common/resbund_cnv.cpp", - "//third_party/icu/icu4c/source/common/umath.cpp", - "//third_party/icu/icu4c/source/common/utext.cpp", - "//third_party/icu/icu4c/source/common/ucurr.cpp", - "//third_party/icu/icu4c/source/common/util_props.cpp", - "//third_party/icu/icu4c/source/common/unorm.cpp", - "//third_party/icu/icu4c/source/common/ubidiwrt.cpp", - "//third_party/icu/icu4c/source/common/usetiter.cpp", - "//third_party/icu/icu4c/source/common/rbbinode.cpp", - "//third_party/icu/icu4c/source/common/ustrcase.cpp", - "//third_party/icu/icu4c/source/common/servnotf.cpp", - "//third_party/icu/icu4c/source/ohos/init_data.cpp", -] - -icu_i18n_source = [ - "//third_party/icu/icu4c/source/i18n/number_capi.cpp", - "//third_party/icu/icu4c/source/i18n/upluralrules.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_currency.cpp", - "//third_party/icu/icu4c/source/i18n/ufieldpositer.cpp", - "//third_party/icu/icu4c/source/i18n/number_output.cpp", - "//third_party/icu/icu4c/source/i18n/number_currencysymbols.cpp", - "//third_party/icu/icu4c/source/i18n/curramt.cpp", - "//third_party/icu/icu4c/source/i18n/alphaindex.cpp", - "//third_party/icu/icu4c/source/i18n/indiancal.cpp", - "//third_party/icu/icu4c/source/i18n/dayperiodrules.cpp", - "//third_party/icu/icu4c/source/i18n/quantityformatter.cpp", - "//third_party/icu/icu4c/source/i18n/collationfastlatinbuilder.cpp", - "//third_party/icu/icu4c/source/i18n/csrucode.cpp", - "//third_party/icu/icu4c/source/i18n/measunit_extra.cpp", - "//third_party/icu/icu4c/source/i18n/ethpccal.cpp", - "//third_party/icu/icu4c/source/i18n/anytrans.cpp", - "//third_party/icu/icu4c/source/i18n/number_scientific.cpp", - "//third_party/icu/icu4c/source/i18n/cpdtrans.cpp", - "//third_party/icu/icu4c/source/i18n/regexst.cpp", - "//third_party/icu/icu4c/source/i18n/numfmt.cpp", - "//third_party/icu/icu4c/source/i18n/formattedvalue.cpp", - "//third_party/icu/icu4c/source/i18n/unesctrn.cpp", - "//third_party/icu/icu4c/source/i18n/ucoleitr.cpp", - "//third_party/icu/icu4c/source/i18n/tmutamt.cpp", - "//third_party/icu/icu4c/source/i18n/transreg.cpp", - "//third_party/icu/icu4c/source/i18n/unum.cpp", - "//third_party/icu/icu4c/source/i18n/number_longnames.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_affixes.cpp", - "//third_party/icu/icu4c/source/i18n/plurrule.cpp", - "//third_party/icu/icu4c/source/i18n/zrule.cpp", - "//third_party/icu/icu4c/source/i18n/collationrootelements.cpp", - "//third_party/icu/icu4c/source/i18n/currunit.cpp", - "//third_party/icu/icu4c/source/i18n/funcrepl.cpp", - "//third_party/icu/icu4c/source/i18n/collationdatareader.cpp", - "//third_party/icu/icu4c/source/i18n/buddhcal.cpp", - "//third_party/icu/icu4c/source/i18n/number_decimalquantity.cpp", - "//third_party/icu/icu4c/source/i18n/scriptset.cpp", - "//third_party/icu/icu4c/source/i18n/fmtable.cpp", - "//third_party/icu/icu4c/source/i18n/regextxt.cpp", - "//third_party/icu/icu4c/source/i18n/bocsu.cpp", - "//third_party/icu/icu4c/source/i18n/olsontz.cpp", - "//third_party/icu/icu4c/source/i18n/utmscale.cpp", - "//third_party/icu/icu4c/source/i18n/ucol.cpp", - "//third_party/icu/icu4c/source/i18n/currfmt.cpp", - "//third_party/icu/icu4c/source/i18n/hebrwcal.cpp", - "//third_party/icu/icu4c/source/i18n/ucol_sit.cpp", - "//third_party/icu/icu4c/source/i18n/rbnf.cpp", - "//third_party/icu/icu4c/source/i18n/decContext.cpp", - "//third_party/icu/icu4c/source/i18n/collationdatawriter.cpp", - "//third_party/icu/icu4c/source/i18n/csr2022.cpp", - "//third_party/icu/icu4c/source/i18n/dtrule.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_validators.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_parsednumber.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-fast-dtoa.cpp", - "//third_party/icu/icu4c/source/i18n/choicfmt.cpp", - "//third_party/icu/icu4c/source/i18n/format.cpp", - "//third_party/icu/icu4c/source/i18n/reldatefmt.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-double-to-string.cpp", - "//third_party/icu/icu4c/source/i18n/rbt_data.cpp", - "//third_party/icu/icu4c/source/i18n/smpdtfmt.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-bignum-dtoa.cpp", - "//third_party/icu/icu4c/source/i18n/number_padding.cpp", - "//third_party/icu/icu4c/source/i18n/vtzone.cpp", - "//third_party/icu/icu4c/source/i18n/region.cpp", - "//third_party/icu/icu4c/source/i18n/coptccal.cpp", - "//third_party/icu/icu4c/source/i18n/datefmt.cpp", - "//third_party/icu/icu4c/source/i18n/formatted_string_builder.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_impl.cpp", - "//third_party/icu/icu4c/source/i18n/plurfmt.cpp", - "//third_party/icu/icu4c/source/i18n/rematch.cpp", - "//third_party/icu/icu4c/source/i18n/simpletz.cpp", - "//third_party/icu/icu4c/source/i18n/search.cpp", - "//third_party/icu/icu4c/source/i18n/number_mapper.cpp", - "//third_party/icu/icu4c/source/i18n/inputext.cpp", - "//third_party/icu/icu4c/source/i18n/dtptngen.cpp", - "//third_party/icu/icu4c/source/i18n/coleitr.cpp", - "//third_party/icu/icu4c/source/i18n/collationweights.cpp", - "//third_party/icu/icu4c/source/i18n/number_modifiers.cpp", - "//third_party/icu/icu4c/source/i18n/scientificnumberformatter.cpp", - "//third_party/icu/icu4c/source/i18n/vzone.cpp", - "//third_party/icu/icu4c/source/i18n/fphdlimp.cpp", - "//third_party/icu/icu4c/source/i18n/udatpg.cpp", - "//third_party/icu/icu4c/source/i18n/collationfcd.cpp", - "//third_party/icu/icu4c/source/i18n/tridpars.cpp", - "//third_party/icu/icu4c/source/i18n/csmatch.cpp", - "//third_party/icu/icu4c/source/i18n/dangical.cpp", - "//third_party/icu/icu4c/source/i18n/ulocdata.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-strtod.cpp", - "//third_party/icu/icu4c/source/i18n/erarules.cpp", - "//third_party/icu/icu4c/source/i18n/numsys.cpp", - "//third_party/icu/icu4c/source/i18n/csdetect.cpp", - "//third_party/icu/icu4c/source/i18n/japancal.cpp", - "//third_party/icu/icu4c/source/i18n/collation.cpp", - "//third_party/icu/icu4c/source/i18n/uregex.cpp", - "//third_party/icu/icu4c/source/i18n/timezone.cpp", - "//third_party/icu/icu4c/source/i18n/strmatch.cpp", - "//third_party/icu/icu4c/source/i18n/decNumber.cpp", - "//third_party/icu/icu4c/source/i18n/nortrans.cpp", - "//third_party/icu/icu4c/source/i18n/sortkey.cpp", - "//third_party/icu/icu4c/source/i18n/ulistformatter.cpp", - "//third_party/icu/icu4c/source/i18n/tzgnames.cpp", - "//third_party/icu/icu4c/source/i18n/number_multiplier.cpp", - "//third_party/icu/icu4c/source/i18n/ztrans.cpp", - "//third_party/icu/icu4c/source/i18n/persncal.cpp", - "//third_party/icu/icu4c/source/i18n/number_utils.cpp", - "//third_party/icu/icu4c/source/i18n/csrmbcs.cpp", - "//third_party/icu/icu4c/source/i18n/taiwncal.cpp", - "//third_party/icu/icu4c/source/i18n/dtitvinf.cpp", - "//third_party/icu/icu4c/source/i18n/astro.cpp", - "//third_party/icu/icu4c/source/i18n/number_patternmodifier.cpp", - "//third_party/icu/icu4c/source/i18n/rulebasedcollator.cpp", - "//third_party/icu/icu4c/source/i18n/msgfmt.cpp", - "//third_party/icu/icu4c/source/i18n/stsearch.cpp", - "//third_party/icu/icu4c/source/i18n/number_affixutils.cpp", - "//third_party/icu/icu4c/source/i18n/quant.cpp", - "//third_party/icu/icu4c/source/i18n/calendar.cpp", - "//third_party/icu/icu4c/source/i18n/collationroot.cpp", - "//third_party/icu/icu4c/source/i18n/rbt_rule.cpp", - "//third_party/icu/icu4c/source/i18n/number_compact.cpp", - "//third_party/icu/icu4c/source/i18n/name2uni.cpp", - "//third_party/icu/icu4c/source/i18n/chnsecal.cpp", - "//third_party/icu/icu4c/source/i18n/csrutf8.cpp", - "//third_party/icu/icu4c/source/i18n/basictz.cpp", - "//third_party/icu/icu4c/source/i18n/reldtfmt.cpp", - "//third_party/icu/icu4c/source/i18n/nultrans.cpp", - "//third_party/icu/icu4c/source/i18n/number_grouping.cpp", - "//third_party/icu/icu4c/source/i18n/rbt_pars.cpp", - "//third_party/icu/icu4c/source/i18n/nounit.cpp", - "//third_party/icu/icu4c/source/i18n/winnmfmt.cpp", - "//third_party/icu/icu4c/source/i18n/uregexc.cpp", - "//third_party/icu/icu4c/source/i18n/fpositer.cpp", - "//third_party/icu/icu4c/source/i18n/tmutfmt.cpp", - "//third_party/icu/icu4c/source/i18n/compactdecimalformat.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_decimal.cpp", - "//third_party/icu/icu4c/source/i18n/number_notation.cpp", - "//third_party/icu/icu4c/source/i18n/uspoof_conf.cpp", - "//third_party/icu/icu4c/source/i18n/utf16collationiterator.cpp", - "//third_party/icu/icu4c/source/i18n/udat.cpp", - "//third_party/icu/icu4c/source/i18n/number_skeletons.cpp", - "//third_party/icu/icu4c/source/i18n/utrans.cpp", - "//third_party/icu/icu4c/source/i18n/number_rounding.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-bignum.cpp", - "//third_party/icu/icu4c/source/i18n/number_asformat.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-string-to-double.cpp", - "//third_party/icu/icu4c/source/i18n/rbtz.cpp", - "//third_party/icu/icu4c/source/i18n/csrsbcs.cpp", - "//third_party/icu/icu4c/source/i18n/selfmt.cpp", - "//third_party/icu/icu4c/source/i18n/tztrans.cpp", - "//third_party/icu/icu4c/source/i18n/uspoof_impl.cpp", - "//third_party/icu/icu4c/source/i18n/regeximp.cpp", - "//third_party/icu/icu4c/source/i18n/measure.cpp", - "//third_party/icu/icu4c/source/i18n/fmtable_cnv.cpp", - "//third_party/icu/icu4c/source/i18n/uspoof.cpp", - "//third_party/icu/icu4c/source/i18n/gregoimp.cpp", - "//third_party/icu/icu4c/source/i18n/umsg.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_symbols.cpp", - "//third_party/icu/icu4c/source/i18n/numrange_impl.cpp", - "//third_party/icu/icu4c/source/i18n/collationtailoring.cpp", - "//third_party/icu/icu4c/source/i18n/double-conversion-cached-powers.cpp", - "//third_party/icu/icu4c/source/i18n/udateintervalformat.cpp", - "//third_party/icu/icu4c/source/i18n/uni2name.cpp", - "//third_party/icu/icu4c/source/i18n/casetrn.cpp", - "//third_party/icu/icu4c/source/i18n/windtfmt.cpp", - "//third_party/icu/icu4c/source/i18n/listformatter.cpp", - "//third_party/icu/icu4c/source/i18n/uregion.cpp", - "//third_party/icu/icu4c/source/i18n/usearch.cpp", - "//third_party/icu/icu4c/source/i18n/brktrans.cpp", - "//third_party/icu/icu4c/source/i18n/gender.cpp", - "//third_party/icu/icu4c/source/i18n/collationruleparser.cpp", - "//third_party/icu/icu4c/source/i18n/rbt.cpp", - "//third_party/icu/icu4c/source/i18n/tzfmt.cpp", - "//third_party/icu/icu4c/source/i18n/dtfmtsym.cpp", - "//third_party/icu/icu4c/source/i18n/tolowtrn.cpp", - "//third_party/icu/icu4c/source/i18n/collationdatabuilder.cpp", - "//third_party/icu/icu4c/source/i18n/unumsys.cpp", - "//third_party/icu/icu4c/source/i18n/csrecog.cpp", - "//third_party/icu/icu4c/source/i18n/collationfastlatin.cpp", - "//third_party/icu/icu4c/source/i18n/esctrn.cpp", - "//third_party/icu/icu4c/source/i18n/collationdata.cpp", - "//third_party/icu/icu4c/source/i18n/titletrn.cpp", - "//third_party/icu/icu4c/source/i18n/ucal.cpp", - "//third_party/icu/icu4c/source/i18n/regexcmp.cpp", - "//third_party/icu/icu4c/source/i18n/wintzimpl.cpp", - "//third_party/icu/icu4c/source/i18n/decimfmt.cpp", - "//third_party/icu/icu4c/source/i18n/tmunit.cpp", - "//third_party/icu/icu4c/source/i18n/number_integerwidth.cpp", - "//third_party/icu/icu4c/source/i18n/ucsdet.cpp", - "//third_party/icu/icu4c/source/i18n/uspoof_build.cpp", - "//third_party/icu/icu4c/source/i18n/ucln_in.cpp", - "//third_party/icu/icu4c/source/i18n/measfmt.cpp", - "//third_party/icu/icu4c/source/i18n/formattedval_iterimpl.cpp", - "//third_party/icu/icu4c/source/i18n/toupptrn.cpp", - "//third_party/icu/icu4c/source/i18n/translit.cpp", - "//third_party/icu/icu4c/source/i18n/dtitvfmt.cpp", - "//third_party/icu/icu4c/source/i18n/dcfmtsym.cpp", - "//third_party/icu/icu4c/source/i18n/islamcal.cpp", - "//third_party/icu/icu4c/source/i18n/numrange_fluent.cpp", - "//third_party/icu/icu4c/source/i18n/gregocal.cpp", - "//third_party/icu/icu4c/source/i18n/zonemeta.cpp", - "//third_party/icu/icu4c/source/i18n/collationbuilder.cpp", - "//third_party/icu/icu4c/source/i18n/string_segment.cpp", - "//third_party/icu/icu4c/source/i18n/collationkeys.cpp", - "//third_party/icu/icu4c/source/i18n/coll.cpp", - "//third_party/icu/icu4c/source/i18n/uitercollationiterator.cpp", - "//third_party/icu/icu4c/source/i18n/nfsubs.cpp", - "//third_party/icu/icu4c/source/i18n/smpdtfst.cpp", - "//third_party/icu/icu4c/source/i18n/collationsettings.cpp", - "//third_party/icu/icu4c/source/i18n/formattedval_sbimpl.cpp", - "//third_party/icu/icu4c/source/i18n/strrepl.cpp", - "//third_party/icu/icu4c/source/i18n/standardplural.cpp", - "//third_party/icu/icu4c/source/i18n/ucol_res.cpp", - "//third_party/icu/icu4c/source/i18n/repattrn.cpp", - "//third_party/icu/icu4c/source/i18n/tznames_impl.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_compositions.cpp", - "//third_party/icu/icu4c/source/i18n/rbt_set.cpp", - "//third_party/icu/icu4c/source/i18n/currpinf.cpp", - "//third_party/icu/icu4c/source/i18n/collationsets.cpp", - "//third_party/icu/icu4c/source/i18n/cecal.cpp", - "//third_party/icu/icu4c/source/i18n/tzrule.cpp", - "//third_party/icu/icu4c/source/i18n/collationiterator.cpp", - "//third_party/icu/icu4c/source/i18n/numparse_scientific.cpp", - "//third_party/icu/icu4c/source/i18n/number_patternstring.cpp", - "//third_party/icu/icu4c/source/i18n/utf8collationiterator.cpp", - "//third_party/icu/icu4c/source/i18n/sharedbreakiterator.cpp", - "//third_party/icu/icu4c/source/i18n/number_fluent.cpp", - "//third_party/icu/icu4c/source/i18n/measunit.cpp", - "//third_party/icu/icu4c/source/i18n/collationcompare.cpp", - "//third_party/icu/icu4c/source/i18n/number_formatimpl.cpp", - "//third_party/icu/icu4c/source/i18n/number_decimfmtprops.cpp", - "//third_party/icu/icu4c/source/i18n/nfrs.cpp", - "//third_party/icu/icu4c/source/i18n/tznames.cpp", - "//third_party/icu/icu4c/source/i18n/remtrans.cpp", - "//third_party/icu/icu4c/source/i18n/nfrule.cpp", -] - -ark_shared_library("shared_icuuc") { - configs = [ - ":icu_config", - "$build_root/config/compiler:rtti", - ] - deps = [ ":static_icustubdata" ] - defines = [ - "U_ATTRIBUTE_DEPRECATED=", - "U_COMMON_IMPLEMENTATION", - "UPRV_BLOCK_MACRO_BEGIN=", - "UPRV_BLOCK_MACRO_END=", - "UCONFIG_USE_WINDOWS_LCID_MAPPING_API=0", - "_REENTRANT", - ] - sources = icu_common_source - cflags_cc = [ - "-O3", - "-W", - "-Wall", - "-pedantic", - "-Wpointer-arith", - "-Wwrite-strings", - "-Wno-error=unused-parameter", - "-Wno-error=unused-const-variable", - "-Wno-error=unneeded-internal-declaration", - "-std=c++11", - "-Wno-ignored-attributes", - ] - ldflags = [ - "-shared", - "-lm", - ] - output_name = "hmicuuc" -} - -ark_shared_library("shared_icui18n") { - sources = icu_i18n_source - configs = [ - ":icu_config", - "$build_root/config/compiler:rtti", - ] - deps = [ ":shared_icuuc" ] - defines = [ - "U_ATTRIBUTE_DEPRECATED=", - "U_I18N_IMPLEMENTATION", - "UPRV_BLOCK_MACRO_BEGIN=", - "UPRV_BLOCK_MACRO_END=", - "_REENTRANT", - "PIC", - ] - cflags_cc = [ - "-O3", - "-W", - "-Wall", - "-pedantic", - "-Wpointer-arith", - "-Wno-error=unused-parameter", - "-Wno-error=unused-const-variable", - "-Wno-error=implicit-float-conversion", - "-Wno-error=unneeded-internal-declaration", - "-Wwrite-strings", - "-std=c++11", - "-Wno-ignored-attributes", - ] - ldflags = [ - "-shared", - "-lm", - ] - if (!is_mingw) { - cflags_cc += [ "-fPIC" ] - ldflags += [ "-ldl" ] - } - output_name = "hmicui18n" -} - -ark_static_library("static_icuuc") { - configs = [ - ":icu_config", - "$build_root/config/compiler:rtti", - ] - deps = [ ":static_icustubdata" ] - defines = [ - "U_ATTRIBUTE_DEPRECATED=", - "U_COMMON_IMPLEMENTATION", - "U_STATIC_IMPLEMENTATION", - "UPRV_BLOCK_MACRO_BEGIN=", - "UPRV_BLOCK_MACRO_END=", - "UCONFIG_USE_WINDOWS_LCID_MAPPING_API=0", - "_REENTRANT", - ] - sources = icu_common_source - cflags_cc = [ - "-Os", - "-W", - "-Wall", - "-pedantic", - "-Wpointer-arith", - "-Wwrite-strings", - "-std=c++11", - "-Wno-error=unused-parameter", - "-Wno-error=unused-const-variable", - "-Wno-error=unneeded-internal-declaration", - "-fvisibility-inlines-hidden", - "-Wno-unused-function", - "-Wno-ignored-attributes", - ] - - cflags = [ - "-fvisibility=hidden", - "-fdata-sections", - "-ffunction-sections", - "-Os", - "-Wno-unused-function", - ] - - ldflags = [ - "-static", - "-ldl", - "-lm", - ] - - output_name = "hmicuuc" -} - -ark_static_library("static_icui18n") { - sources = icu_i18n_source - configs = [ - ":icu_config", - "$build_root/config/compiler:rtti", - ] - deps = [ ":static_icuuc" ] - defines = [ - "U_ATTRIBUTE_DEPRECATED=", - "U_I18N_IMPLEMENTATION", - "U_STATIC_IMPLEMENTATION", - "UPRV_BLOCK_MACRO_BEGIN=", - "UPRV_BLOCK_MACRO_END=", - "_REENTRANT", - "PIC", - ] - - cflags_cc = [ - "-Os", - "-W", - "-Wall", - "-pedantic", - "-Wpointer-arith", - "-Wwrite-strings", - "-Wno-error=unused-parameter", - "-Wno-error=unused-const-variable", - "-Wno-error=implicit-float-conversion", - "-Wno-error=unneeded-internal-declaration", - "-std=c++11", - "-fvisibility-inlines-hidden", - "-fno-exceptions", - "-Wno-ignored-attributes", - ] - - if (is_mingw) { - cflags_cc += [ "-DWINVER=0x0601" ] - } else { - cflags_cc += [ "-fPIC" ] - } - - cflags = [ - "-fvisibility=hidden", - "-fdata-sections", - "-ffunction-sections", - "-Os", - ] - - ldflags = [ - "-static", - "-ldl", - "-lm", - ] - output_name = "hmicui18n" -} diff --git a/build/third_party_gn/zlib/BUILD.gn b/build/third_party_gn/zlib/BUILD.gn deleted file mode 100644 index b6fc3603b71d355b9a83ff1e5d14e9002012b3fe..0000000000000000000000000000000000000000 --- a/build/third_party_gn/zlib/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("$build_root/ark.gni") - -config("zlib_config") { - cflags = [ - "-Wno-incompatible-pointer-types", - "-Werror", - "-Wimplicit-function-declaration", - "-fPIC", - ] -} - -config("zlib_public_config") { - include_dirs = [ "." ] -} - -ark_static_library("libz") { - sources = [ - "//third_party/zlib/adler32.c", - "//third_party/zlib/compress.c", - "//third_party/zlib/contrib/minizip/ioapi.c", - "//third_party/zlib/contrib/minizip/unzip.c", - "//third_party/zlib/contrib/minizip/zip.c", - "//third_party/zlib/crc32.c", - "//third_party/zlib/crc32.h", - "//third_party/zlib/deflate.c", - "//third_party/zlib/deflate.h", - "//third_party/zlib/gzclose.c", - "//third_party/zlib/gzguts.h", - "//third_party/zlib/gzlib.c", - "//third_party/zlib/gzread.c", - "//third_party/zlib/gzwrite.c", - "//third_party/zlib/infback.c", - "//third_party/zlib/inffast.c", - "//third_party/zlib/inffast.h", - "//third_party/zlib/inffixed.h", - "//third_party/zlib/inflate.c", - "//third_party/zlib/inflate.h", - "//third_party/zlib/inftrees.c", - "//third_party/zlib/inftrees.h", - "//third_party/zlib/trees.c", - "//third_party/zlib/trees.h", - "//third_party/zlib/uncompr.c", - "//third_party/zlib/zconf.h", - "//third_party/zlib/zlib.h", - "//third_party/zlib/zutil.c", - "//third_party/zlib/zutil.h", - ] - configs = [ ":zlib_config" ] - public_configs = [ ":zlib_public_config" ] -} diff --git a/docs/development-example-zh.md b/docs/development-example-zh.md index 8a53e172c0119db8129671e8e04fe260f57e5746..bdebde868d86ab6881f72ea5a0a309cbf1902655 100644 --- a/docs/development-example-zh.md +++ b/docs/development-example-zh.md @@ -31,13 +31,13 @@ 编译arm32版本: ``` - ./build.sh --product-name rk3568 --build-target libarkruntime --build-target ark_js_runtime --build-target ld-musl-arm.so.1 + ./build.sh --product-name rk3568 --build-target ark_js_runtime --build-target ld-musl-arm.so.1 ``` 2. 编译方舟前端,编译命令: ``` - ./build.sh --product-name rk3568 --build-target ark_ts2abc_build + ./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc_build ``` **说明**:上述编译命令为release版本,且执行路径为项目根目录。编译debug版本需增加编译选项:--gn-args is_debug=true。 @@ -55,20 +55,20 @@ 1. 通过方舟前端生成hello-world.abc文件,编译命令: ``` - node --expose-gc /your code path/out/rk3568/clang_x64/ark/ark/build/src/index.js hello-world.js + node --expose-gc /your code path/out/hispark_taurus/clang_x64/ark/ark/build/src/index.js hello-world.js ``` 2. 执行hello-world.abc文件: 1. 设置搜索路径: ``` - export LD_LIBRARY_PATH= /your code path/out/rk3568/clang_x64/ark/ark:/your code path/out/rk3568/clang_x64/ark/ark_js_runtime:/your code path/out/rk3568/clang_x64/global/i18n_standard:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib + export LD_LIBRARY_PATH= /your code path/out/hispark_taurus/clang_x64/ark/ark:/your code path/out/hispark_taurus/clang_x64/ark/ark_js_runtime:/your code path/out/hispark_taurus/clang_x64/global/i18n_standard:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib ``` 2. 执行ark\_js\_vm: ``` - /your code path/out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm hello-world.abc + /your code path/out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm hello-world.abc ``` 执行结果如下: @@ -92,7 +92,7 @@ 执行如下命令,结果输出到output.pa文件中: ``` -./your code path/out/rk3568/clang_x64/ark/ark/ark_disasm hello-world.abc output.pa +./your code path/out/hispark_taurus/clang_x64/ark/ark/ark_disasm hello-world.abc output.pa ``` hello-world.abc反汇编结果如下: @@ -139,13 +139,13 @@ hello-world.abc反汇编结果如下: 1. 编译方舟运行时,编译命令: ``` -./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages +./build.sh --product-name hispark_taurus_standard --build-target ark_js_host_linux_tools_packages ``` 1. 编译方舟前端,编译命令: ``` -./build.sh --product-name rk3568 --build-target ark_ts2abc_build +./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc_build ``` **说明**:编译命令执行路径为项目根目录。 @@ -260,16 +260,20 @@ python3 test262/run_test262.py [options] python3 test262/run_test262.py --es51 ``` -- 仅运行ES2015测试用: +- 仅运行ES2015测试用例: ``` - python3 test262/run_test262.py --es2015 only + python3 test262/run_test262.py --es2015 ``` +- 仅运行ES2021测试用例: -- 运行ES2015和ES51所有测试用例: + ``` + python3 test262/run_test262.py --es2021 only + +- 运行ES2015和ES51和ES2021所有测试用例: ``` - python3 test262/run_test262.py --es2015 all + python3 test262/run_test262.py --es2021 all ``` - 运行单一测试用例: @@ -305,7 +309,7 @@ node test262/harness/bin/run.js --hostType=panda --hostPath=python3 - --hostArgs='-B test262/run_sunspider.py --ark-tool=/your code path/out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/rk3568/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/rk3568/clang_x64/ark/ark:/your code path/out/rk3568/clang_x64/global/i18n:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ --ark-frontend=ts2panda' + --hostArgs='-B test262/run_sunspider.py --ark-tool=/your code path/out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/hispark_taurus/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/hispark_taurus/clang_x64/ark/ark:/your code path/out/hispark_taurus/clang_x64/global/i18n:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ --ark-frontend=ts2panda' --threads=15 --mode=only strict mode --timeout=60000 diff --git a/docs/development-example.md b/docs/development-example.md index 444e4a42e4f93eccb426fe6f31a3194095d62cdd..ef262d35b77d7d9ec84d6ec3313aaf977105c445 100644 --- a/docs/development-example.md +++ b/docs/development-example.md @@ -29,7 +29,7 @@ This section describes how to develop and test ARK runtime. arm32: ``` - ./build.sh --product-name rk3568 --build-target libarkruntime --build-target ark_js_runtime --build-target ld-musl-arm.so.1 + ./build.sh --product-name rk3568 --build-target ark_js_runtime --build-target ld-musl-arm.so.1 ``` **NOTE**: Run the compilation commands in the project root directory. @@ -48,20 +48,20 @@ Run the **hello-world.js** file. 1. Use the ARK frontend to create the **hello-world.abc** file. ``` - node --expose-gc /your code path/out/rk3568/clang_x64/ark/ark/build/src/index.js hello-world.js + node --expose-gc /your code path/out/hispark_taurus/clang_x64/ark/ark/build/src/index.js hello-world.js ``` 2. Run the **hello-world.abc** file. 1. Set the search path. ``` - export LD_LIBRARY_PATH= out/rk3568/clang_x64/ark/ark:out/rk3568/clang_x64/ark/ark_js_runtime:out/rk3568/clang_x64/global/i18n_standard:prebuilts/clang/ohos/linux-x86_64/llvm/lib + export LD_LIBRARY_PATH= out/hispark_taurus/clang_x64/ark/ark:out/hispark_taurus/clang_x64/ark/ark_js_runtime:out/hispark_taurus/clang_x64/global/i18n_standard:prebuilts/clang/ohos/linux-x86_64/llvm/lib ``` 2. Run **ark\_js\_vm**. ``` - /your code path/out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm hello-world.abc + /your code path/out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm hello-world.abc ``` The execution result is as follows: @@ -77,7 +77,7 @@ Run the **hello-world.js** file. Run the following command to export the result to the **output** file: ``` -./your code path/out/rk3568/clang_x64/ark/ark/ark_disasm hello-world.abc output +./your code path/out/hispark_taurus/clang_x64/ark/ark/ark_disasm hello-world.abc output ``` The output is as follows: @@ -124,13 +124,13 @@ The output is as follows: 1. Run the following command to compile ARK runtime: ``` -./build.sh --product-name rk3568 --build-target ark_js_host_linux_tools_packages +./build.sh --product-name hispark_taurus_standard --build-target ark_js_host_linux_tools_packages ``` 2. Run the following command to compile the ARK frontend: ``` -./build.sh --product-name rk3568 --build-target ark_ts2abc_build +./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc_build ``` **NOTE**: Run the compilation commands in the project root directory. @@ -251,13 +251,18 @@ Run the script in _Project root directory_**/ark/ts2abc**. - Run test case ES2015 only. ``` - python3 test262/run_test262.py --es2015 only + python3 test262/run_test262.py --es2015 ``` -- Run all ES2015 and ES51 test cases. +- Run test case ES2021 only. ``` - python3 test262/run_test262.py --es2015 all + python3 test262/run_test262.py --es2021 only + +- Run all ES2015 and ES51 and ES2021 test cases. + + ``` + python3 test262/run_test262.py --es2021 all ``` - Run a test case. @@ -293,7 +298,7 @@ node test262/harness/bin/run.js --hostType=panda --hostPath=python3 - --hostArgs='-B test262/run_sunspider.py --ark-tool=/your code path/out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/rk3568/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/rk3568/clang_x64/ark/ark:/your code path/out/rk3568/clang_x64/global/i18n:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ --ark-frontend=ts2panda' + --hostArgs='-B test262/run_sunspider.py --ark-tool=/your code path/out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=/your code path/out/hispark_taurus/clang_x64/ark/ark/build/src/index.js --libs-dir=/your code path/out/hispark_taurus/clang_x64/ark/ark:/your code path/out/hispark_taurus/clang_x64/global/i18n:/your code path/prebuilts/clang/ohos/linux-x86_64/llvm/lib/ --ark-frontend=ts2panda' --threads=15 --mode=only strict mode --timeout=60000 diff --git a/docs/environment-setup-and-compilation-zh.md b/docs/environment-setup-and-compilation-zh.md index 47e6c17660ce63afcad25930e8fa7935399509dd..fea4f238a4d03719af47b44d6ae1c7685ed3afdd 100644 --- a/docs/environment-setup-and-compilation-zh.md +++ b/docs/environment-setup-and-compilation-zh.md @@ -14,7 +14,7 @@ Ubuntu版本要求18.04或20.04,详细环境搭建参考: 1. 首次编译: ``` - ./build.sh --product-name rk3568 + ./build.sh --product-name hispark_taurus_standard ``` 2. 首次编译后增量编译方舟运行时: @@ -31,13 +31,13 @@ Ubuntu版本要求18.04或20.04,详细环境搭建参考: 编译arm32版本: ``` - ./build.sh --product-name rk3568 --build-target libarkruntime --build-target ark_js_runtime --build-target ld-musl-arm.so.1 + ./build.sh --product-name rk3568 --build-target ark_js_runtime --build-target ld-musl-arm.so.1 ``` 3. 首次编译后增量编译方舟前端: ``` - ./build.sh --product-name rk3568 --build-target ark_ts2abc_build + ./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc_build ``` **说明**:上述编译命令为release版本,且执行路径为项目根目录。编译debug版本需增加编译选项:--gn-args is_debug=true。 @@ -45,9 +45,9 @@ Ubuntu版本要求18.04或20.04,详细环境搭建参考: 方舟相关的二进制文件在如下路径: ``` -out/rk3568/ark/ark/ -out/rk3568/ark/ark_js_runtime/ -out/rk3568/clang_x64/ark/ark/ -out/rk3568/clang_x64/ark/ark_js_runtime +out/hispark_taurus/ark/ark/ +out/hispark_taurus/ark/ark_js_runtime/ +out/hispark_taurus/clang_x64/ark/ark/ +out/hispark_taurus/clang_x64/ark/ark_js_runtime ``` diff --git a/docs/environment-setup-and-compilation.md b/docs/environment-setup-and-compilation.md index d8d0bfed8d8c8c5a31b93f295dab68c69485d291..5c73a9fe42c644e99cddc6053aecdef007e582cd 100644 --- a/docs/environment-setup-and-compilation.md +++ b/docs/environment-setup-and-compilation.md @@ -11,7 +11,7 @@ Use Ubuntu 18.04 or 20.04. For details about how to set up the environment, see: 1. First compilation: ``` - ./build.sh --product-name rk3568 + ./build.sh --product-name hispark_taurus_standard ``` 2. Compile an ARK runtime after the first compilation: @@ -28,13 +28,13 @@ Use Ubuntu 18.04 or 20.04. For details about how to set up the environment, see: arm32: ``` - ./build.sh --product-name rk3568 --build-target libarkruntime --build-target ark_js_runtime --build-target ld-musl-arm.so.1 + ./build.sh --product-name rk3568 --build-target ark_js_runtime --build-target ld-musl-arm.so.1 ``` 3. Compile the ARK frontend after the first compilation: ``` - ./build.sh --product-name rk3568 --build-target ark_ts2abc_build + ./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc_build ``` **NOTE**: Run the compilation commands in the project root directory. @@ -42,8 +42,8 @@ Use Ubuntu 18.04 or 20.04. For details about how to set up the environment, see: The binary files related to ARK are available in the following paths: ``` -out/rk3568/ark/ark/ -out/rk3568/ark/ark_js_runtime/ -out/rk3568/clang_x64/ark/ark/ -out/rk3568/clang_x64/ark/ark_js_runtime +out/hispark_taurus/ark/ark/ +out/hispark_taurus/ark/ark_js_runtime/ +out/hispark_taurus/clang_x64/ark/ark/ +out/hispark_taurus/clang_x64/ark/ark_js_runtime ``` diff --git a/docs/using-the-toolchain-zh.md b/docs/using-the-toolchain-zh.md index 50d489197f0ec48ca4448e1fab9e3294af48ed33..8ea6b4ecf92d2d18146f66ba420fd4b6e5f891c4 100644 --- a/docs/using-the-toolchain-zh.md +++ b/docs/using-the-toolchain-zh.md @@ -9,13 +9,13 @@ 构建编译: ``` -$ ./build.sh --product-name rk3568 --build-target ark_ts2abc_build +$ ./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc_build ``` 安装`node`和`npm`后, 使用前端工具: ``` -$ cd out/rk3568/clang_x64/ark/ark/build +$ cd out/hispark_taurus/clang_x64/ark/ark/build $ npm install $ node --expose-gc src/index.js [选项] file.js ``` diff --git a/docs/using-the-toolchain.md b/docs/using-the-toolchain.md index 637170afde25f93959cd7183c9fbdea386a5b486..fe1b811a5f1c0f2e4c3d2e3a18658a59a2443bda 100644 --- a/docs/using-the-toolchain.md +++ b/docs/using-the-toolchain.md @@ -9,13 +9,13 @@ Front-end tools, converting JS source code into ARK bytecode, can be built by sp Build tools: ``` -$ ./build.sh --product-name rk3568 --build-target ark_ts2abc +$ ./build.sh --product-name hispark_taurus_standard --build-target ark_ts2abc ``` Install `node` and `npm`, then use tools: ``` -$ cd out/rk3568/clang_x64/ark/ark/build +$ cd out/hispark_taurus/clang_x64/ark/ark/build $ npm install $ node --expose-gc src/index.js [option] file.js ``` diff --git a/ecmascript/accessor_data.h b/ecmascript/accessor_data.h index 4e132fecc420f480be218b0e1a10a44d93e6ed45..4d9e876e5bf0f6ed2d89a3eede68d7ef8904a934 100644 --- a/ecmascript/accessor_data.h +++ b/ecmascript/accessor_data.h @@ -30,7 +30,7 @@ public: using InternalGetFunc = JSTaggedValue (*)(JSThread *, const JSHandle &); using InternalSetFunc = bool (*)(JSThread *, const JSHandle &, const JSHandle &, bool); - static AccessorData *Cast(ObjectHeader *object) + static AccessorData *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsAccessorData() || JSTaggedValue(object).IsInternalAccessor()); return static_cast(object); @@ -81,7 +81,7 @@ enum class CompletionRecordType : uint8_t { class CompletionRecord final : public Record { public: - static CompletionRecord *Cast(ObjectHeader *object) + static CompletionRecord *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsCompletionRecord()); return static_cast(object); diff --git a/ecmascript/base/array_helper.cpp b/ecmascript/base/array_helper.cpp index b8e383859e0b3b1bbdd587c86b0674e63429be68..2735b363a7519e7669db59a900ce1ec5a03e5141 100644 --- a/ecmascript/base/array_helper.cpp +++ b/ecmascript/base/array_helper.cpp @@ -81,10 +81,11 @@ int32_t ArrayHelper::SortCompare(JSThread *thread, const JSHandle // d. Return v. if (!callbackfnHandle->IsUndefined()) { JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackfnHandle, undefined, undefined, 2); // 2: «x, y» - info.SetCallArg(valueX.GetTaggedValue(), valueY.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); + info->SetCallArg(valueX.GetTaggedValue(), valueY.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); if (callResult.IsInt()) { return callResult.GetInt(); } @@ -193,12 +194,13 @@ JSTaggedValue ArrayHelper::FlattenIntoArray(JSThread *thread, const JSHandleIsUndefined()) { - const size_t argsLength = 3; // 3: « element, sourceIndex, source » + const int32_t argsLength = 3; // 3: « element, sourceIndex, source » JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, mapperFunctionHandle, thisArg, undefined, argsLength); - info.SetCallArg(element.GetTaggedValue(), p.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue obj = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(element.GetTaggedValue(), p.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue obj = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); element.Update(obj); } diff --git a/ecmascript/base/atomic_helper.cpp b/ecmascript/base/atomic_helper.cpp index 950881094325693934435aaa1ce89790e7d22824..1ec2138072e776fdb750cc4e5d181281c5f6abdb 100644 --- a/ecmascript/base/atomic_helper.cpp +++ b/ecmascript/base/atomic_helper.cpp @@ -85,7 +85,7 @@ uint32_t AtomicHelper::ValidateAtomicAccess(JSThread *thread, const JSHandleGetByteOffset(); // 9. Return (accessIndex × elementSize) + offset. - uint32_t allOffset = index * elementSize + offset; + uint32_t allOffset = static_cast(index) * elementSize + offset; return allOffset; } diff --git a/ecmascript/base/builtins_base.h b/ecmascript/base/builtins_base.h index be50bb83cc00234aa705531d52f3a8d29a487dd1..1a7bbf6a7844c4bf048edbb23531ac2cb1106191 100644 --- a/ecmascript/base/builtins_base.h +++ b/ecmascript/base/builtins_base.h @@ -49,7 +49,7 @@ public: return msg->GetNewTarget(); } - static inline JSHandle GetCallArg(EcmaRuntimeCallInfo *msg, uint32_t position) + static inline JSHandle GetCallArg(EcmaRuntimeCallInfo *msg, int32_t position) { if (position >= msg->GetArgsNumber()) { JSThread *thread = msg->GetThread(); diff --git a/ecmascript/base/config.h b/ecmascript/base/config.h index 69ff97af1707a5b356129f81dd691f5420cff5fa..d67a96414b4ec0e4effee7ba660b960322bc5d0e 100644 --- a/ecmascript/base/config.h +++ b/ecmascript/base/config.h @@ -23,11 +23,14 @@ namespace panda::ecmascript { #define ECMASCRIPT_ENABLE_DEBUG_MODE 0 #define ECMASCRIPT_ENABLE_ARK_CONTAINER 1 #define ECMASCRIPT_ENABLE_ASM_INTERPRETER_LOG 0 +#define ECMASCRIPT_ENABLE_VERBOSE_LEVEL_LOG 0 +#define ECMASCRIPT_ENABLE_INTERPRETER_LOG 0 #define ECMASCRIPT_ENABLE_RUNTIME_STAT 0 // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ECMASCRIPT_ENABLE_INTERPRETER_RUNTIME_STAT 0 #define ECMASCRIPT_ENABLE_BUILTINS_RUNTIME_STAT 0 #define ECMASCRIPT_ENABLE_ALLOCATE_AND_GC_RUNTIME_STAT 0 +#define ECMASCRIPT_ENABLE_SNAPSHOT 0 /* * 1. close ic @@ -47,6 +50,7 @@ namespace panda::ecmascript { #define ECMASCRIPT_SWITCH_GC_MODE_TO_FULL_GC 1 #define ECMASCRIPT_ENABLE_CAST_CHECK 1 #define ECMASCRIPT_ENABLE_NEW_HANDLE_CHECK 1 + #define ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK 1 #define ECMASCRIPT_ENABLE_HEAP_VERIFY 1 #define ECMASCRIPT_ENABLE_THREAD_CHECK 1 #define ECMASCRIPT_ENABLE_ACTIVE_CPUPROFILER 0 @@ -58,6 +62,7 @@ namespace panda::ecmascript { #define ECMASCRIPT_SWITCH_GC_MODE_TO_FULL_GC 0 #define ECMASCRIPT_ENABLE_CAST_CHECK 0 #define ECMASCRIPT_ENABLE_NEW_HANDLE_CHECK 0 + #define ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK 0 #define ECMASCRIPT_ENABLE_HEAP_VERIFY 0 #define ECMASCRIPT_ENABLE_THREAD_CHECK 1 #define ECMASCRIPT_ENABLE_ACTIVE_CPUPROFILER 0 diff --git a/ecmascript/base/error_helper.cpp b/ecmascript/base/error_helper.cpp index 6e0faefa489f900282e4d3738eee7f60f991982d..307f5f4c1568ac4799cec044c7fd4f990ec1041d 100644 --- a/ecmascript/base/error_helper.cpp +++ b/ecmascript/base/error_helper.cpp @@ -107,6 +107,9 @@ JSHandle ErrorHelper::GetErrorName(JSThread *thread, const JSHand case ErrorType::TYPE_ERROR: errorKey = reinterpret_cast(*globalConst->GetHandledTypeErrorString()); break; + case ErrorType::AGGREGATE_ERROR: + errorKey = reinterpret_cast(*globalConst->GetHandledAggregateErrorString()); + break; case ErrorType::URI_ERROR: errorKey = reinterpret_cast(*globalConst->GetHandledURIErrorString()); break; @@ -154,7 +157,7 @@ JSTaggedValue ErrorHelper::ErrorCommonConstructor(EcmaRuntimeCallInfo *argv, auto globalConst = thread->GlobalConstants(); if (!message->IsUndefined()) { JSHandle handleStr = JSTaggedValue::ToString(thread, message); - LOG(DEBUG, ECMASCRIPT) << "Ark throw error: " << utf::Mutf8AsCString(handleStr->GetDataUtf8()); + LOG_ECMA(DEBUG) << "Throw error: " << utf::Mutf8AsCString(handleStr->GetDataUtf8()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle msgKey = globalConst->GetHandledMessageString(); PropertyDescriptor msgDesc(thread, JSHandle::Cast(handleStr), true, false, true); @@ -184,7 +187,7 @@ JSHandle ErrorHelper::BuildEcmaStackTrace(JSThread *thread) { std::string data = BuildJsStackTrace(thread, false); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - LOG(DEBUG, ECMASCRIPT) << data; + LOG_ECMA(DEBUG) << data; return factory->NewFromStdString(data); } @@ -220,12 +223,12 @@ std::string ErrorHelper::BuildJsStackTrace(JSThread *thread, bool needNative) int lineNumber = 0; auto callbackLineFunc = [&data, &lineNumber](int32_t line) -> bool { lineNumber = line + 1; - data += ToCString(lineNumber); + data += std::to_string(lineNumber); data.push_back(':'); return true; }; auto callbackColumnFunc = [&data](int32_t column) -> bool { - data += ToCString(column + 1); + data += std::to_string(column + 1); return true; }; panda_file::File::EntityId methodId = method->GetMethodId(); diff --git a/ecmascript/base/error_type.h b/ecmascript/base/error_type.h index 42a5dcd1528cf486a363d0a1c557d3ab05d46c65..868f1ad1c90b1c26728200a711726438cc6a74fd 100644 --- a/ecmascript/base/error_type.h +++ b/ecmascript/base/error_type.h @@ -27,6 +27,7 @@ enum class ErrorType : uint8_t { SYNTAX_ERROR, TYPE_ERROR, URI_ERROR, + AGGREGATE_ERROR, }; } // namespace panda::ecmascript::base diff --git a/ecmascript/base/json_parser.cpp b/ecmascript/base/json_parser.cpp index 95defa65a4ad20c814151daac9c7e0fe76325b28..3abb46ba6aa376e4b5caf1b98e69a8623a2a3e85 100644 --- a/ecmascript/base/json_parser.cpp +++ b/ecmascript/base/json_parser.cpp @@ -55,11 +55,12 @@ JSHandle Internalize::InternalizeJsonProperty(JSThread *thread, c } // Return ? Call(receiver, holder, « name, val »). - const size_t argsLength = 2; // 2: « name, val » + const int32_t argsLength = 2; // 2: « name, val » JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, receiver, objHandle, undefined, argsLength); - info.SetCallArg(name.GetTaggedValue(), val.GetTaggedValue()); - JSTaggedValue result = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, receiver, objHandle, undefined, argsLength); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + info->SetCallArg(name.GetTaggedValue(), val.GetTaggedValue()); + JSTaggedValue result = JSFunction::Call(info); return JSHandle(thread, result); } diff --git a/ecmascript/base/json_stringifier.cpp b/ecmascript/base/json_stringifier.cpp index 5e64e9bc65bfeb2d6a1f17a628b9d40b409965ee..02a2a6b1b8a1dedaed3127b03c877669bc550341 100644 --- a/ecmascript/base/json_stringifier.cpp +++ b/ecmascript/base/json_stringifier.cpp @@ -298,9 +298,10 @@ JSTaggedValue JsonStringifier::GetSerializeValue(const JSHandle & // c. If IsCallable(toJSON) is true if (UNLIKELY(toJsonFun->IsCallable())) { // Let value be Call(toJSON, value, «key»). - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread_, toJsonFun, value, undefined, 1); - info.SetCallArg(key.GetTaggedValue()); - tagValue = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, toJsonFun, value, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); + info->SetCallArg(key.GetTaggedValue()); + tagValue = JSFunction::Call(info); // ii. ReturnIfAbrupt(value). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } @@ -309,11 +310,12 @@ JSTaggedValue JsonStringifier::GetSerializeValue(const JSHandle & if (UNLIKELY(replacer->IsCallable())) { handleValue_.Update(tagValue); // a. Let value be Call(ReplacerFunction, holder, «key, value»). - const size_t argsLength = 2; // 2: «key, value» - EcmaRuntimeCallInfo info = + const int32_t argsLength = 2; // 2: «key, value» + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, replacer, object, undefined, argsLength); - info.SetCallArg(key.GetTaggedValue(), handleValue_.GetTaggedValue()); - tagValue = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); + info->SetCallArg(key.GetTaggedValue(), handleValue_.GetTaggedValue()); + tagValue = JSFunction::Call(info); // b. ReturnIfAbrupt(value). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread_); } @@ -374,6 +376,10 @@ JSTaggedValue JsonStringifier::SerializeJSONProperty(const JSHandle(valHandle))); + return tagValue; + } default: { if (!tagValue.IsCallable()) { JSHClass *jsHclass = tagValue.GetTaggedObject()->GetClass(); diff --git a/ecmascript/base/number_helper.cpp b/ecmascript/base/number_helper.cpp index caead58f0facbc084ae4c9ac91909ddbca90cdd9..bd23527d8d4262a5a23ddc5f63804f01b916207e 100644 --- a/ecmascript/base/number_helper.cpp +++ b/ecmascript/base/number_helper.cpp @@ -219,7 +219,7 @@ JSTaggedValue NumberHelper::StringToDoubleWithRadix(const uint8_t *start, const for (; p != end; ++p) { // The maximum value to ensure that uint32_t will not overflow const uint32_t MAX_MULTIPER = 0xffffffffU / 36; - uint32_t m = multiplier * radix; + uint32_t m = multiplier * static_cast(radix); if (m > MAX_MULTIPER) { break; } @@ -633,7 +633,7 @@ int32_t NumberHelper::DoubleToInt(double d, size_t bits) // Still has significand bits after mod 2^ // Get low bits by shift left <64 - bits> and shift right <64 - bits> uint64_t value = (((u64 & DOUBLE_SIGNIFICAND_MASK) | DOUBLE_HIDDEN_BIT) - << (exp - DOUBLE_SIGNIFICAND_SIZE + INT64_BITS - bits)) >> + << (static_cast(exp) - DOUBLE_SIGNIFICAND_SIZE + INT64_BITS - bits)) >> (INT64_BITS - bits); ret = static_cast(value); if ((u64 & DOUBLE_SIGN_MASK) == DOUBLE_SIGN_MASK && ret != INT32_MIN) { @@ -749,14 +749,14 @@ void NumberHelper::GetBase(double d, int digits, int *decpt, char *buf, char *bu { int result = snprintf_s(bufTmp, size, size - 1, "%+.*e", digits - 1, d); if (result == -1) { - LOG_ECMA(FATAL) << "snprintf_s failed"; + LOG_FULL(FATAL) << "snprintf_s failed"; UNREACHABLE(); } // mantissa buf[0] = bufTmp[1]; if (digits > 1) { if (memcpy_s(buf + 1, digits, bufTmp + 2, digits) != EOK) { // 2 means add the point char to buf - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } diff --git a/ecmascript/base/string_helper.h b/ecmascript/base/string_helper.h index b12404b061d31e5d360e7dfc78ceba439bb41c79..e355855d586344625300f0709fd40c1a366538b6 100644 --- a/ecmascript/base/string_helper.h +++ b/ecmascript/base/string_helper.h @@ -30,7 +30,6 @@ #include "ecmascript/js_thread.h" #include "ecmascript/mem/assert_scope.h" #include "ecmascript/object_factory.h" -#include "libpandafile/file_items.h" #include "unicode/unistr.h" namespace panda::ecmascript::base { @@ -40,9 +39,18 @@ static constexpr uint16_t SPACE_OR_LINE_TERMINAL[] = { 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x0020, 0x00A0, 0x1680, 0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, 0x2006, 0x2007, 0x2008, 0x2009, 0x200A, 0x2028, 0x2029, 0x202F, 0x205F, 0x3000, 0xFEFF, }; - +static constexpr int UICODE_FROM_UTF8[] = { + 0x80, 0xc0, 0xdf, 0xe0, 0xef, 0xf0, 0xf7, 0xf8, 0xfb, 0xfc, 0xfd, +}; +static constexpr int UTF8_MIN_CODE[] = { + 0x80, 0x800, 0x10000, 0x00200000, 0x04000000, +}; +static constexpr char UTF8_FIRST_CODE[] = { + 0x1f, 0xf, 0x7, 0x3, 0x1, +}; class StringHelper { public: + static constexpr int INVALID_UNICODE_FROM_UTF8 = -1; static std::string ToStdString(EcmaString *string); static bool CheckDuplicate(EcmaString *string); @@ -176,7 +184,51 @@ public: static EcmaString *Repeat(JSThread *thread, const std::u16string &thisStr, int32_t repeatLen, bool canBeCompress); - static EcmaString *Trim(JSThread *thread, const std::u16string &thisStr); + static int UnicodeFromUtf8(const uint8_t *p, int maxLen, const uint8_t **pp) + { + int c = *p++; + if (c < UICODE_FROM_UTF8[0]) { + *pp = p; + return c; + } + int l = 0; + if (c >= UICODE_FROM_UTF8[1] && c <= UICODE_FROM_UTF8[2]) { // 1 - 2: 0000 0080 - 0000 07FF + l = 1; // 1: 0000 0080 - 0000 07FF Unicode + } else if (c >= UICODE_FROM_UTF8[3] && c <= UICODE_FROM_UTF8[4]) { // 3 - 4: 0000 0800 - 0000 FFFF + l = 2; // 2: 0000 0800 - 0000 FFFF Unicode + } else if (c >= UICODE_FROM_UTF8[5] && c <= UICODE_FROM_UTF8[6]) { // 5 - 6: 0001 0000 - 0010 FFFF + l = 3; // 3: 0001 0000 - 0010 FFFF Unicode + } else if (c >= UICODE_FROM_UTF8[7] && c <= UICODE_FROM_UTF8[8]) { // 7 - 8: 0020 0000 - 03FF FFFF + l = 4; // 4: 0020 0000 - 03FF FFFF Unicode + } else if (c == UICODE_FROM_UTF8[9] || c == UICODE_FROM_UTF8[10]) { // 9 - 10: 0400 0000 - 7FFF FFFF + l = 5; // 5: 0400 0000 - 7FFF FFFF Unicode + } else { + return INVALID_UNICODE_FROM_UTF8; + } + /* check that we have enough characters */ + if (l > (maxLen - 1)) { + return INVALID_UNICODE_FROM_UTF8; + } + return FromUtf8(c, l, p, pp); + } + + static int FromUtf8(int c, int l, const uint8_t *p, const uint8_t **pp) + { + uint32_t b; + c &= UTF8_FIRST_CODE[l - 1]; + for (int i = 0; i < l; i++) { + b = *p++; + if (b < utf_helper::UTF8_2B_SECOND || b >= utf_helper::UTF8_2B_FIRST) { + return INVALID_UNICODE_FROM_UTF8; + } + c = (c << 6) | (b & utf_helper::UTF8_2B_THIRD); // 6: Maximum Unicode range + } + if (c < UTF8_MIN_CODE[l - 1]) { + return INVALID_UNICODE_FROM_UTF8; + } + *pp = p; + return c; + } static inline std::u16string Append(const std::u16string &str1, const std::u16string &str2) { @@ -203,18 +255,22 @@ public: static inline std::string GetSpecifiedLine(const std::string &srcStr, int lineNumber) { - std::stringstream ss(srcStr); - int count = 0; - std::string lineStr = ""; - std::string tempLine; - while (getline(ss, tempLine, '\n')) { - count++; - if (count == lineNumber) { - lineStr = tempLine; - break; + ASSERT(lineNumber >= 1); + int prePos = 0; + int findPrePos = lineNumber - 1; + for (int i = 0; i < findPrePos; i++) { + prePos = srcStr.find('\n', prePos); + if (prePos == -1) { + return ""; } + prePos += 1; + } + int findEndPos = srcStr.find('\n', prePos); + if (findEndPos == -1) { + return srcStr.substr(prePos, srcStr.length() - prePos); } - return lineStr; + ASSERT(findEndPos > prePos); + return srcStr.substr(prePos, findEndPos - prePos); } static inline bool IsNonspace(uint16_t c) diff --git a/ecmascript/base/tests/builtins_base_test.cpp b/ecmascript/base/tests/builtins_base_test.cpp index d9c678c5adb8c7033a65bfe2be3f40e38aa9bbbc..3725c52fb0a1017d9e2d2f98d2620ca2a2293849 100644 --- a/ecmascript/base/tests/builtins_base_test.cpp +++ b/ecmascript/base/tests/builtins_base_test.cpp @@ -59,14 +59,14 @@ public: */ HWTEST_F_L0(BuiltinsBaseTest, GetArgsArray) { - array_size_t argvLength = 10; + uint32_t argvLength = 10; auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), argvLength); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(2)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSHandle resultArray = BuiltinsBase::GetArgsArray(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSHandle resultArray = BuiltinsBase::GetArgsArray(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(resultArray->GetLength(), 3U); @@ -95,24 +95,24 @@ HWTEST_F_L0(BuiltinsBaseTest, BuiltinsBase_info_Get) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(ArgsPosition::FIRST)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(ArgsPosition::SECOND)); ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(ArgsPosition::FOURTH)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); - EXPECT_TRUE(BuiltinsBase::GetConstructor(ecmaRuntimeCallInfo1.get())->IsUndefined()); - EXPECT_TRUE(BuiltinsBase::GetNewTarget(ecmaRuntimeCallInfo1.get())->IsUndefined()); - EXPECT_EQ(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo1.get(), 0)->GetInt(), 0); - EXPECT_EQ(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo1.get(), 1)->GetInt(), 1); - EXPECT_EQ(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo1.get(), 2)->GetInt(), 3); + EXPECT_TRUE(BuiltinsBase::GetConstructor(ecmaRuntimeCallInfo1)->IsUndefined()); + EXPECT_TRUE(BuiltinsBase::GetNewTarget(ecmaRuntimeCallInfo1)->IsUndefined()); + EXPECT_EQ(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo1, 0)->GetInt(), 0); + EXPECT_EQ(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo1, 1)->GetInt(), 1); + EXPECT_EQ(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo1, 2)->GetInt(), 3); TestHelper::TearDownFrame(thread, prev1); auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*handleNewTarget), 6); ecmaRuntimeCallInfo2->SetFunction(handleFunction.GetTaggedValue()); ecmaRuntimeCallInfo2->SetThis(handleNewTarget.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); - EXPECT_TRUE(BuiltinsBase::GetConstructor(ecmaRuntimeCallInfo2.get())->IsJSFunction()); - EXPECT_TRUE(BuiltinsBase::GetNewTarget(ecmaRuntimeCallInfo2.get())->IsJSGlobalObject()); - EXPECT_TRUE(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo2.get(), 0)->IsUndefined()); + EXPECT_TRUE(BuiltinsBase::GetConstructor(ecmaRuntimeCallInfo2)->IsJSFunction()); + EXPECT_TRUE(BuiltinsBase::GetNewTarget(ecmaRuntimeCallInfo2)->IsJSGlobalObject()); + EXPECT_TRUE(BuiltinsBase::GetCallArg(ecmaRuntimeCallInfo2, 0)->IsUndefined()); TestHelper::TearDownFrame(thread, prev2); } diff --git a/ecmascript/base/typed_array_helper.cpp b/ecmascript/base/typed_array_helper.cpp index 1745b80509337d68c83cce8343580f0d5703f372..7d271a38597bbfc1e65e1fb844b93bf6083e9592 100644 --- a/ecmascript/base/typed_array_helper.cpp +++ b/ecmascript/base/typed_array_helper.cpp @@ -474,9 +474,10 @@ JSHandle TypedArrayHelper::TypedArrayCreate(JSThread *thread, const JS { // 1. Let newTypedArray be ? Construct(constructor, argumentList). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, argc); - info.SetCallArg(argc, argv); - JSTaggedValue taggedArray = JSFunction::Construct(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, argc); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); + info->SetCallArg(argc, argv); + JSTaggedValue taggedArray = JSFunction::Construct(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSHandle(thread, JSTaggedValue::Exception())); if (!taggedArray.IsECMAObject()) { THROW_TYPE_ERROR_AND_RETURN(thread, "Failed to construct the Typedarray.", @@ -491,7 +492,7 @@ JSHandle TypedArrayHelper::TypedArrayCreate(JSThread *thread, const JS // a. If newTypedArray.[[ArrayLength]] < argumentList[0], throw a TypeError exception. if (argc == 1) { if (JSHandle::Cast(newTypedArray)->GetArrayLength() < - JSTaggedValue::ToUint32(thread, info.GetCallArg(0))) { + JSTaggedValue::ToUint32(thread, info->GetCallArg(0))) { THROW_TYPE_ERROR_AND_RETURN(thread, "the length of newTypedArray is not a correct value.", JSHandle(thread, JSTaggedValue::Exception())); } @@ -533,12 +534,13 @@ int32_t TypedArrayHelper::SortCompare(JSThread *thread, const JSHandleIsUndefined()) { - const size_t argsLength = 2; + const int32_t argsLength = 2; JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackfnHandle, undefined, undefined, argsLength); - info.SetCallArg(firstValue.GetTaggedValue(), secondValue.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); + info->SetCallArg(firstValue.GetTaggedValue(), secondValue.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, 0); if (BuiltinsArrayBuffer::IsDetachedBuffer(buffer.GetTaggedValue())) { THROW_TYPE_ERROR_AND_RETURN(thread, "The buffer is detached buffer.", 0); diff --git a/ecmascript/base/utf_helper.h b/ecmascript/base/utf_helper.h index 64df9d09cee292cdcc0a46a74cff76c875b9f2f0..858405d4bccbc114ff486035026cd1f6369cc743 100644 --- a/ecmascript/base/utf_helper.h +++ b/ecmascript/base/utf_helper.h @@ -40,6 +40,7 @@ static constexpr uint8_t UTF8_1B_MAX = 0x7f; static constexpr uint16_t UTF8_2B_MAX = 0x7ff; static constexpr uint8_t UTF8_2B_FIRST = 0xc0; static constexpr uint8_t UTF8_2B_SECOND = 0x80; +static constexpr uint8_t UTF8_2B_THIRD = 0x3f; static constexpr uint8_t UTF8_3B_FIRST = 0xe0; static constexpr uint8_t UTF8_3B_SECOND = 0x80; diff --git a/ecmascript/builtins.cpp b/ecmascript/builtins.cpp index 38242dcb997aeaf6c2155b0aab0bb0d0bb82670d..37eca9aeffdee5331972289faf93a23c68c2ad92 100644 --- a/ecmascript/builtins.cpp +++ b/ecmascript/builtins.cpp @@ -16,7 +16,6 @@ #include "ecmascript/builtins.h" #ifdef PANDA_TARGET_WINDOWS -#include "shlwapi.h" #ifdef ERROR #undef ERROR #endif @@ -33,9 +32,9 @@ #include "ecmascript/builtins/builtins_atomics.h" #include "ecmascript/builtins/builtins_bigint.h" #include "ecmascript/builtins/builtins_boolean.h" -#include "ecmascript/builtins/builtin_cjs_module.h" -#include "ecmascript/builtins/builtin_cjs_require.h" -#include "ecmascript/builtins/builtin_cjs_exports.h" +#include "ecmascript/builtins/builtins_cjs_module.h" +#include "ecmascript/builtins/builtins_cjs_require.h" +#include "ecmascript/builtins/builtins_cjs_exports.h" #include "ecmascript/builtins/builtins_collator.h" #include "ecmascript/builtins/builtins_dataview.h" #include "ecmascript/builtins/builtins_date.h" @@ -75,6 +74,7 @@ #include "ecmascript/builtins/builtins_weak_set.h" #include "ecmascript/containers/containers_private.h" #include "ecmascript/ecma_runtime_call_info.h" +#include "ecmascript/file_loader.h" #include "ecmascript/js_array.h" #include "ecmascript/js_arraybuffer.h" #include "ecmascript/js_array_iterator.h" @@ -138,6 +138,7 @@ using Error = builtins::BuiltinsError; using RangeError = builtins::BuiltinsRangeError; using ReferenceError = builtins::BuiltinsReferenceError; using TypeError = builtins::BuiltinsTypeError; +using AggregateError = builtins::BuiltinsAggregateError; using URIError = builtins::BuiltinsURIError; using SyntaxError = builtins::BuiltinsSyntaxError; using EvalError = builtins::BuiltinsEvalError; @@ -169,40 +170,13 @@ using Collator = builtins::BuiltinsCollator; using PluralRules = builtins::BuiltinsPluralRules; using DisplayNames = builtins::BuiltinsDisplayNames; using ListFormat = builtins::BuiltinsListFormat; -using CjsModule = builtins::BuiltinsCjsModule; -using CjsExports = builtins::BuiltinsCjsExports; -using CjsRequire = builtins::BuiltinsCjsRequire; +using BuiltinsCjsModule = builtins::BuiltinsCjsModule; +using BuiltinsCjsExports = builtins::BuiltinsCjsExports; +using BuiltinsCjsRequire = builtins::BuiltinsCjsRequire; using ContainersPrivate = containers::ContainersPrivate; using SharedArrayBuffer = builtins::BuiltinsSharedArrayBuffer; -bool GetAbsolutePath(const std::string &relativePath, std::string &absPath) -{ - if (relativePath.size() >= PATH_MAX) { - return false; - } - char buffer[PATH_MAX] = {0}; -#ifndef PANDA_TARGET_WINDOWS - auto path = realpath(relativePath.c_str(), buffer); - if (path == nullptr) { - return false; - } - absPath = std::string(path); - return true; -#else - auto path = _fullpath(buffer, relativePath.c_str(), sizeof(buffer) - 1); - if (path == nullptr) { - return false; - } - bool valid = PathCanonicalizeA(buffer, path); - if (!valid) { - return false; - } - absPath = std::string(buffer); - return true; -#endif -} - void Builtins::Initialize(const JSHandle &env, JSThread *thread) { thread_ = thread; @@ -253,25 +227,6 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION, env->GetFunctionPrototype()); env->SetAsyncAwaitStatusFunctionClass(thread_, asyncAwaitStatusFuncClass); - JSHandle promiseReactionFuncClass = factory_->NewEcmaDynClass( - JSPromiseReactionsFunction::SIZE, JSType::JS_PROMISE_REACTIONS_FUNCTION, env->GetFunctionPrototype()); - promiseReactionFuncClass->SetCallable(true); - promiseReactionFuncClass->SetExtensible(true); - env->SetPromiseReactionFunctionClass(thread_, promiseReactionFuncClass); - - JSHandle promiseExecutorFuncClass = factory_->NewEcmaDynClass( - JSPromiseExecutorFunction::SIZE, JSType::JS_PROMISE_EXECUTOR_FUNCTION, env->GetFunctionPrototype()); - promiseExecutorFuncClass->SetCallable(true); - promiseExecutorFuncClass->SetExtensible(true); - env->SetPromiseExecutorFunctionClass(thread_, promiseExecutorFuncClass); - - JSHandle promiseAllResolveElementFunctionClass = - factory_->NewEcmaDynClass(JSPromiseAllResolveElementFunction::SIZE, - JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION, env->GetFunctionPrototype()); - promiseAllResolveElementFunctionClass->SetCallable(true); - promiseAllResolveElementFunctionClass->SetExtensible(true); - env->SetPromiseAllResolveElementFunctionClass(thread_, promiseAllResolveElementFunctionClass); - JSHandle proxyRevocFuncClass = factory_->NewEcmaDynClass( JSProxyRevocFunction::SIZE, JSType::JS_PROXY_REVOC_FUNCTION, env->GetFunctionPrototype()); proxyRevocFuncClass->SetCallable(true); @@ -281,7 +236,6 @@ void Builtins::Initialize(const JSHandle &env, JSThread *thread) // Object = new Function() JSHandle objectFunction( NewBuiltinConstructor(env, objFuncPrototype, Object::ObjectConstructor, "Object", FunctionLength::ONE)); - objectFunction.GetObject()->SetBuiltinsCtorMode(); objectFunction.GetObject()->SetFunctionPrototype(thread_, objFuncDynclass.GetTaggedValue()); // initialize object method. env->SetObjectFunction(thread_, objectFunction); @@ -372,8 +326,7 @@ void Builtins::InitializeForSnapshot(JSThread *thread) InitializeIcuData(); // Initialize ArkTools - JSRuntimeOptions options = vm_->GetJSOptions(); - if (options.EnableArkTools()) { + if (vm_->GetJSOptions().EnableArkTools()) { auto env = vm_->GetGlobalEnv(); auto globalObject = JSHandle::Cast(env->GetJSGlobalObject()); JSHandle arkTools(InitializeArkTools(env)); @@ -392,8 +345,7 @@ void Builtins::InitializeGlobalObject(const JSHandle &env, const JSHa SetFunction(env, globalObject, "stopRuntimeStat", Global::StopRuntimeStat, 0); #endif - JSRuntimeOptions options = vm_->GetJSOptions(); - if (options.EnableArkTools()) { + if (vm_->GetJSOptions().EnableArkTools()) { JSHandle arkTools(InitializeArkTools(env)); SetConstantObject(globalObject, "ArkTools", arkTools); } @@ -439,8 +391,6 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle JSHandle funcFuncIntanceDynclass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, funcFuncPrototypeValue); funcFuncIntanceDynclass->SetConstructor(true); - JSHandle function = JSHandle::Cast(factory_->NewJSObjectWithInit(funcFuncIntanceDynclass)); - function->SetBuiltinsCtorMode(); // Function = new Function() (forbidden use NewBuiltinConstructor) JSHandle funcFunc = @@ -466,9 +416,6 @@ void Builtins::InitializeFunction(const JSHandle &env, const JSHandle JSHandle constructorFunctionClass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetFunctionPrototype()); constructorFunctionClass->SetConstructor(true); - JSHandle functionConstructor = - JSHandle::Cast(factory_->NewJSObjectWithInit(constructorFunctionClass)); - functionConstructor->SetBuiltinsCtorMode(); env->SetConstructorFunctionClass(thread_, constructorFunctionClass); StrictModeForbiddenAccessCallerArguments(env, funcFuncPrototypeObj); @@ -518,6 +465,8 @@ void Builtins::InitializeObject(const JSHandle &env, const JSHandle &env, const JSHandle &env, const JSHandle &objFuncDynclass) const { [[maybe_unused]] EcmaHandleScope scope(thread_); - const int utcLength = 7; + constexpr int utcLength = 7; // Date.prototype JSHandle dateFuncPrototype = factory_->NewJSObjectWithInit(objFuncDynclass); JSHandle dateFuncPrototypeValue(dateFuncPrototype); @@ -1015,8 +964,6 @@ void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHa JSHandle nativeErrorFuncClass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetErrorFunction()); nativeErrorFuncClass->SetConstructor(true); - JSHandle function = JSHandle::Cast(factory_->NewJSObjectWithInit(nativeErrorFuncClass)); - function->SetBuiltinsCtorMode(); env->SetNativeErrorFunctionClass(thread_, nativeErrorFuncClass); JSHandle errorNativeFuncInstanceDynclass = @@ -1024,6 +971,7 @@ void Builtins::InitializeAllTypeError(const JSHandle &env, const JSHa InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_RANGE_ERROR); InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_REFERENCE_ERROR); InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_TYPE_ERROR); + InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_AGGREGATE_ERROR); InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_URI_ERROR); InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_SYNTAX_ERROR); InitializeError(env, errorNativeFuncInstanceDynclass, JSType::JS_EVAL_ERROR); @@ -1039,6 +987,7 @@ void Builtins::InitializeAllTypeErrorWithRealm(const JSHandle &realm) SetErrorWithRealm(realm, JSType::JS_RANGE_ERROR); SetErrorWithRealm(realm, JSType::JS_REFERENCE_ERROR); SetErrorWithRealm(realm, JSType::JS_TYPE_ERROR); + SetErrorWithRealm(realm, JSType::JS_AGGREGATE_ERROR); SetErrorWithRealm(realm, JSType::JS_URI_ERROR); SetErrorWithRealm(realm, JSType::JS_SYNTAX_ERROR); SetErrorWithRealm(realm, JSType::JS_EVAL_ERROR); @@ -1072,6 +1021,11 @@ void Builtins::SetErrorWithRealm(const JSHandle &realm, const JSType realm->SetTypeErrorFunction(thread_, nativeErrorFunction); realm->SetThrowTypeError(thread_, env->GetThrowTypeError()); break; + case JSType::JS_AGGREGATE_ERROR: + nativeErrorFunction = env->GetAggregateErrorFunction(); + nameString = JSHandle(thread_->GlobalConstants()->GetHandledAggregateErrorString()); + realm->SetAggregateErrorFunction(thread_, nativeErrorFunction); + break; case JSType::JS_URI_ERROR: nativeErrorFunction = env->GetURIErrorFunction(); nameString = JSHandle(thread_->GlobalConstants()->GetHandledURIErrorString()); @@ -1124,6 +1078,10 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandle &env, const JSHandleNewEcmaDynClass(JSObject::SIZE, errorParameter.nativeJstype, nativeErrorFuncPrototypeValue); // NativeError() = new Error() + FunctionLength functionLength = FunctionLength::ONE; + if (errorTag == JSType::JS_AGGREGATE_ERROR) { + functionLength = FunctionLength::TWO; + } JSHandle nativeErrorFunction = factory_->NewJSNativeErrorFunction(env, reinterpret_cast(errorParameter.nativeConstructor)); InitializeCtor(env, nativeErrorFuncPrototype, nativeErrorFunction, errorParameter.nativePropertyName, - FunctionLength::ONE); + functionLength); nativeErrorFunction->SetFunctionPrototype(thread_, nativeErrorFuncInstanceDynclass.GetTaggedValue()); @@ -1167,6 +1129,8 @@ void Builtins::InitializeError(const JSHandle &env, const JSHandle::Cast(throwTypeErrorFunction)); env->SetThrowTypeError(thread_, throwTypeErrorFunction); + } else if (errorTag == JSType::JS_AGGREGATE_ERROR) { + env->SetAggregateErrorFunction(thread_, nativeErrorFunction); } else if (errorTag == JSType::JS_URI_ERROR) { env->SetURIErrorFunction(thread_, nativeErrorFunction); } else if (errorTag == JSType::JS_SYNTAX_ERROR) { @@ -1592,6 +1556,7 @@ void Builtins::InitializeString(const JSHandle &env, const JSHandle &env, const JSHandle(arrayFunction), speciesSymbol, speciesGetter); - const int arrProtoLen = 0; + constexpr int arrProtoLen = 0; JSHandle key_string = thread_->GlobalConstants()->GetHandledLengthString(); PropertyDescriptor descriptor(thread_, JSHandle(thread_, JSTaggedValue(arrProtoLen)), true, false, false); @@ -2026,9 +1991,6 @@ void Builtins::InitializeTypedArray(const JSHandle &env, const JSHand JSHandle specificTypedArrayFuncClass = factory_->NewEcmaDynClass(JSFunction::SIZE, JSType::JS_FUNCTION, env->GetTypedArrayFunction()); specificTypedArrayFuncClass->SetConstructor(true); - JSHandle function = - JSHandle::Cast(factory_->NewJSObjectWithInit(specificTypedArrayFuncClass)); - function->SetBuiltinsCtorMode(); env->SetSpecificTypedArrayFunctionClass(thread_, specificTypedArrayFuncClass); InitializeInt8Array(env, typedArrFuncInstanceDynclass); @@ -2062,7 +2024,7 @@ void Builtins::InitializeInt8Array(const JSHandle &env, const JSHandl int8ArrayFunction->SetProtoOrDynClass(thread_, int8ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 1; + constexpr int bytesPerElement = 1; SetConstant(int8ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(int8ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetInt8ArrayFunction(thread_, int8ArrayFunction); @@ -2086,7 +2048,7 @@ void Builtins::InitializeUint8Array(const JSHandle &env, const JSHand uint8ArrayFunction->SetProtoOrDynClass(thread_, uint8ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 1; + constexpr int bytesPerElement = 1; SetConstant(uint8ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(uint8ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetUint8ArrayFunction(thread_, uint8ArrayFunction); @@ -2113,7 +2075,7 @@ void Builtins::InitializeUint8ClampedArray(const JSHandle &env, uint8ClampedArrayFunction->SetProtoOrDynClass(thread_, uint8ClampedArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 1; + constexpr int bytesPerElement = 1; SetConstant(uint8ClampedArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(uint8ClampedArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetUint8ClampedArrayFunction(thread_, uint8ClampedArrayFunction); @@ -2137,7 +2099,7 @@ void Builtins::InitializeInt16Array(const JSHandle &env, const JSHand int16ArrayFunction->SetProtoOrDynClass(thread_, int16ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 2; + constexpr int bytesPerElement = 2; SetConstant(int16ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(int16ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetInt16ArrayFunction(thread_, int16ArrayFunction); @@ -2161,7 +2123,7 @@ void Builtins::InitializeUint16Array(const JSHandle &env, const JSHan uint16ArrayFunction->SetProtoOrDynClass(thread_, uint16ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 2; + constexpr int bytesPerElement = 2; SetConstant(uint16ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(uint16ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetUint16ArrayFunction(thread_, uint16ArrayFunction); @@ -2185,7 +2147,7 @@ void Builtins::InitializeInt32Array(const JSHandle &env, const JSHand int32ArrayFunction->SetProtoOrDynClass(thread_, int32ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 4; + constexpr int bytesPerElement = 4; SetConstant(int32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(int32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetInt32ArrayFunction(thread_, int32ArrayFunction); @@ -2209,7 +2171,7 @@ void Builtins::InitializeUint32Array(const JSHandle &env, const JSHan uint32ArrayFunction->SetProtoOrDynClass(thread_, uint32ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 4; + constexpr int bytesPerElement = 4; SetConstant(uint32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(uint32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetUint32ArrayFunction(thread_, uint32ArrayFunction); @@ -2233,7 +2195,7 @@ void Builtins::InitializeFloat32Array(const JSHandle &env, const JSHa float32ArrayFunction->SetProtoOrDynClass(thread_, float32ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 4; + constexpr int bytesPerElement = 4; SetConstant(float32ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(float32ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetFloat32ArrayFunction(thread_, float32ArrayFunction); @@ -2257,7 +2219,7 @@ void Builtins::InitializeFloat64Array(const JSHandle &env, const JSHa float64ArrayFunction->SetProtoOrDynClass(thread_, float64ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 8; + constexpr int bytesPerElement = 8; SetConstant(float64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(float64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetFloat64ArrayFunction(thread_, float64ArrayFunction); @@ -2281,7 +2243,7 @@ void Builtins::InitializeBigInt64Array(const JSHandle &env, const JSH bigInt64ArrayFunction->SetProtoOrDynClass(thread_, bigInt64ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 8; + constexpr int bytesPerElement = 8; SetConstant(bigInt64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(bigInt64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetBigInt64ArrayFunction(thread_, bigInt64ArrayFunction); @@ -2305,7 +2267,7 @@ void Builtins::InitializeBigUint64Array(const JSHandle &env, const JS bigUint64ArrayFunction->SetProtoOrDynClass(thread_, bigUint64ArrFuncInstanceDynclass.GetTaggedValue()); - const int bytesPerElement = 8; + constexpr int bytesPerElement = 8; SetConstant(bigUint64ArrFuncPrototype, "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); SetConstant(JSHandle(bigUint64ArrayFunction), "BYTES_PER_ELEMENT", JSTaggedValue(bytesPerElement)); env->SetBigUint64ArrayFunction(thread_, bigUint64ArrayFunction); @@ -2451,10 +2413,13 @@ void Builtins::InitializePromise(const JSHandle &env, const JSHandle< SetFunction(env, promiseFunction, "race", Promise::Race, FunctionLength::ONE); SetFunction(env, promiseFunction, "resolve", Promise::Resolve, FunctionLength::ONE); SetFunction(env, promiseFunction, "reject", Promise::Reject, FunctionLength::ONE); + SetFunction(env, promiseFunction, "any", Promise::Any, FunctionLength::ONE); + SetFunction(env, promiseFunction, "allSettled", Promise::AllSettled, FunctionLength::ONE); // promise.prototype method SetFunction(env, promiseFuncPrototype, "catch", Promise::Catch, FunctionLength::ONE); SetFunction(env, promiseFuncPrototype, "then", Promise::Then, FunctionLength::TWO); + SetFunction(env, promiseFuncPrototype, "finally", Promise::Finally, FunctionLength::ONE); // Promise.prototype [ @@toStringTag ] SetStringTagSymbol(env, promiseFuncPrototype, "Promise"); @@ -2466,6 +2431,61 @@ void Builtins::InitializePromise(const JSHandle &env, const JSHandle< SetGetter(promiseFunction, speciesSymbol, speciesGetter); env->SetPromiseFunction(thread_, promiseFunction); + InitializeForPromiseFuncClass(env); +} + + +void Builtins::InitializeForPromiseFuncClass(const JSHandle &env) +{ + vm_ = thread_->GetEcmaVM(); + factory_ = vm_->GetFactory(); + + JSHandle promiseReactionFuncClass = factory_->NewEcmaDynClass( + JSPromiseReactionsFunction::SIZE, JSType::JS_PROMISE_REACTIONS_FUNCTION, env->GetFunctionPrototype()); + promiseReactionFuncClass->SetCallable(true); + promiseReactionFuncClass->SetExtensible(true); + env->SetPromiseReactionFunctionClass(thread_, promiseReactionFuncClass); + + JSHandle promiseExecutorFuncClass = factory_->NewEcmaDynClass( + JSPromiseExecutorFunction::SIZE, JSType::JS_PROMISE_EXECUTOR_FUNCTION, env->GetFunctionPrototype()); + promiseExecutorFuncClass->SetCallable(true); + promiseExecutorFuncClass->SetExtensible(true); + env->SetPromiseExecutorFunctionClass(thread_, promiseExecutorFuncClass); + + JSHandle promiseAllResolveElementFunctionClass = + factory_->NewEcmaDynClass(JSPromiseAllResolveElementFunction::SIZE, + JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION, env->GetFunctionPrototype()); + promiseAllResolveElementFunctionClass->SetCallable(true); + promiseAllResolveElementFunctionClass->SetExtensible(true); + env->SetPromiseAllResolveElementFunctionClass(thread_, promiseAllResolveElementFunctionClass); + + JSHandle promiseAnyRejectElementFunctionClass = + factory_->NewEcmaDynClass(JSPromiseAnyRejectElementFunction::SIZE, + JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION, env->GetFunctionPrototype()); + promiseAnyRejectElementFunctionClass->SetCallable(true); + promiseAnyRejectElementFunctionClass->SetExtensible(true); + env->SetPromiseAnyRejectElementFunctionClass(thread_, promiseAnyRejectElementFunctionClass); + + JSHandle promiseAllSettledElementFunctionClass = + factory_->NewEcmaDynClass(JSPromiseAllSettledElementFunction::SIZE, + JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION, env->GetFunctionPrototype()); + promiseAllSettledElementFunctionClass->SetCallable(true); + promiseAllSettledElementFunctionClass->SetExtensible(true); + env->SetPromiseAllSettledElementFunctionClass(thread_, promiseAllSettledElementFunctionClass); + + JSHandle promiseFinallyFunctionClass = + factory_->NewEcmaDynClass(JSPromiseFinallyFunction::SIZE, + JSType::JS_PROMISE_FINALLY_FUNCTION, env->GetFunctionPrototype()); + promiseFinallyFunctionClass->SetCallable(true); + promiseFinallyFunctionClass->SetExtensible(true); + env->SetPromiseFinallyFunctionClass(thread_, promiseFinallyFunctionClass); + + JSHandle promiseValueThunkOrThrowerFunctionClass = + factory_->NewEcmaDynClass(JSPromiseValueThunkOrThrowerFunction::SIZE, + JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION, env->GetFunctionPrototype()); + promiseValueThunkOrThrowerFunctionClass->SetCallable(true); + promiseValueThunkOrThrowerFunctionClass->SetExtensible(true); + env->SetPromiseValueThunkOrThrowerFunctionClass(thread_, promiseValueThunkOrThrowerFunctionClass); } void Builtins::InitializePromiseJob(const JSHandle &env) @@ -3211,7 +3231,9 @@ JSHandle Builtins::InitializeArkTools(const JSHandle &env) JSHandle tools = factory_->NewEmptyJSObject(); SetFunction(env, tools, "print", builtins::BuiltinsArkTools::ObjectDump, FunctionLength::ZERO); SetFunction(env, tools, "compareHClass", builtins::BuiltinsArkTools::CompareHClass, FunctionLength::TWO); - SetFunction(env, tools, "DumpHClass", builtins::BuiltinsArkTools::DumpHClass, FunctionLength::ONE); + SetFunction(env, tools, "dumpHClass", builtins::BuiltinsArkTools::DumpHClass, FunctionLength::ONE); + SetFunction(env, tools, "isTSHClass", builtins::BuiltinsArkTools::IsTSHClass, FunctionLength::ONE); + SetFunction(env, tools, "getHClass", builtins::BuiltinsArkTools::GetHClass, FunctionLength::ONE); return tools; } @@ -3265,23 +3287,24 @@ void Builtins::InitializeCjsModule(const JSHandle &env) const // CjsModule.prototype_or_dynclass JSHandle cjsModuleDynclass = - factory_->NewEcmaDynClass(JSCjsModule::SIZE, JSType::JS_CJS_MODULE, cjsModulePrototypeValue); + factory_->NewEcmaDynClass(CjsModule::SIZE, JSType::JS_CJS_MODULE, cjsModulePrototypeValue); // CjsModule.prototype.Constructor JSHandle cjsModuleFunction( - NewBuiltinCjsCtor(env, cjsModulePrototype, CjsModule::CjsModuleConstructor, "Module", FunctionLength::TWO)); + NewBuiltinCjsCtor(env, cjsModulePrototype, BuiltinsCjsModule::CjsModuleConstructor, "Module", + FunctionLength::TWO)); JSHandle(cjsModuleFunction)->SetFunctionPrototype(thread_, cjsModuleDynclass.GetTaggedValue()); // CjsModule method - SetFunction(env, cjsModuleFunction, "_load", CjsModule::Load, FunctionLength::ONE); - SetFunction(env, cjsModuleFunction, "_resolveFilename", CjsModule::ResolveFilename, FunctionLength::ONE); + SetFunction(env, cjsModuleFunction, "_load", BuiltinsCjsModule::Load, FunctionLength::ONE); + SetFunction(env, cjsModuleFunction, "_resolveFilename", BuiltinsCjsModule::ResolveFilename, FunctionLength::ONE); // CjsModule.prototype method - SetFunction(env, cjsModulePrototype, "require", CjsModule::Require, FunctionLength::ONE); + SetFunction(env, cjsModulePrototype, "require", BuiltinsCjsModule::Require, FunctionLength::ONE); SetFunction(env, cjsModulePrototype, "getExportsForCircularRequire", - CjsModule::GetExportsForCircularRequire, FunctionLength::ONE); - SetFunction(env, cjsModulePrototype, "updateChildren", CjsModule::UpdateChildren, FunctionLength::ONE); + BuiltinsCjsModule::GetExportsForCircularRequire, FunctionLength::ONE); + SetFunction(env, cjsModulePrototype, "updateChildren", BuiltinsCjsModule::UpdateChildren, FunctionLength::ONE); JSHandle id(thread_->GlobalConstants()->GetHandledEmptyString()); JSHandle path(thread_->GlobalConstants()->GetHandledEmptyString()); @@ -3319,11 +3342,11 @@ void Builtins::InitializeCjsExports(const JSHandle &env) const // CjsExports.prototype_or_dynclass JSHandle cjsExportsDynclass = - factory_->NewEcmaDynClass(JSCjsExports::SIZE, JSType::JS_CJS_EXPORTS, cjsExportsPrototypeValue); + factory_->NewEcmaDynClass(CjsExports::SIZE, JSType::JS_CJS_EXPORTS, cjsExportsPrototypeValue); // CjsExports.prototype.Constructor JSHandle cjsExportsFunction( - NewBuiltinCjsCtor(env, cjsExportsPrototype, CjsExports::CjsExportsConstructor, "Exports", + NewBuiltinCjsCtor(env, cjsExportsPrototype, BuiltinsCjsExports::CjsExportsConstructor, "Exports", FunctionLength::TWO)); JSHandle(cjsExportsFunction)->SetFunctionPrototype(thread_, cjsExportsDynclass.GetTaggedValue()); @@ -3341,15 +3364,16 @@ void Builtins::InitializeCjsRequire(const JSHandle &env) const // CjsExports.prototype_or_dynclass JSHandle cjsRequireDynclass = - factory_->NewEcmaDynClass(JSCjsRequire::SIZE, JSType::JS_CJS_REQUIRE, cjsRequirePrototypeValue); + factory_->NewEcmaDynClass(CjsRequire::SIZE, JSType::JS_CJS_REQUIRE, cjsRequirePrototypeValue); // CjsExports.prototype.Constructor JSHandle cjsRequireFunction = - NewBuiltinCjsCtor(env, cjsRequirePrototype, CjsRequire::CjsRequireConstructor, "require", FunctionLength::ONE); + NewBuiltinCjsCtor(env, cjsRequirePrototype, BuiltinsCjsRequire::CjsRequireConstructor, "require", + FunctionLength::ONE); JSHandle(cjsRequireFunction)->SetFunctionPrototype(thread_, cjsRequireDynclass.GetTaggedValue()); // CjsModule.prototype method - SetFunction(env, cjsRequirePrototype, "Main", builtins::BuiltinsCjsRequire::Main, FunctionLength::ONE); + SetFunction(env, cjsRequirePrototype, "Main", BuiltinsCjsRequire::Main, FunctionLength::ONE); env->SetCjsRequireFunction(thread_, cjsRequireFunction); } @@ -3365,7 +3389,7 @@ void Builtins::InitializeIcuData() } } else { std::string absPath; - if (GetAbsolutePath(icuPath, absPath)) { + if (FileLoader::GetAbsolutePath(icuPath, absPath)) { u_setDataDirectory(absPath.c_str()); } } diff --git a/ecmascript/builtins.h b/ecmascript/builtins.h index 4740646460d54487e65c6097c4f871af6e9dd383..ee0de854e780b587cc3068e9fc65ec0938da2c6a 100644 --- a/ecmascript/builtins.h +++ b/ecmascript/builtins.h @@ -180,6 +180,8 @@ private: void InitializeDataView(const JSHandle &env, const JSHandle &objFuncDynclass) const; + void InitializeForPromiseFuncClass(const JSHandle &env); + void InitializeProxy(const JSHandle &env); void InitializeReflect(const JSHandle &env, const JSHandle &objFuncPrototypeVal) const; diff --git a/ecmascript/builtins/builtins_ark_tools.cpp b/ecmascript/builtins/builtins_ark_tools.cpp index 48dcd7adadda7e971de3b2aa6d2ab2e051dc8c1e..7429df01c138b3ec6708e84b8a2fb4b1c4bd87da 100644 --- a/ecmascript/builtins/builtins_ark_tools.cpp +++ b/ecmascript/builtins/builtins_ark_tools.cpp @@ -19,60 +19,85 @@ namespace panda::ecmascript::builtins { using StringHelper = base::StringHelper; -JSTaggedValue BuiltinsArkTools::ObjectDump(EcmaRuntimeCallInfo *msg) +JSTaggedValue BuiltinsArkTools::ObjectDump(EcmaRuntimeCallInfo *info) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(info); + JSThread *thread = info->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(msg, 0)); + JSHandle str = JSTaggedValue::ToString(thread, GetCallArg(info, 0)); // The default log level of ace_engine and js_runtime is error - LOG(ERROR, RUNTIME) << ": " << base::StringHelper::ToStdString(*str); + LOG_ECMA(ERROR) << ": " << base::StringHelper::ToStdString(*str); - uint32_t numArgs = msg->GetArgsNumber(); - for (uint32_t i = 1; i < numArgs; i++) { - JSHandle obj = GetCallArg(msg, i); + int32_t numArgs = info->GetArgsNumber(); + for (int32_t i = 1; i < numArgs; i++) { + JSHandle obj = GetCallArg(info, i); std::ostringstream oss; obj->Dump(oss); // The default log level of ace_engine and js_runtime is error - LOG(ERROR, RUNTIME) << ": " << oss.str(); + LOG_ECMA(ERROR) << ": " << oss.str(); } return JSTaggedValue::Undefined(); } -JSTaggedValue BuiltinsArkTools::CompareHClass(EcmaRuntimeCallInfo *msg) +JSTaggedValue BuiltinsArkTools::CompareHClass(EcmaRuntimeCallInfo *info) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(info); + JSThread *thread = info->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj1 = GetCallArg(msg, 0); - JSHandle obj2 = GetCallArg(msg, 1); + JSHandle obj1 = GetCallArg(info, 0); + JSHandle obj2 = GetCallArg(info, 1); JSHClass* obj1Hclass = obj1->GetTaggedObject()->GetClass(); JSHClass* obj2Hclass = obj2->GetTaggedObject()->GetClass(); std::ostringstream oss; obj1Hclass->Dump(oss); bool res = (obj1Hclass == obj2Hclass); if (!res) { - LOG(ERROR, RUNTIME) << "These two object don't share the same hclass:" << oss.str(); + LOG_ECMA(ERROR) << "These two object don't share the same hclass:" << oss.str(); } return JSTaggedValue(res); } -JSTaggedValue BuiltinsArkTools::DumpHClass(EcmaRuntimeCallInfo *msg) +JSTaggedValue BuiltinsArkTools::DumpHClass(EcmaRuntimeCallInfo *info) { - ASSERT(msg); - JSThread *thread = msg->GetThread(); + ASSERT(info); + JSThread *thread = info->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle obj = GetCallArg(msg, 0); + JSHandle obj = GetCallArg(info, 0); JSHClass* objHclass = obj->GetTaggedObject()->GetClass(); std::ostringstream oss; objHclass->Dump(oss); - LOG(ERROR, RUNTIME) << "hclass:" << oss.str(); + LOG_ECMA(ERROR) << "hclass:" << oss.str(); return JSTaggedValue::Undefined(); } + +JSTaggedValue BuiltinsArkTools::IsTSHClass(EcmaRuntimeCallInfo *info) +{ + ASSERT(info); + JSThread *thread = info->GetThread(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + + ASSERT(info->GetArgsNumber() == 1); + JSHandle object = GetCallArg(info, 0); + JSHClass* hclass = object->GetTaggedObject()->GetClass(); + bool isTSHClass = hclass->IsTSType(); + return GetTaggedBoolean(isTSHClass); +} + +JSTaggedValue BuiltinsArkTools::GetHClass(EcmaRuntimeCallInfo *info) +{ + ASSERT(info); + JSThread *thread = info->GetThread(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + + ASSERT(info->GetArgsNumber() == 1); + JSHandle object = GetCallArg(info, 0); + JSHClass* hclass = object->GetTaggedObject()->GetClass(); + return JSTaggedValue(hclass); +} } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_ark_tools.h b/ecmascript/builtins/builtins_ark_tools.h index 2403cb611d023ff3b14acf3e323546c13e2527dc..75a0d1d5134f4b52e7c5aa350698c5f0be7a5b15 100644 --- a/ecmascript/builtins/builtins_ark_tools.h +++ b/ecmascript/builtins/builtins_ark_tools.h @@ -24,11 +24,16 @@ class BuiltinsArkTools : public base::BuiltinsBase { public: // Make sure the ECMASCRIPT_OBJECT_DUMP in config.h has been opened before use it // Use through ArkTools.print(msg, [obj1, obj2, ... objn]) in js - static JSTaggedValue ObjectDump(EcmaRuntimeCallInfo *msg); + static JSTaggedValue ObjectDump(EcmaRuntimeCallInfo *info); - static JSTaggedValue CompareHClass(EcmaRuntimeCallInfo *msg); + static JSTaggedValue CompareHClass(EcmaRuntimeCallInfo *info); - static JSTaggedValue DumpHClass(EcmaRuntimeCallInfo *msg); + static JSTaggedValue DumpHClass(EcmaRuntimeCallInfo *info); + + // return whether the hclass used for object is created by static ts type + static JSTaggedValue IsTSHClass(EcmaRuntimeCallInfo *info); + + static JSTaggedValue GetHClass(EcmaRuntimeCallInfo *info); }; } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_array.cpp b/ecmascript/builtins/builtins_array.cpp index 1a16af2b19727e2cc2e939b8000e347c499d38ce..3eb903a5437617ee84bbc2b2622ff05117ce2c5f 100644 --- a/ecmascript/builtins/builtins_array.cpp +++ b/ecmascript/builtins/builtins_array.cpp @@ -48,7 +48,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let numberOfArgs be the number of arguments passed to this function call. - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 3. If NewTarget is undefined, let newTarget be the active function object, else let newTarget be NewTarget. JSHandle constructor = GetConstructor(argv); @@ -115,7 +115,7 @@ JSTaggedValue BuiltinsArray::ArrayConstructor(EcmaRuntimeCallInfo *argv) // d. Assert: defineStatus is true. // e. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - for (uint32_t k = 0; k < argc; k++) { + for (int32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); JSHandle itemK = GetCallArg(argv, k); JSObject::CreateDataProperty(thread, newArrayHandle, key, itemK); @@ -172,9 +172,9 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // c. ReturnIfAbrupt(A). JSTaggedValue newArray; if (thisHandle->IsConstructor()) { - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, thisHandle, undefined, undefined, 0); - newArray = JSFunction::Construct(&info); + newArray = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue(); @@ -219,14 +219,15 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // 3. Let mappedValue be mappedValue.[[value]]. // viii. Else, let mappedValue be nextValue. if (mapping) { - const size_t argsLength = 2; // 2: «nextValue, k» - EcmaRuntimeCallInfo info = + const int32_t argsLength = 2; // 2: «nextValue, k» + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, mapfn, thisArgHandle, undefined, argsLength); - info.SetCallArg(nextValue.GetTaggedValue(), key.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(nextValue.GetTaggedValue(), key.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); mapValue.Update(callResult); JSTaggedValue mapResult = JSIterator::IteratorClose(thread, iterator, mapValue).GetTaggedValue(); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue(mapResult)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, mapResult); } else { mapValue.Update(nextValue.GetTaggedValue()); } @@ -236,7 +237,7 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) JSHandle defineStatus( thread, JSTaggedValue(JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, key, mapValue))); JSTaggedValue defineResult = JSIterator::IteratorClose(thread, iterator, defineStatus).GetTaggedValue(); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue(defineResult)); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, defineResult); k++; } } @@ -257,10 +258,11 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) // 14. ReturnIfAbrupt(A). JSTaggedValue newArray; if (thisHandle->IsConstructor()) { - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, thisHandle, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(len)); - newArray = JSFunction::Construct(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(JSTaggedValue(len)); + newArray = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } else { newArray = JSArray::ArrayCreate(thread, JSTaggedNumber(len)).GetTaggedValue(); @@ -286,11 +288,12 @@ JSTaggedValue BuiltinsArray::From(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (mapping) { key.Update(JSTaggedValue(k)); - const size_t argsLength = 2; // 2: «kValue, k» - EcmaRuntimeCallInfo info = + const int32_t argsLength = 2; // 2: «kValue, k» + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, mapfn, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); mapValue.Update(callResult); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -333,7 +336,7 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) JSHandle lengthKey = globalConst->GetHandledLengthString(); // 1. Let len be the actual number of arguments passed to this function. - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 3. Let C be the this value. JSHandle thisHandle = GetThis(argv); @@ -345,10 +348,11 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) JSHandle newArray; if (thisHandle->IsConstructor()) { JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, thisHandle, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(argc)); - JSTaggedValue taggedArray = JSFunction::Construct(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(JSTaggedValue(argc)); + JSTaggedValue taggedArray = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); newArray = JSHandle(thread, taggedArray); } else { @@ -368,7 +372,7 @@ JSTaggedValue BuiltinsArray::Of(EcmaRuntimeCallInfo *argv) // d. ReturnIfAbrupt(defineStatus). // e. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - for (uint32_t k = 0; k < argc; k++) { + for (int32_t k = 0; k < argc; k++) { key.Update(JSTaggedValue(k)); JSHandle kValue = GetCallArg(argv, k); JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, key, kValue); @@ -397,7 +401,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Array, Concat); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -449,7 +453,7 @@ JSTaggedValue BuiltinsArray::Concat(EcmaRuntimeCallInfo *argv) n++; } // 7. Repeat, while items is not empty - for (uint32_t i = 0; i < argc; i++) { + for (int32_t i = 0; i < argc; i++) { // a. Remove the first element from items and let E be the value of the element JSHandle addHandle = GetCallArg(argv, i); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -708,12 +712,13 @@ JSTaggedValue BuiltinsArray::Every(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool boolResult = callResult.ToBoolean(); if (!boolResult) { @@ -870,12 +875,13 @@ JSTaggedValue BuiltinsArray::Filter(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); bool boolResult = callResult.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boolResult) { @@ -936,12 +942,13 @@ JSTaggedValue BuiltinsArray::Find(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); bool boolResult = callResult.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boolResult) { @@ -998,12 +1005,13 @@ JSTaggedValue BuiltinsArray::FindIndex(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); bool boolResult = callResult.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boolResult) { @@ -1064,12 +1072,13 @@ JSTaggedValue BuiltinsArray::ForEach(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); } k++; @@ -1087,7 +1096,7 @@ JSTaggedValue BuiltinsArray::IndexOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1275,7 +1284,7 @@ JSTaggedValue BuiltinsArray::LastIndexOf(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1400,12 +1409,13 @@ JSTaggedValue BuiltinsArray::Map(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, k); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue mapResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue mapResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); mapResultHandle.Update(mapResult); JSObject::CreateDataPropertyOrThrow(thread, newArrayHandle, k, mapResultHandle); @@ -1486,7 +1496,7 @@ JSTaggedValue BuiltinsArray::Push(EcmaRuntimeCallInfo *argv) return JSStableArray::Push(JSHandle::Cast(thisHandle), argv); } // 6. Let argCount be the number of elements in items. - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -1539,7 +1549,7 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -1617,13 +1627,14 @@ JSTaggedValue BuiltinsArray::Reduce(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); JSHandle thisArgHandle = globalConst->GetHandledUndefined(); - const size_t argsLength = 4; // 4: «accumulator, kValue, k, O» + const int32_t argsLength = 4; // 4: «accumulator, kValue, k, O» JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(accumulator.GetTaggedValue(), kValue.GetTaggedValue(), key.GetTaggedValue(), + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(accumulator.GetTaggedValue(), kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - callResult = JSFunction::Call(&info); + callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); accumulator.Update(callResult); } @@ -1643,7 +1654,7 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -1722,13 +1733,14 @@ JSTaggedValue BuiltinsArray::ReduceRight(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle thisArgHandle = globalConst->GetHandledUndefined(); - const size_t argsLength = 4; // 4: «accumulator, kValue, k, O» + const int32_t argsLength = 4; // 4: «accumulator, kValue, k, O» JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(accumulator.GetTaggedValue(), kValue.GetTaggedValue(), key.GetTaggedValue(), + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(accumulator.GetTaggedValue(), kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - callResult = JSFunction::Call(&info); + callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); accumulator.Update(callResult); } @@ -2096,12 +2108,13 @@ JSTaggedValue BuiltinsArray::Some(EcmaRuntimeCallInfo *argv) key.Update(JSTaggedValue(k)); JSHandle kValue = JSArray::FastGetPropertyByValue(thread, thisObjVal, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - const size_t argsLength = 3; // 3: «kValue, k, O» + const int32_t argsLength = 3; // 3: «kValue, k, O» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); bool boolResult = callResult.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boolResult) { @@ -2186,7 +2199,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Array, Splice); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); @@ -2366,7 +2379,7 @@ JSTaggedValue BuiltinsArray::Splice(EcmaRuntimeCallInfo *argv) k = start; // 23. Repeat, while items is not empty JSMutableHandle key(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 2; i < argc; i++) { + for (int32_t i = 2; i < argc; i++) { JSHandle itemValue = GetCallArg(argv, i); key.Update(JSTaggedValue(k)); JSArray::FastSetPropertyByValue(thread, thisObjVal, key, itemValue); @@ -2454,10 +2467,11 @@ JSTaggedValue BuiltinsArray::ToLocaleString(EcmaRuntimeCallInfo *argv) if (!nextElement->IsUndefined() && !nextElement->IsNull()) { JSHandle nextValueHandle = nextElement; JSHandle key = globalConst->GetHandledToLocaleStringString(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextValueHandle, undefined, 2); // 2: two args - info.SetCallArg(locales.GetTaggedValue(), options.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Invoke(&info, key); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(locales.GetTaggedValue(), options.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Invoke(info, key); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); next = callResult; } @@ -2508,12 +2522,13 @@ JSTaggedValue BuiltinsArray::ToString(EcmaRuntimeCallInfo *argv) callbackFnHandle = JSTaggedValue::GetProperty(thread, objectPrototype, toStringKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } - const size_t argsLength = argv->GetArgsNumber(); + const int32_t argsLength = argv->GetArgsNumber(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisObjVal, undefined, argsLength); - info.SetCallArg(argsLength, 0, argv, 0); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, 0, argv, 0); + return JSFunction::Call(info); } // 22.1.3.28 Array.prototype.unshift ( ...items ) @@ -2525,7 +2540,7 @@ JSTaggedValue BuiltinsArray::Unshift(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); // 5. Let argCount be the number of actual arguments. - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); // 1. Let O be ToObject(this value). JSHandle thisHandle = GetThis(argv); @@ -2682,7 +2697,7 @@ JSTaggedValue BuiltinsArray::Flat(EcmaRuntimeCallInfo *argv) JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - array_size_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); JSHandle thisObjVal(thisObjHandle); // 2. Let sourceLen be ? LengthOfArrayLike(O). @@ -2769,7 +2784,7 @@ JSTaggedValue BuiltinsArray::Includes(EcmaRuntimeCallInfo *argv) JSHandle thisObjHandle = JSTaggedValue::ToObject(thread, thisHandle); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - array_size_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); JSHandle thisObjVal(thisObjHandle); JSHandle searchElement = GetCallArg(argv, 0); diff --git a/ecmascript/builtins/builtins_arraybuffer.cpp b/ecmascript/builtins/builtins_arraybuffer.cpp index 830b64671df2367e6396ceae4d691726e939c8ef..67718437e625615a1ea32f3675796bce226ff81b 100644 --- a/ecmascript/builtins/builtins_arraybuffer.cpp +++ b/ecmascript/builtins/builtins_arraybuffer.cpp @@ -170,10 +170,11 @@ JSTaggedValue BuiltinsArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 15. Let new be Construct(ctor, «newLen»). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(newLen)); - JSTaggedValue taggedNewArrBuf = JSFunction::Construct(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(JSTaggedValue(newLen)); + JSTaggedValue taggedNewArrBuf = JSFunction::Construct(info); JSHandle newArrBuf(thread, taggedNewArrBuf); // 16. ReturnIfAbrupt(new). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/builtins/builtins_atomics.cpp b/ecmascript/builtins/builtins_atomics.cpp index 1db98b8229a221f2300802495acf984a358231b0..c4e63f7f6bff2df3212c54f20e16ba355df13d0f 100644 --- a/ecmascript/builtins/builtins_atomics.cpp +++ b/ecmascript/builtins/builtins_atomics.cpp @@ -157,7 +157,7 @@ JSTaggedValue BuiltinsAtomics::Wait(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - BUILTINS_API_TRACE(thread, Atomic, Wait); + BUILTINS_API_TRACE(thread, Atomics, Wait); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle array = GetCallArg(argv, 0); @@ -233,7 +233,7 @@ JSTaggedValue BuiltinsAtomics::Notify(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - BUILTINS_API_TRACE(thread, Atomic, Notify); + BUILTINS_API_TRACE(thread, Atomics, Notify); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle array = GetCallArg(argv, 0); @@ -308,7 +308,7 @@ JSTaggedValue BuiltinsAtomics::AtomicReadModifyWriteCase(JSThread *thread, JSTag JSTaggedValue data = jsArrayBuffer->GetArrayBufferData(); void *pointer = JSNativePointer::Cast(data.GetTaggedObject())->GetExternalPointer(); auto *block = reinterpret_cast(pointer); - uint32_t size = argv->GetArgsNumber(); + uint32_t size = static_cast(argv->GetArgsNumber()); switch (type) { case DataViewType::UINT8: return HandleWithUint8(thread, size, block, indexedPosition, argv, op); diff --git a/ecmascript/builtins/builtin_cjs_exports.cpp b/ecmascript/builtins/builtins_cjs_exports.cpp similarity index 95% rename from ecmascript/builtins/builtin_cjs_exports.cpp rename to ecmascript/builtins/builtins_cjs_exports.cpp index 4525c509859270204d394093298b4d4a98bc8240..eb9edd0773cc81aa67fcc68c331605d329bd4244 100644 --- a/ecmascript/builtins/builtin_cjs_exports.cpp +++ b/ecmascript/builtins/builtins_cjs_exports.cpp @@ -15,10 +15,9 @@ #include "ecmascript/base/builtins_base.h" #include "ecmascript/require/js_cjs_exports.h" -#include "ecmascript/builtins/builtin_cjs_exports.h" +#include "ecmascript/builtins/builtins_cjs_exports.h" namespace panda::ecmascript::builtins { - JSTaggedValue BuiltinsCjsExports::CjsExportsConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); diff --git a/ecmascript/builtins/builtin_cjs_exports.h b/ecmascript/builtins/builtins_cjs_exports.h similarity index 99% rename from ecmascript/builtins/builtin_cjs_exports.h rename to ecmascript/builtins/builtins_cjs_exports.h index cf37359bc20169ee4a4f0afddc1aabad00bf175b..b22a7cc1c52cf9b8d5fe3b9d8a625802247de070 100644 --- a/ecmascript/builtins/builtin_cjs_exports.h +++ b/ecmascript/builtins/builtins_cjs_exports.h @@ -23,9 +23,7 @@ namespace panda::ecmascript::builtins { class BuiltinsCjsExports : public base::BuiltinsBase { public: - static JSTaggedValue CjsExportsConstructor(EcmaRuntimeCallInfo *argv); - }; } // namespace panda::ecmascript::builtins #endif // ECMASCRIPT_BUILTINS_BUILTINS_CJS_EXPORTS_H diff --git a/ecmascript/builtins/builtin_cjs_module.cpp b/ecmascript/builtins/builtins_cjs_module.cpp similarity index 89% rename from ecmascript/builtins/builtin_cjs_module.cpp rename to ecmascript/builtins/builtins_cjs_module.cpp index 3599d3b45f4fd67911fe1d83395bd49cb1ec30bc..0258887e375538721c9fa62a0c6c05a04641e23b 100644 --- a/ecmascript/builtins/builtin_cjs_module.cpp +++ b/ecmascript/builtins/builtins_cjs_module.cpp @@ -14,7 +14,7 @@ */ #include "ecmascript/base/builtins_base.h" -#include "ecmascript/builtins/builtin_cjs_module.h" +#include "ecmascript/builtins/builtins_cjs_module.h" #include "ecmascript/require/js_cjs_module.h" #include "ecmascript/require/js_require_manager.h" #include "ecmascript/interpreter/interpreter-inl.h" @@ -51,19 +51,19 @@ JSTaggedValue BuiltinsCjsModule::ResolveFilename(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t length = argv->GetArgsNumber(); + int32_t length = argv->GetArgsNumber(); JSMutableHandle parent(thread, JSTaggedValue::Undefined()); JSMutableHandle dirname(thread, JSTaggedValue::Undefined()); const JSPandaFile *jsPandaFile = EcmaInterpreter::GetNativeCallPandafile(thread); - JSRequireManager::ResolveCurrentPath(thread, parent, dirname, jsPandaFile); + RequireManager::ResolveCurrentPath(thread, parent, dirname, jsPandaFile); if (length != 1) { // strange arg's number LOG_ECMA(ERROR) << "BuiltinsCjsModule::Load : can only accept one argument"; UNREACHABLE(); } JSHandle requestName = JSHandle::Cast(GetCallArg(argv, 0)); - JSHandle filename = JSCjsModule::ResolveFilename(thread, dirname.GetTaggedValue(), - requestName.GetTaggedValue()); + JSHandle filename = CjsModule::ResolveFilename(thread, dirname.GetTaggedValue(), + requestName.GetTaggedValue()); return filename.GetTaggedValue(); } diff --git a/ecmascript/builtins/builtin_cjs_module.h b/ecmascript/builtins/builtins_cjs_module.h similarity index 100% rename from ecmascript/builtins/builtin_cjs_module.h rename to ecmascript/builtins/builtins_cjs_module.h diff --git a/ecmascript/builtins/builtin_cjs_require.cpp b/ecmascript/builtins/builtins_cjs_require.cpp similarity index 93% rename from ecmascript/builtins/builtin_cjs_require.cpp rename to ecmascript/builtins/builtins_cjs_require.cpp index 16aaebb576226d61eab02dce33c0a3758f0ea633..3fe8d6accf6b15133f0ac89d48ecdd032927ad40 100644 --- a/ecmascript/builtins/builtin_cjs_require.cpp +++ b/ecmascript/builtins/builtins_cjs_require.cpp @@ -19,10 +19,9 @@ #include "ecmascript/js_object-inl.h" #include "ecmascript/js_tagged_value-inl.h" #include "ecmascript/js_thread.h" -#include "ecmascript/builtins/builtin_cjs_require.h" +#include "ecmascript/builtins/builtins_cjs_require.h" namespace panda::ecmascript::builtins { - JSTaggedValue BuiltinsCjsRequire::CjsRequireConstructor(EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); @@ -33,14 +32,14 @@ JSTaggedValue BuiltinsCjsRequire::CjsRequireConstructor(EcmaRuntimeCallInfo *arg if (!newTarget->IsUndefined()) { THROW_TYPE_ERROR_AND_RETURN(thread, "newTarget is undefined", JSTaggedValue::Exception()); } - uint32_t length = argv->GetArgsNumber(); + int32_t length = argv->GetArgsNumber(); JSHandle result(thread, JSTaggedValue::Undefined()); if (length != 1) { // strange arg's number LOG_ECMA(ERROR) << "BuiltinsCjsRequire::CjsRequireConstructor : can only accept one argument"; UNREACHABLE(); } JSHandle requestName = JSHandle::Cast(GetCallArg(argv, 0)); - result = JSCjsModule::Load(thread, requestName); + result = CjsModule::Load(thread, requestName); return result.GetTaggedValue(); } diff --git a/ecmascript/builtins/builtin_cjs_require.h b/ecmascript/builtins/builtins_cjs_require.h similarity index 100% rename from ecmascript/builtins/builtin_cjs_require.h rename to ecmascript/builtins/builtins_cjs_require.h diff --git a/ecmascript/builtins/builtins_date.cpp b/ecmascript/builtins/builtins_date.cpp index 1721d8e82772d0c2ff04cbf163e16a229593218e..75a1c784af28116889d915493434b9d9adad26f7 100644 --- a/ecmascript/builtins/builtins_date.cpp +++ b/ecmascript/builtins/builtins_date.cpp @@ -41,7 +41,7 @@ JSTaggedValue BuiltinsDate::DateConstructor(EcmaRuntimeCallInfo *argv) } JSTaggedValue timeValue(0.0); - uint32_t length = argv->GetArgsNumber(); + uint32_t length = static_cast(argv->GetArgsNumber()); if (length == 0) { // no value timeValue = JSDate::Now(); } else if (length == 1) { // one value @@ -177,9 +177,9 @@ JSTaggedValue BuiltinsDate::ToJSON(EcmaRuntimeCallInfo *argv) } JSHandle calleeKey(thread->GetEcmaVM()->GetFactory()->NewFromASCII("toISOString")); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, objectHandle, undefined, 0); - return JSFunction::Invoke(&info, calleeKey); + return JSFunction::Invoke(info, calleeKey); } // 20.4.4.44 diff --git a/ecmascript/builtins/builtins_errors.cpp b/ecmascript/builtins/builtins_errors.cpp index 9be6f76d93e23c66eff03d261a5951b32496e2be..b54752f724f999eb810452dd43244dddd422b4cd 100644 --- a/ecmascript/builtins/builtins_errors.cpp +++ b/ecmascript/builtins/builtins_errors.cpp @@ -15,7 +15,12 @@ #include "ecmascript/builtins/builtins_errors.h" #include "ecmascript/base/error_helper.h" +#include "ecmascript/ecma_macros.h" +#include "ecmascript/global_env.h" #include "ecmascript/js_tagged_value-inl.h" +#include "ecmascript/js_array.h" +#include "ecmascript/js_primitive_ref.h" +#include "ecmascript/js_iterator.h" namespace panda::ecmascript::builtins { using ErrorHelper = base::ErrorHelper; @@ -103,4 +108,55 @@ JSTaggedValue BuiltinsEvalError::ToString(EcmaRuntimeCallInfo *argv) { return ErrorHelper::ErrorCommonToString(argv, ErrorType::EVAL_ERROR); } + +// AggregateError +JSTaggedValue BuiltinsAggregateError::AggregateErrorConstructor(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + [[maybe_unused]] EcmaHandleScope scope(thread); + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + // 1. If NewTarget is undefined, let newTarget be the active function object; else let newTarget be NewTarget. + JSHandle constructor = GetConstructor(argv); + JSMutableHandle newTarget(thread, GetNewTarget(argv)); + if (newTarget->IsUndefined()) { + newTarget.Update(constructor.GetTaggedValue()); + } + JSHandle errors = BuiltinsBase::GetCallArg(argv, 0); + JSHandle message = BuiltinsBase::GetCallArg(argv, 1); + // 2. Let O be ? OrdinaryCreateFromConstructor(newTarget, "%AggregateError.prototype%", « [[ErrorData]] »). + JSHandle objValues = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle taggedObj = JSHandle::Cast(objValues); + // 3. If message is not undefined, then + // a. Let msg be ? ToString(message). + // b. Let msgDesc be the PropertyDescriptor + // { [[Value]]: msg, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }. + // c. Perform ! DefinePropertyOrThrow(O, "message", msgDesc). + JSHandle msgKey = globalConst->GetHandledMessageString(); + JSHandle errorsKey = globalConst->GetHandledErrorsString(); + if (!message->IsUndefined()) { + JSHandle handleStr = JSTaggedValue::ToString(thread, message); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + PropertyDescriptor msgDesc(thread, JSHandle::Cast(handleStr), true, false, true); + JSTaggedValue::DefinePropertyOrThrow(thread, taggedObj, msgKey, msgDesc); + } + // 4. Let errorsList be ? IterableToList(errors). + JSHandle errorsList = JSObject::IterableToList(thread, errors); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 5. Perform ! DefinePropertyOrThrow(O, "errors", PropertyDescriptor { [[Configurable]]: true, + // [[Enumerable]]: false, [[Writable]]: true, [[Value]]: !CreateArrayFromList(errorsList) }). + JSHandle errorsArray = JSArray::ToTaggedArray(thread, errorsList); + JSHandle errorsValues(JSArray::CreateArrayFromList(thread, errorsArray)); + PropertyDescriptor msgDesc(thread, errorsValues, true, false, true); + JSTaggedValue::DefinePropertyOrThrow(thread, taggedObj, errorsKey, msgDesc); + // 6. Return O. + return taggedObj.GetTaggedValue(); +} + +JSTaggedValue BuiltinsAggregateError::ToString(EcmaRuntimeCallInfo *argv) +{ + return ErrorHelper::ErrorCommonToString(argv, ErrorType::AGGREGATE_ERROR); +} } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_errors.h b/ecmascript/builtins/builtins_errors.h index 9c842a790a927f0d096364c4048bb1b946e40203..7f9e83f841e09f723ae75244c608ed98035edf30 100644 --- a/ecmascript/builtins/builtins_errors.h +++ b/ecmascript/builtins/builtins_errors.h @@ -77,6 +77,13 @@ public: static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); }; -} // namespace panda::ecmascript::builtins + +class BuiltinsAggregateError : public base::BuiltinsBase { +public: + static JSTaggedValue AggregateErrorConstructor(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); +}; +} // namespace panda::ecmascript::builtins #endif // ECMASCRIPT_BUILTINS_BUILTINS_ERRORS_H diff --git a/ecmascript/builtins/builtins_finalization_registry.cpp b/ecmascript/builtins/builtins_finalization_registry.cpp index 25bfb1355b5ab95ed3accafc233fde2522469f1a..34e48d7a69dfbadd8f33e8d96fdfcf6dd397580f 100644 --- a/ecmascript/builtins/builtins_finalization_registry.cpp +++ b/ecmascript/builtins/builtins_finalization_registry.cpp @@ -63,7 +63,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Register(EcmaRuntimeCallInfo *argv) { ASSERT(argv); JSThread *thread = argv->GetThread(); - BUILTINS_API_TRACE(thread, BuiltinsFinalizationRegistry, Register); + BUILTINS_API_TRACE(thread, FinalizationRegistry, Register); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle target = GetCallArg(argv, 0); JSHandle heldValue = GetCallArg(argv, 1); @@ -102,7 +102,7 @@ JSTaggedValue BuiltinsFinalizationRegistry::Unregister(EcmaRuntimeCallInfo *argv { ASSERT(argv); JSThread *thread = argv->GetThread(); - BUILTINS_API_TRACE(thread, BuiltinsFinalizationRegistry, Unregister); + BUILTINS_API_TRACE(thread, FinalizationRegistry, Unregister); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle unregisterToken = GetCallArg(argv, 0); // 1. Let finalizationRegistry be the this value. diff --git a/ecmascript/builtins/builtins_function.cpp b/ecmascript/builtins/builtins_function.cpp index 031244f66709f01572992e39b93fd70a1e7945fd..beb862c1dfc19a648ef6987637dc97d4889ec140 100644 --- a/ecmascript/builtins/builtins_function.cpp +++ b/ecmascript/builtins/builtins_function.cpp @@ -104,8 +104,8 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv // 2. If argArray is null or undefined, then if (GetCallArg(argv, 1)->IsUndefined()) { // null will also get undefined // a. Return Call(func, thisArg). - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, 0); - return JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, 0); + return JSFunction::Call(info); } // 3. Let argList be CreateListFromArrayLike(argArray). JSHandle arrayObj = GetCallArg(argv, 1); @@ -115,16 +115,18 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeApply(EcmaRuntimeCallInfo *argv JSObject::CreateListFromArrayLike(thread, arrayObj)); // 4. ReturnIfAbrupt(argList). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - const size_t argsLength = argList->GetLength(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); - info.SetCallArg(argsLength, argList); - return JSFunction::Call(&info); + const int32_t argsLength = static_cast(argList->GetLength()); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, argList); + return JSFunction::Call(info); } // 6. Return Call(func, thisArg, argList). - const size_t argsLength = argumentsList.second; - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); - info.SetCallArg(argsLength, argumentsList.first); - return JSFunction::Call(&info); + const int32_t argsLength = static_cast(argumentsList.second); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, argumentsList.first); + return JSFunction::Call(info); } // ecma 19.2.3.2 Function.prototype.bind (thisArg , ...args) @@ -144,7 +146,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) } JSHandle thisArg = GetCallArg(argv, 0); - size_t argsLength = 0; + int32_t argsLength = 0; if (argv->GetArgsNumber() > 1) { argsLength = argv->GetArgsNumber() - 1; } @@ -152,7 +154,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeBind(EcmaRuntimeCallInfo *argv) // 3. Let args be a new (possibly empty) List consisting of all of the argument // values provided after thisArg in order. JSHandle argsArray = factory->NewTaggedArray(argsLength); - for (size_t index = 0; index < argsLength; ++index) { + for (int32_t index = 0; index < argsLength; ++index) { argsArray->Set(thread, index, GetCallArg(argv, index + 1)); } // 4. Let F be BoundFunctionCreate(Target, thisArg, args). @@ -234,7 +236,7 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) JSHandle func = GetThis(argv); JSHandle thisArg = GetCallArg(argv, 0); - size_t argsLength = 0; + int32_t argsLength = 0; if (argv->GetArgsNumber() > 1) { argsLength = argv->GetArgsNumber() - 1; } @@ -243,9 +245,10 @@ JSTaggedValue BuiltinsFunction::FunctionPrototypeCall(EcmaRuntimeCallInfo *argv) // starting with the second argument, append each argument as the last element of argList. // 5. Return Call(func, thisArg, argList). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); - info.SetCallArg(argsLength, 0, argv, 1); - return JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, 0, argv, 1); + return JSFunction::Call(info); } // ecma 19.2.3.5 Function.prototype.toString () diff --git a/ecmascript/builtins/builtins_global.cpp b/ecmascript/builtins/builtins_global.cpp index 4609089c1ec142ba04daeb267dbdde740bb5b3bd..0efd5b826792bea8674158f76520eb68972b5d61 100644 --- a/ecmascript/builtins/builtins_global.cpp +++ b/ecmascript/builtins/builtins_global.cpp @@ -479,8 +479,8 @@ JSTaggedValue BuiltinsGlobal::PrintEntrypoint(EcmaRuntimeCallInfo *msg) [[maybe_unused]] EcmaHandleScope handleScope(thread); BUILTINS_API_TRACE(thread, Global, PrintEntryPoint); - uint32_t numArgs = msg->GetArgsNumber(); - for (uint32_t i = 0; i < numArgs; i++) { + int32_t numArgs = msg->GetArgsNumber(); + for (int32_t i = 0; i < numArgs; i++) { JSHandle stringContent = JSTaggedValue::ToString(thread, GetCallArg(msg, i)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); PrintString(thread, *stringContent); diff --git a/ecmascript/builtins/builtins_json.cpp b/ecmascript/builtins/builtins_json.cpp index 44b82bb5d334cce359a453226cd8f6d519046df3..a4dbc458782579a301b885c0e9bd7603ef87f302 100644 --- a/ecmascript/builtins/builtins_json.cpp +++ b/ecmascript/builtins/builtins_json.cpp @@ -35,7 +35,7 @@ JSTaggedValue BuiltinsJson::Parse(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc == 0) { JSHandle syntaxError = factory->GetJSError(base::ErrorType::SYNTAX_ERROR, "arg is empty"); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); @@ -83,7 +83,7 @@ JSTaggedValue BuiltinsJson::Stringify(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); JSTaggedValue value = GetCallArg(argv, 0).GetTaggedValue(); JSTaggedValue replacer = JSTaggedValue::Undefined(); JSTaggedValue gap = JSTaggedValue::Undefined(); diff --git a/ecmascript/builtins/builtins_map.cpp b/ecmascript/builtins/builtins_map.cpp index d6075ac43544c96d8f6f521fff7a3c623ff91951..e9b82173c6f898113c2c1fed0865da69ff22c634 100644 --- a/ecmascript/builtins/builtins_map.cpp +++ b/ecmascript/builtins/builtins_map.cpp @@ -177,7 +177,7 @@ JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSHandle thisArg = GetCallArg(argv, 1); JSMutableHandle hashMap(thread, map->GetLinkedMap()); - const size_t argsLength = 3; + const int32_t argsLength = 3; int index = 0; int totalElements = hashMap->NumberOfElements() + hashMap->NumberOfDeletedElements(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); @@ -187,11 +187,12 @@ JSTaggedValue BuiltinsMap::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) // a. If e is not empty, then if (!key->IsHole()) { JSHandle value(thread, hashMap->GetValue(index - 1)); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo( + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo( thread, func, thisArg, undefined, argsLength); - info.SetCallArg(value.GetTaggedValue(), key.GetTaggedValue(), map.GetTaggedValue()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(value.GetTaggedValue(), key.GetTaggedValue(), map.GetTaggedValue()); // i. Let funcResult be Call(callbackfn, T, «e, e, S»). - JSTaggedValue ret = JSFunction::Call(&info); // 3: three args + JSTaggedValue ret = JSFunction::Call(info); // 3: three args // ii. ReturnIfAbrupt(funcResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // Maybe add or delete @@ -306,12 +307,13 @@ JSTaggedValue BuiltinsMap::AddEntriesFromIterable(JSThread *thread, const JSHand if (thread->HasPendingException()) { return JSIterator::IteratorCloseAndReturn(thread, iter); } - const size_t argsLength = 2; // 2: key and value pair + const int32_t argsLength = 2; // 2: key and value pair JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, adder, JSHandle(target), undefined, argsLength); - info.SetCallArg(key.GetTaggedValue(), value.GetTaggedValue()); - JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, next.GetTaggedValue()); + info->SetCallArg(key.GetTaggedValue(), value.GetTaggedValue()); + JSFunction::Call(info); // If status is an abrupt completion, return IteratorClose(iter, status). if (thread->HasPendingException()) { return JSIterator::IteratorCloseAndReturn(thread, iter); diff --git a/ecmascript/builtins/builtins_math.cpp b/ecmascript/builtins/builtins_math.cpp index 744d87b38dab75df2552ac4db2561e381b1b7643..1b1191368890c090690bae27cb00cbe4a64f7210 100644 --- a/ecmascript/builtins/builtins_math.cpp +++ b/ecmascript/builtins/builtins_math.cpp @@ -363,9 +363,9 @@ JSTaggedValue BuiltinsMath::Hypot(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); double result = 0; double value = 0; - uint32_t argLen = argv->GetArgsNumber(); + int32_t argLen = argv->GetArgsNumber(); auto numberValue = JSTaggedNumber(0); - for (uint32_t i = 0; i < argLen; i++) { + for (int32_t i = 0; i < argLen; i++) { JSHandle msg = GetCallArg(argv, i); numberValue = JSTaggedValue::ToNumber(thread, msg); value = numberValue.GetNumber(); @@ -482,13 +482,13 @@ JSTaggedValue BuiltinsMath::Max(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Math, Max); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argLen = argv->GetArgsNumber(); + int32_t argLen = argv->GetArgsNumber(); auto numberValue = JSTaggedNumber(-base::POSITIVE_INFINITY); // If no arguments are given, the result is -inf auto result = JSTaggedNumber(-base::POSITIVE_INFINITY); auto tmpMax = -base::POSITIVE_INFINITY; auto value = -base::POSITIVE_INFINITY; - for (uint32_t i = 0; i < argLen; i++) { + for (int32_t i = 0; i < argLen; i++) { JSHandle msg = GetCallArg(argv, i); numberValue = JSTaggedValue::ToNumber(thread, msg); value = numberValue.GetNumber(); @@ -516,13 +516,13 @@ JSTaggedValue BuiltinsMath::Min(EcmaRuntimeCallInfo *argv) BUILTINS_API_TRACE(argv->GetThread(), Math, Min); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t argLen = argv->GetArgsNumber(); + int32_t argLen = argv->GetArgsNumber(); auto numberValue = JSTaggedNumber(base::POSITIVE_INFINITY); // If no arguments are given, the result is inf auto result = JSTaggedNumber(base::POSITIVE_INFINITY); auto tmpMin = base::POSITIVE_INFINITY; auto value = base::POSITIVE_INFINITY; - for (uint32_t i = 0; i < argLen; i++) { + for (int32_t i = 0; i < argLen; i++) { JSHandle msg = GetCallArg(argv, i); numberValue = JSTaggedValue::ToNumber(thread, msg); value = numberValue.GetNumber(); @@ -698,8 +698,12 @@ JSTaggedValue BuiltinsMath::Sqrt(EcmaRuntimeCallInfo *argv) JSTaggedNumber numberValue = JSTaggedValue::ToNumber(thread, msg); double value = numberValue.GetNumber(); double result = base::NAN_VALUE; - // If value is NaN or -NaN, or value < 0, the result is NaN - if (!std::isnan(std::abs(value)) && value >= 0) { + // If value is negative, include -NaN and -Infinity but not -0.0, the result is NaN + if (std::signbit(value) && value != 0) { + return GetTaggedDouble(result); + } + // If value is NaN, the result is NaN + if (!std::isnan(value)) { result = std::sqrt(value); } return GetTaggedDouble(result); diff --git a/ecmascript/builtins/builtins_number_format.h b/ecmascript/builtins/builtins_number_format.h index f61eaa5e754c3fae9b22fd130aa666c3605d75ec..31e56248f9c6db05c08296cce0d88dd414f5ea80 100644 --- a/ecmascript/builtins/builtins_number_format.h +++ b/ecmascript/builtins/builtins_number_format.h @@ -36,6 +36,9 @@ public: // 13.4.5 Intl.DateTimeFormat.prototype.resolvedOptions () static JSTaggedValue ResolvedOptions(EcmaRuntimeCallInfo *argv); +private: + friend class panda::ecmascript::ObjectFactory; + // Number Format Functions static JSTaggedValue NumberFormatInternalFormatNumber(EcmaRuntimeCallInfo *argv); }; } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_object.cpp b/ecmascript/builtins/builtins_object.cpp index 2c8142755974a331a1d9ced91a0f4e72a0910304..09baea55eb2242bf9cbcd0585c4eb5b63b0b989e 100644 --- a/ecmascript/builtins/builtins_object.cpp +++ b/ecmascript/builtins/builtins_object.cpp @@ -66,7 +66,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); - uint32_t numArgs = argv->GetArgsNumber(); + int32_t numArgs = argv->GetArgsNumber(); // 1.Let to be ToObject(target). JSHandle target = GetCallArg(argv, 0); JSHandle toAssign = JSTaggedValue::ToObject(thread, target); @@ -82,7 +82,7 @@ JSTaggedValue BuiltinsObject::Assign(EcmaRuntimeCallInfo *argv) // ii.Let keys be from.[[OwnPropertyKeys]](). // iii.ReturnIfAbrupt(keys). JSMutableHandle key(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 1; i < numArgs; i++) { + for (int32_t i = 1; i < numArgs; i++) { JSHandle source = GetCallArg(argv, i); if (!source->IsNull() && !source->IsUndefined()) { JSHandle from = JSTaggedValue::ToObject(thread, source); @@ -537,6 +537,32 @@ JSTaggedValue BuiltinsObject::Keys(EcmaRuntimeCallInfo *argv) return result.GetTaggedValue(); } +// 20.1.2.22 Object.values(O) +JSTaggedValue BuiltinsObject::Values(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, Object, Values); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + + // 1. Let obj be ToObject(O). + JSHandle msg = GetCallArg(argv, 0); + JSHandle obj = JSTaggedValue::ToObject(thread, msg); + + // 2. ReturnIfAbrupt(obj). + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + + // 3. Let nameList be ? EnumerableOwnPropertyNames(obj, value). + JSHandle nameList = JSObject::EnumerableOwnPropertyNames(thread, obj, PropertyKind::VALUE); + + // 4. ReturnIfAbrupt(nameList). + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + + // 5. Return CreateArrayFromList(nameList). + JSHandle result = JSArray::CreateArrayFromList(thread, nameList); + return result.GetTaggedValue(); +} + // 19.1.2.15 Object.preventExtensions(O) JSTaggedValue BuiltinsObject::PreventExtensions(EcmaRuntimeCallInfo *argv) { @@ -741,15 +767,16 @@ JSTaggedValue BuiltinsObject::ToLocaleString(EcmaRuntimeCallInfo *argv) [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let O be the this value. JSHandle object = GetThis(argv); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(argv->GetThread()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 2. Return Invoke(O, "toString"). JSHandle calleeKey = thread->GlobalConstants()->GetHandledToStringString(); - const size_t argsLength = argv->GetArgsNumber(); + const int32_t argsLength = argv->GetArgsNumber(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, object, undefined, argsLength); - info.SetCallArg(argsLength, 0, argv, 0); - return JSFunction::Invoke(&info, calleeKey); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, object, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, 0, argv, 0); + return JSFunction::Invoke(info, calleeKey); } JSTaggedValue BuiltinsObject::GetBuiltinTag(JSThread *thread, const JSHandle &object) diff --git a/ecmascript/builtins/builtins_object.h b/ecmascript/builtins/builtins_object.h index 59bcd0a97af14ed5d4fd791b5bb63b83732a91f3..82ab31a5904b1544015f0d607e11f21d5730fe0c 100644 --- a/ecmascript/builtins/builtins_object.h +++ b/ecmascript/builtins/builtins_object.h @@ -60,6 +60,8 @@ public: static JSTaggedValue IsSealed(EcmaRuntimeCallInfo *argv); // 19.1.2.14 Object.keys(O) static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); + // 20.1.2.22 Object.values(O) + static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); // 19.1.2.15 Object.preventExtensions(O) static JSTaggedValue PreventExtensions(EcmaRuntimeCallInfo *argv); // 19.1.2.17 Object.seal(O) diff --git a/ecmascript/builtins/builtins_promise.cpp b/ecmascript/builtins/builtins_promise.cpp index 996f2c802dcc3bc4ac454330af02fd4e14f8d3b2..14d68615ee92007d494ed07ad1dc2b3528ae5573 100644 --- a/ecmascript/builtins/builtins_promise.cpp +++ b/ecmascript/builtins/builtins_promise.cpp @@ -72,10 +72,11 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa auto resolveFunc = resolvingFunction->GetResolveFunction(); auto rejectFunc = resolvingFunction->GetRejectFunction(); JSHandle undefined = globalConst->GetHandledUndefined(); - const size_t argsLength = 2; // 2: «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]» - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, executor, undefined, undefined, argsLength); - info.SetCallArg(resolveFunc, rejectFunc); - JSTaggedValue taggedValue = JSFunction::Call(&info); + const int32_t argsLength = 2; // 2: «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]» + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, executor, undefined, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(resolveFunc, rejectFunc); + JSTaggedValue taggedValue = JSFunction::Call(info); JSHandle completionValue(thread, taggedValue); // 10. If completion is an abrupt completion, then @@ -85,10 +86,11 @@ JSTaggedValue BuiltinsPromise::PromiseConstructor([[maybe_unused]] EcmaRuntimeCa completionValue = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); JSHandle reject(thread, resolvingFunction->GetRejectFunction()); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); - runtimeInfo.SetCallArg(completionValue.GetTaggedValue()); - JSFunction::Call(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(completionValue.GetTaggedValue()); + JSFunction::Call(runtimeInfo); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -266,9 +268,10 @@ JSTaggedValue BuiltinsPromise::Resolve(EcmaRuntimeCallInfo *argv) // 7. ReturnIfAbrupt(resolveResult). JSHandle resolve(thread, promiseCapability->GetResolve()); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); - info.SetCallArg(xValue.GetTaggedValue()); - JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(xValue.GetTaggedValue()); + JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Return promiseCapability.[[Promise]]. @@ -302,9 +305,10 @@ JSTaggedValue BuiltinsPromise::Reject(EcmaRuntimeCallInfo *argv) JSHandle reason = GetCallArg(argv, 0); JSHandle reject(thread, promiseCapability->GetReject()); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); - info.SetCallArg(reason.GetTaggedValue()); - JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(reason.GetTaggedValue()); + JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 7. Return promiseCapability.[[Promise]]. @@ -333,10 +337,11 @@ JSTaggedValue BuiltinsPromise::Catch(EcmaRuntimeCallInfo *argv) JSHandle thenKey = globalConst->GetHandledPromiseThenString(); JSHandle reject = GetCallArg(argv, 0); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promise, undefined, 2); // 2: «undefined, onRejected» - info.SetCallArg(undefined.GetTaggedValue(), reject.GetTaggedValue()); - return JSFunction::Invoke(&info, thenKey); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(undefined.GetTaggedValue(), reject.GetTaggedValue()); + return JSFunction::Invoke(info, thenKey); } // 25.4.5.3 Promise.prototype.then ( onFulfilled , onRejected ) @@ -481,10 +486,11 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, JSArray::CreateArrayFromList(thread, JSHandle(thread, values->GetValue())); // 2. Let resolveResult be Call(resultCapability.[[Resolve]], undefined, «valuesArray»). JSHandle resCapaFunc(thread, capa->GetResolve()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resCapaFunc, undefined, undefined, 1); - info.SetCallArg(jsArrayValues.GetTaggedValue()); - JSTaggedValue resolveRes = JSFunction::Call(&info); + RETURN_COMPLETION_IF_ABRUPT(thread, next); + info->SetCallArg(jsArrayValues.GetTaggedValue()); + JSTaggedValue resolveRes = JSFunction::Call(info); // 3. ReturnIfAbrupt(resolveResult) JSHandle resolveAbrupt(thread, resolveRes); RETURN_COMPLETION_IF_ABRUPT(thread, resolveAbrupt); @@ -512,9 +518,10 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, values->SetValue(thread, valuesArray); // i. Let nextPromise be Invoke(constructor, "resolve", «‍nextValue»). JSHandle resolveKey = globalConst->GetHandledPromiseResolveString(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, ctor, undefined, 1); - info.SetCallArg(nextVal.GetTaggedValue()); - JSTaggedValue taggedNextPromise = JSFunction::Invoke(&info, resolveKey); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, ctor, undefined, 1); + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + info->SetCallArg(nextVal.GetTaggedValue()); + JSTaggedValue taggedNextPromise = JSFunction::Invoke(info, resolveKey); // j. ReturnIfAbrupt(nextPromise). JSHandle nextPromise(thread, taggedNextPromise); RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); @@ -537,11 +544,12 @@ JSHandle BuiltinsPromise::PerformPromiseAll(JSThread *thread, remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); // r. Let result be Invoke(nextPromise, "then", «‍resolveElement, resultCapability.[[Reject]]»). JSHandle thenKey = globalConst->GetHandledPromiseThenString(); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: «‍resolveElement, resultCapability.[[Reject]]» - runtimeInfo.SetCallArg(resoleveElement.GetTaggedValue(), capa->GetReject()); - JSTaggedValue taggedResult = JSFunction::Invoke(&runtimeInfo, thenKey); + RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); + runtimeInfo->SetCallArg(resoleveElement.GetTaggedValue(), capa->GetReject()); + JSTaggedValue taggedResult = JSFunction::Invoke(runtimeInfo, thenKey); JSHandle result(thread, taggedResult); // s. ReturnIfAbrupt(result). RETURN_COMPLETION_IF_ABRUPT(thread, result); @@ -597,9 +605,10 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, RETURN_COMPLETION_IF_ABRUPT(thread, nextValue); JSHandle resolveStr = globalConst->GetHandledPromiseResolveString(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, constructor, undefined, 1); - info.SetCallArg(nextValue.GetTaggedValue()); - JSTaggedValue result = JSFunction::Invoke(&info, resolveStr); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, constructor, undefined, 1); + RETURN_COMPLETION_IF_ABRUPT(thread, nextValue); + info->SetCallArg(nextValue.GetTaggedValue()); + JSTaggedValue result = JSFunction::Invoke(info, resolveStr); JSHandle nextPromise(thread, result); if (thread->HasPendingException()) { nextPromise = JSPromise::IfThrowGetThrowValue(thread); @@ -608,10 +617,11 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, JSHandle thenStr = globalConst->GetHandledPromiseThenString(); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: two args - runtimeInfo.SetCallArg(capability->GetResolve(), capability->GetReject()); - result = JSFunction::Invoke(&runtimeInfo, thenStr); + RETURN_COMPLETION_IF_ABRUPT(thread, nextPromise); + runtimeInfo->SetCallArg(capability->GetResolve(), capability->GetReject()); + result = JSFunction::Invoke(runtimeInfo, thenStr); JSHandle handleResult(thread, result); if (thread->HasPendingException()) { handleResult = JSPromise::IfThrowGetThrowValue(thread); @@ -619,4 +629,466 @@ JSHandle BuiltinsPromise::PerformPromiseRace(JSThread *thread, RETURN_COMPLETION_IF_ABRUPT(thread, handleResult); } } + +JSTaggedValue BuiltinsPromise::GetPromiseResolve(JSThread *thread, JSHandle promiseConstructor) +{ + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + // 1. Let promiseResolve be ? Get(promiseConstructor, "resolve"). + JSHandle resolveKey = globalConst->GetHandledPromiseResolveString(); + JSHandle promiseResolve = JSObject::GetProperty(thread, promiseConstructor, resolveKey).GetValue(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 2. If IsCallable(promiseResolve) is false, throw a TypeError exception. + if (!promiseResolve->IsCallable()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "promiseResolve is not callable", JSTaggedValue::Exception()); + } + // 3. Return promiseResolve. + return promiseResolve.GetTaggedValue(); +} + +// 27.2.4.3 Promise.any ( iterable ) +JSTaggedValue BuiltinsPromise::Any(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + BUILTINS_API_TRACE(argv->GetThread(), Promise, Any); + JSThread *thread = argv->GetThread(); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + // 1. Let C be the this value. + JSHandle thisValue = GetThis(argv); + // 2. Let promiseCapability be ? NewPromiseCapability(C). + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, thisValue); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, promiseCapability.GetTaggedValue()); + // 3. Let promiseResolve be GetPromiseResolve(C). + JSHandle promiseResolve(thread, BuiltinsPromise::GetPromiseResolve(thread, thisValue)); + // 4. IfAbruptRejectPromise(promiseResolve, promiseCapability). + if (thread->HasPendingException()) { + promiseResolve = JSPromise::IfThrowGetThrowValue(thread); + } + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, promiseResolve, promiseCapability); + // 5. Let iteratorRecord be GetIterator(iterable). + JSHandle iterable = GetCallArg(argv, 0); + JSHandle iterator = JSIterator::GetIterator(thread, iterable); + // 6. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + if (thread->HasPendingException()) { + iterator = JSPromise::IfThrowGetThrowValue(thread); + } + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promiseCapability); + // Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + JSHandle iteratorRecord = factory->NewPromiseIteratorRecord(iterator, false); + // 7. Let result be PerformPromiseAny(iteratorRecord, C, promiseCapability, promiseResolve). + JSHandle result = PerformPromiseAny(thread, iteratorRecord, thisValue, + promiseCapability, promiseResolve); + // 8. If result is an abrupt completion, then + if (result->IsThrow()) { + thread->ClearException(); + // a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + // b. IfAbruptRejectPromise(result, promiseCapability). + if (!iteratorRecord->GetDone()) { + JSHandle resultHandle = JSHandle::Cast(result); + JSHandle closeVal = JSIterator::IteratorClose(thread, iterator, resultHandle); + if (closeVal.GetTaggedValue().IsCompletionRecord()) { + result = JSHandle(closeVal); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + return result->GetValue(); + } + } + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + return result->GetValue(); + } + // 9. Return ? result. + return result->GetValue(); +} + +JSHandle BuiltinsPromise::PerformPromiseAny(JSThread *thread, + const JSHandle &iteratorRecord, + const JSHandle &constructor, + const JSHandle &resultCapability, + const JSHandle &promiseResolve) +{ + auto ecmaVm = thread->GetEcmaVM(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->GetFactory(); + // 1. Let errors be a new empty List. + JSHandle errors = factory->NewPromiseRecord(); + JSHandle emptyArray = factory->EmptyArray(); + errors->SetValue(thread, emptyArray); + // 2. Let remainingElementsCount be the Record { [[Value]]: 1 }. + JSHandle remainCnt = factory->NewPromiseRecord(); + remainCnt->SetValue(thread, JSTaggedNumber(1)); + // 3. Let index be 0. + uint32_t index = 0; + // 4. Repeat, + JSHandle iter(thread, iteratorRecord->GetIterator()); + JSMutableHandle next(thread, globalConst->GetUndefined()); + JSHandle undefined(globalConst->GetHandledUndefined()); + while (true) { + // a. Let next be IteratorStep(iteratorRecord). + next.Update(JSIterator::IteratorStep(thread, iter).GetTaggedValue()); + // b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + if (thread->HasPendingException()) { + iteratorRecord->SetDone(true); + next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); + } + // c. ReturnIfAbrupt(next). + RETURN_COMPLETION_IF_ABRUPT(thread, next); + // d. If next is false, then + if (next->IsFalse()) { + // i. Set iteratorRecord.[[Done]] to true. + iteratorRecord->SetDone(true); + // ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + // iii. If remainingElementsCount.[[Value]] is 0, then + if (remainCnt->GetValue().IsZero()) { + // 1. Let error be a newly created AggregateError object. + JSHandle error = factory->NewJSAggregateError(); + // 2. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, + // [[Enumerable]]: false, [[Writable]]: true, [[Value]]: ! CreateArrayFromList(errors) }). + JSHandle errorsKey(thread, globalConst->GetErrorsString()); + JSHandle errorsArray = + JSHandle::Cast(JSHandle(thread, errors->GetValue())); + JSHandle errorsValue(JSArray::CreateArrayFromList(thread, errorsArray)); + PropertyDescriptor msgDesc(thread, errorsValue, true, false, true); + JSHandle errorTagged = JSHandle::Cast(error); + JSTaggedValue::DefinePropertyOrThrow(thread, errorTagged, errorsKey, msgDesc); + // 3. Return ThrowCompletion(error). + JSHandle errorCompletion( + factory->NewCompletionRecord(CompletionRecordType::THROW, errorTagged)); + JSHandle errorResult = JSHandle::Cast(errorCompletion); + return errorResult; + } + // iv. Return resultCapability.[[Promise]]. + JSHandle resultCapabilityHandle(thread, resultCapability->GetPromise()); + JSHandle resRecord = factory->NewCompletionRecord( + CompletionRecordType::NORMAL, resultCapabilityHandle); + return resRecord; + } + // e. Let nextValue be IteratorValue(next). + JSHandle nextVal = JSIterator::IteratorValue(thread, next); + // f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true. + if (thread->HasPendingException()) { + iteratorRecord->SetDone(true); + nextVal = JSHandle(thread, thread->GetException()); + } + // g. ReturnIfAbrupt(nextValue). + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + // h. Append undefined to errors. + JSHandle errorsHandle(thread, errors->GetValue()); + JSHandle errorsArray = JSHandle::Cast(errorsHandle); + errorsArray = TaggedArray::SetCapacity(thread, errorsArray, index + 1); + errorsArray->Set(thread, index, JSTaggedValue::Undefined()); + errors->SetValue(thread, errorsArray); + // i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + EcmaRuntimeCallInfo *taggedInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, promiseResolve, constructor, undefined, 1); + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + taggedInfo->SetCallArg(nextVal.GetTaggedValue()); + JSTaggedValue taggedNextPromise = JSFunction::Call(taggedInfo); + JSHandle nextPromise(thread, taggedNextPromise); + if (thread->HasPendingException()) { + JSHandle promiseResult = JSPromise::IfThrowGetThrowValue(thread); + JSHandle completionRecord = + factory->NewCompletionRecord(CompletionRecordType::THROW, promiseResult); + return completionRecord; + } + // j. Let stepsRejected be the algorithm steps defined in Promise.any Reject Element Functions. + // k. Let lengthRejected be the number of non-optional parameters of the function definition in + // Promise.any Reject Element Functions. + // l. Let onRejected be CreateBuiltinFunction(stepsRejected, lengthRejected, "", « [[AlreadyCalled]], + // [[Index]], [[Errors]], [[Capability]], [[RemainingElements]] »). + JSHandle onRejected = factory->NewJSPromiseAnyRejectElementFunction(); + // m. Set onRejected.[[AlreadyCalled]] to false. + onRejected->SetAlreadyCalled(thread, JSTaggedValue::False()); + // n. Set onRejected.[[Index]] to index. + onRejected->SetIndex(index); + // o. Set onRejected.[[Errors]] to errors. + onRejected->SetErrors(thread, errors); + // p. Set onRejected.[[Capability]] to resultCapability. + onRejected->SetCapability(thread, resultCapability); + // q. Set onRejected.[[RemainingElements]] to remainingElementsCount. + onRejected->SetRemainingElements(thread, remainCnt); + // r. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1. + remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); + // s. Perform ? Invoke(nextPromise, "then", « resultCapability.[[Resolve]], onRejected »). + JSHandle thenKey = globalConst->GetHandledPromiseThenString(); + JSHandle resCapaFunc(thread, resultCapability->GetResolve()); + EcmaRuntimeCallInfo *invokeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: two args + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + invokeInfo->SetCallArg(resCapaFunc.GetTaggedValue(), onRejected.GetTaggedValue()); + JSFunction::Invoke(invokeInfo, thenKey); + if (thread->HasPendingException()) { + JSHandle taggedResult = JSPromise::IfThrowGetThrowValue(thread); + JSHandle completionRecord = + factory->NewCompletionRecord(CompletionRecordType::THROW, taggedResult); + return completionRecord; + } + // t. Set index to index + 1. + ++index; + } +} + +// 25.6.4.2 Promise.allSettled ( iterable ) +JSTaggedValue BuiltinsPromise::AllSettled(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + BUILTINS_API_TRACE(argv->GetThread(), Promise, AllSettled); + JSThread *thread = argv->GetThread(); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + // 1. Let C be the this value. + JSHandle thisValue = GetThis(argv); + // 2. Let promiseCapability be ? NewPromiseCapability(C). + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, thisValue); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, promiseCapability.GetTaggedValue()); + // 3. Let promiseResolve be Completion(GetPromiseResolve(C)). + JSHandle promiseResolve(thread, BuiltinsPromise::GetPromiseResolve(thread, thisValue)); + // 4. IfAbruptRejectPromise(promiseResolve, promiseCapability). + if (thread->HasPendingException()) { + promiseResolve = JSPromise::IfThrowGetThrowValue(thread); + } + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, promiseResolve, promiseCapability); + // 5. Let iteratorRecord be Completion(GetIterator(iterable)). + JSHandle iterable = GetCallArg(argv, 0); + JSHandle iterator = JSIterator::GetIterator(thread, iterable); + // 6. IfAbruptRejectPromise(iteratorRecord, promiseCapability). + if (thread->HasPendingException()) { + iterator = JSPromise::IfThrowGetThrowValue(thread); + } + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, iterator, promiseCapability); + // Let iteratorRecord be Record {[[iterator]]: iterator, [[done]]: false}. + JSHandle iteratorRecord = factory->NewPromiseIteratorRecord(iterator, false); + // 7. Let result be PerformPromiseAllSettled(iteratorRecord, C, promiseCapability). + JSHandle result = PerformPromiseAllSettled(thread, iteratorRecord, thisValue, + promiseCapability, promiseResolve); + // 8. If result is an abrupt completion, then + if (result->IsThrow()) { + thread->ClearException(); + // a. If iteratorRecord.[[Done]] is false, set result to IteratorClose(iteratorRecord, result). + if (!iteratorRecord->GetDone()) { + JSHandle resultHandle = JSHandle::Cast(result); + JSHandle closeVal = JSIterator::IteratorClose(thread, iterator, resultHandle); + if (closeVal.GetTaggedValue().IsCompletionRecord()) { + result = JSHandle(closeVal); + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + return result->GetValue(); + } + } + // b. IfAbruptRejectPromise(result, promiseCapability). + RETURN_REJECT_PROMISE_IF_ABRUPT(thread, result, promiseCapability); + return result->GetValue(); + } + // 7.Return Completion(result). + return result->GetValue(); +} + +JSHandle BuiltinsPromise::PerformPromiseAllSettled(JSThread *thread, + const JSHandle &iterRecord, + const JSHandle &constructor, + const JSHandle &resultCapa, + const JSHandle &promiseResolve) +{ + auto ecmaVm = thread->GetEcmaVM(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = ecmaVm->GetFactory(); + // 1. Let values be a new empty List. + JSHandle values = factory->NewPromiseRecord(); + JSHandle emptyArray = factory->EmptyArray(); + values->SetValue(thread, emptyArray); + // 2. Let remainingElementsCount be the Record { [[Value]]: 1 }. + JSHandle remainCnt = factory->NewPromiseRecord(); + remainCnt->SetValue(thread, JSTaggedNumber(1)); + // 3. Let index be 0. + uint32_t index = 0; + // 4. Repeat, + JSHandle iter(thread, iterRecord->GetIterator()); + JSMutableHandle next(thread, globalConst->GetUndefined()); + JSHandle undefined(globalConst->GetHandledUndefined()); + while (true) { + // a. Let next be IteratorStep(iteratorRecord). + next.Update(JSIterator::IteratorStep(thread, iter).GetTaggedValue()); + // b. If next is an abrupt completion, set iteratorRecord.[[Done]] to true. + if (thread->HasPendingException()) { + iterRecord->SetDone(true); + next.Update(JSPromise::IfThrowGetThrowValue(thread).GetTaggedValue()); + } + // c. ReturnIfAbrupt(next). + RETURN_COMPLETION_IF_ABRUPT(thread, next); + // d. If next is false, then + if (next->IsFalse()) { + // i. Set iteratorRecord.[[Done]] to true. + iterRecord->SetDone(true); + // ii. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + // iii. If remainingElementsCount.[[Value]] is 0, then + if (remainCnt->GetValue().IsZero()) { + // 1. Let valuesArray be ! CreateArrayFromList(values). + JSHandle taggedValues(thread, values->GetValue()); + JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, taggedValues); + // 2. Perform ? Call(resultCapability.[[Resolve]], undefined, « valuesArray »). + JSHandle resCapaFunc(thread, resultCapa->GetResolve()); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, resCapaFunc, undefined, undefined, 1); + RETURN_COMPLETION_IF_ABRUPT(thread, next); + info->SetCallArg(jsArrayValues.GetTaggedValue()); + JSFunction::Call(info); + if (thread->HasPendingException()) { + JSHandle throwValue = JSPromise::IfThrowGetThrowValue(thread); + JSHandle completionRecord = + factory->NewCompletionRecord(CompletionRecordType::THROW, throwValue); + return completionRecord; + } + } + // iv. Return resultCapability.[[Promise]]. + JSHandle resultCapabilityHandle(thread, resultCapa->GetPromise()); + JSHandle resRecord = factory->NewCompletionRecord( + CompletionRecordType::NORMAL, resultCapabilityHandle); + return resRecord; + } + // e. Let nextValue be IteratorValue(next). + JSHandle nextVal = JSIterator::IteratorValue(thread, next); + // f. If nextValue is an abrupt completion, set iteratorRecord.[[Done]] to true. + if (thread->HasPendingException()) { + iterRecord->SetDone(true); + nextVal = JSHandle(thread, thread->GetException()); + } + // g. ReturnIfAbrupt(nextValue). + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + // h. Append undefined to values. + JSHandle valuesHandle(thread, values->GetValue()); + JSHandle valuesArray = JSHandle::Cast(valuesHandle); + valuesArray = TaggedArray::SetCapacity(thread, valuesArray, index + 1); + valuesArray->Set(thread, index, JSTaggedValue::Undefined()); + values->SetValue(thread, valuesArray); + // i. Let nextPromise be ? Call(promiseResolve, constructor, « nextValue »). + EcmaRuntimeCallInfo *taggedInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, promiseResolve, constructor, undefined, 1); + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + taggedInfo->SetCallArg(nextVal.GetTaggedValue()); + JSTaggedValue taggedNextPromise = JSFunction::Call(taggedInfo); + JSHandle nextPromise(thread, taggedNextPromise); + if (thread->HasPendingException()) { + JSHandle promiseResult = JSPromise::IfThrowGetThrowValue(thread); + JSHandle completionRecord = + factory->NewCompletionRecord(CompletionRecordType::THROW, promiseResult); + return completionRecord; + } + // j. Let stepsFulfilled be the algorithm steps defined in Promise.allSettled Resolve Element Functions. + // k. Let lengthFulfilled be the number of non-optional parameters of the function definition in + // Promise.allSettled Resolve Element Functions. + // l. Let onFulfilled be CreateBuiltinFunction(stepsFulfilled, lengthFulfilled, "", + // « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »). + JSHandle onFulfilled = + factory->NewJSPromiseAllSettledResolveElementFunction(); + // m. Let alreadyCalled be the Record { [[Value]]: false }. + JSHandle alreadyCalled = factory->NewPromiseRecord(); + alreadyCalled->SetValue(thread, JSTaggedValue::False()); + // n. Set onFulfilled.[[AlreadyCalled]] to alreadyCalled. + onFulfilled->SetAlreadyCalled(thread, alreadyCalled); + // o. Set onFulfilled.[[Index]] to index. + onFulfilled->SetIndex(index); + // p. Set onFulfilled.[[Values]] to values. + onFulfilled->SetValues(thread, values); + // q. Set onFulfilled.[[Capability]] to resultCapability. + onFulfilled->SetCapability(thread, resultCapa); + // r. Set onFulfilled.[[RemainingElements]] to remainingElementsCount. + onFulfilled->SetRemainingElements(thread, remainCnt); + // s. Let stepsRejected be the algorithm steps defined in Promise.allSettled Reject Element Functions. + // t. Let lengthRejected be the number of non-optional parameters of the function definition in + // Promise.allSettled Reject Element Functions. + // u. Let onRejected be CreateBuiltinFunction(stepsRejected, lengthRejected, "", + // « [[AlreadyCalled]], [[Index]], [[Values]], [[Capability]], [[RemainingElements]] »). + JSHandle onRejected = + factory->NewJSPromiseAllSettledRejectElementFunction(); + // v. Set onRejected.[[AlreadyCalled]] to alreadyCalled. + onRejected->SetAlreadyCalled(thread, alreadyCalled); + // w. Set onRejected.[[Index]] to index. + onRejected->SetIndex(index); + // x. Set onRejected.[[Values]] to values. + onRejected->SetValues(thread, values); + // y. Set onRejected.[[Capability]] to resultCapability. + onRejected->SetCapability(thread, resultCapa); + // z. Set onRejected.[[RemainingElements]] to remainingElementsCount. + onRejected->SetRemainingElements(thread, remainCnt); + // aa. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] + 1. + remainCnt->SetValue(thread, ++JSTaggedNumber(remainCnt->GetValue())); + // ab. Perform ? Invoke(nextPromise, "then", « onFulfilled, onRejected »). + JSHandle thenKey = globalConst->GetHandledPromiseThenString(); + EcmaRuntimeCallInfo *invokeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, nextPromise, undefined, 2); // 2: two args + RETURN_COMPLETION_IF_ABRUPT(thread, nextVal); + invokeInfo->SetCallArg(onFulfilled.GetTaggedValue(), onRejected.GetTaggedValue()); + JSFunction::Invoke(invokeInfo, thenKey); + if (thread->HasPendingException()) { + JSHandle taggedResult = JSPromise::IfThrowGetThrowValue(thread); + JSHandle completionRecord = + factory->NewCompletionRecord(CompletionRecordType::THROW, taggedResult); + return completionRecord; + } + // ac. Set index to index + 1. + ++index; + } +} + +// 27.2.5.3 Promise.prototype.finally ( onFinally ) +JSTaggedValue BuiltinsPromise::Finally(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + BUILTINS_API_TRACE(argv->GetThread(), Promise, Finally); + JSThread *thread = argv->GetThread(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + ObjectFactory *factory = ecmaVm->GetFactory(); + // 1. Let promise be the this value. + // 2. If Type(promise) is not Object, throw a TypeError exception. + JSHandle promise = GetThis(argv); + if (!promise->IsECMAObject()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "Reject: this value is not object", JSTaggedValue::Exception()); + } + // 3. Let C be SpeciesConstructor(promise, %Promise%). + // 4. Assert: IsConstructor(C) is true. + JSHandle onFinally = BuiltinsBase::GetCallArg(argv, 0); + JSHandle ctor = JSHandle::Cast(promise); + JSHandle promiseFunc = JSHandle::Cast(env->GetPromiseFunction()); + JSHandle constructor = JSObject::SpeciesConstructor(thread, ctor, promiseFunc); + ASSERT_PRINT(constructor->IsConstructor(), "constructor is not constructor"); + JSHandle thenFinally; + JSHandle catchFinally; + // 5. If IsCallable(onFinally) is false, then + if (!onFinally->IsCallable()) { + // a. Let thenFinally be onFinally. + // b. Let catchFinally be onFinally. + thenFinally = onFinally; + catchFinally = onFinally; + // 6. Else, + } else { + // a. Let stepsThenFinally be the algorithm steps defined in Then Finally Functions. + // b. Let thenFinally be CreateBuiltinFunction(stepsThenFinally, « [[Constructor]], [[OnFinally]] »). + JSHandle thenFinallyFun = + factory->NewJSPromiseThenFinallyFunction(); + // c. Set thenFinally.[[Constructor]] to C. + // d. Set thenFinally.[[OnFinally]] to onFinally. + thenFinallyFun->SetConstructor(thread, constructor); + thenFinallyFun->SetOnFinally(thread, onFinally); + thenFinally = JSHandle(thenFinallyFun); + // e. Let stepsCatchFinally be the algorithm steps defined in Catch Finally Functions. + // f. Let catchFinally be CreateBuiltinFunction(stepsCatchFinally, « [[Constructor]], [[OnFinally]] »). + JSHandle catchFinallyFun = + factory->NewJSPromiseCatchFinallyFunction(); + // g. Set catchFinally.[[Constructor]] to C. + // h. Set catchFinally.[[OnFinally]] to onFinally. + catchFinallyFun->SetConstructor(thread, constructor); + catchFinallyFun->SetOnFinally(thread, onFinally); + catchFinally = JSHandle(catchFinallyFun); + } + // 7. return invoke(promise, "then", <>) + JSHandle thenKey(globalConst->GetHandledPromiseThenString()); + JSHandle undefined(globalConst->GetHandledUndefined()); + EcmaRuntimeCallInfo *invokeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promise, undefined, 2); // 2: two args + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + invokeInfo->SetCallArg(thenFinally.GetTaggedValue(), catchFinally.GetTaggedValue()); + return JSFunction::Invoke(invokeInfo, thenKey); +} } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_promise.h b/ecmascript/builtins/builtins_promise.h index 0fbc9a9cf83be6a4871b546c523b8b8fa07681e7..e3234801f9e55c911063db1a6fb68a4540e0248a 100644 --- a/ecmascript/builtins/builtins_promise.h +++ b/ecmascript/builtins/builtins_promise.h @@ -48,6 +48,14 @@ public: const JSHandle &onRejected, const JSHandle &capability); + static JSTaggedValue Any(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue AllSettled(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue Finally(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue GetPromiseResolve(JSThread *thread, JSHandle promiseConstructor); + private: static JSHandle PerformPromiseAll(JSThread *thread, const JSHandle &itRecord, @@ -58,6 +66,18 @@ private: const JSHandle &iteratorRecord, const JSHandle &capability, const JSHandle &constructor); + + static JSHandle PerformPromiseAllSettled(JSThread *thread, + const JSHandle &iterRecord, + const JSHandle &constructor, + const JSHandle &resultCapa, + const JSHandle &promiseResolve); + + static JSHandle PerformPromiseAny(JSThread *thread, + const JSHandle &iteratorRecord, + const JSHandle &constructor, + const JSHandle &resultCapability, + const JSHandle &promiseResolve); }; } // namespace panda::ecmascript::builtins #endif // ECMASCRIPT_BUILTINS_BUILTINS_PROMISE_H \ No newline at end of file diff --git a/ecmascript/builtins/builtins_promise_handler.cpp b/ecmascript/builtins/builtins_promise_handler.cpp index 8695acbde63927c4b0638e7b0f52ea6d088f769c..a841bfe2bd29a01dfffe74b1c96e2d588538916d 100644 --- a/ecmascript/builtins/builtins_promise_handler.cpp +++ b/ecmascript/builtins/builtins_promise_handler.cpp @@ -205,10 +205,11 @@ JSTaggedValue BuiltinsPromiseHandler::ResolveElementFunction(EcmaRuntimeCallInfo // b. Return Call(promiseCapability.[[Resolve]], undefined, «valuesArray»). JSHandle capaResolve(thread, capa->GetResolve()); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, capaResolve, undefined, undefined, 1); - info.SetCallArg(jsArrayValues.GetTaggedValue()); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(jsArrayValues.GetTaggedValue()); + return JSFunction::Call(info); } // 11. Return undefined. return JSTaggedValue::Undefined(); @@ -233,4 +234,322 @@ JSTaggedValue BuiltinsPromiseHandler::AsyncAwaitRejected(EcmaRuntimeCallInfo *ar JSHandle func(GetConstructor(argv)); return JSAsyncAwaitStatusFunction::AsyncFunctionAwaitRejected(argv->GetThread(), func, reason).GetTaggedValue(); } + +JSTaggedValue BuiltinsPromiseHandler::valueThunkFunction(EcmaRuntimeCallInfo *argv) +{ + JSHandle valueThunk = + JSHandle::Cast(GetConstructor(argv)); + return valueThunk->GetResult(); +} + +JSTaggedValue BuiltinsPromiseHandler::throwerFunction(EcmaRuntimeCallInfo *argv) +{ + JSThread *thread = argv->GetThread(); + JSHandle thrower = + JSHandle::Cast(GetConstructor(argv)); + JSTaggedValue undefined = thread->GlobalConstants()->GetUndefined(); + THROW_NEW_ERROR_AND_RETURN_VALUE(thread, thrower->GetResult(), undefined); +} + +JSTaggedValue BuiltinsPromiseHandler::ThenFinally(EcmaRuntimeCallInfo *argv) +{ + // 1. Let F be the active function object. + JSThread *thread = argv->GetThread(); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle thenFinally(GetConstructor(argv)); + JSHandle value = BuiltinsBase::GetCallArg(argv, 0); + // 2. Let onFinally be F.[[OnFinally]]. + // 3. Assert: IsCallable(onFinally) is true. + JSHandle onFinally(thread, thenFinally->GetOnFinally()); + ASSERT_PRINT(onFinally->IsCallable(), "onFinally is not callable"); + // 4. Let result be ? Call(onFinally, undefined). + JSHandle undefined = globalConst->GetHandledUndefined(); + EcmaRuntimeCallInfo *taggedInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, onFinally, undefined, undefined, 0); + JSTaggedValue result = JSFunction::Call(taggedInfo); + JSHandle resultHandle(thread, result); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 5. Let C be F.[[Constructor]]. + // 6. Assert: IsConstructor(C) is true. + JSHandle thenFinallyConstructor(thread, thenFinally->GetConstructor()); + ASSERT_PRINT(thenFinallyConstructor->IsConstructor(), "thenFinallyConstructor is not constructor"); + // 7. Let promise be ? PromiseResolve(C, result). + JSHandle promiseHandle = + BuiltinsPromiseHandler::PromiseResolve(thread, thenFinallyConstructor, resultHandle); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 8. Let valueThunk be equivalent to a function that returns value. + JSHandle valueThunk = + factory->NewJSPromiseValueThunkFunction(); + valueThunk->SetResult(thread, value); + JSHandle thenKey(globalConst->GetHandledPromiseThenString()); + EcmaRuntimeCallInfo *invokeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promiseHandle, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + invokeInfo->SetCallArg(valueThunk.GetTaggedValue()); + // 9. Return ? Invoke(promise, "then", « valueThunk »). + return JSFunction::Invoke(invokeInfo, thenKey); +} + +JSTaggedValue BuiltinsPromiseHandler::CatchFinally(EcmaRuntimeCallInfo *argv) +{ + // 1. Let F be the active function object. + JSThread *thread = argv->GetThread(); + auto ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle catchFinally(GetConstructor(argv)); + // 2. Let onFinally be F.[[OnFinally]]. + // 3. Assert: IsCallable(onFinally) is true. + JSHandle onFinally(thread, catchFinally->GetOnFinally()); + ASSERT_PRINT(onFinally->IsCallable(), "thenOnFinally is not callable"); + // 4. Let result be ? Call(onFinally, undefined). + JSHandle undefined = globalConst->GetHandledUndefined(); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, onFinally, undefined, undefined, 0); + JSTaggedValue result = JSFunction::Call(info); + JSHandle resultHandle(thread, result); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 5. Let C be F.[[Constructor]]. + // 6. Assert: IsConstructor(C) is true. + JSHandle catchFinallyConstructor(thread, catchFinally->GetConstructor()); + ASSERT_PRINT(catchFinallyConstructor->IsConstructor(), "catchFinallyConstructor is not constructor"); + // 7. Let promise be ? PromiseResolve(C, result). + JSHandle promiseHandle = + BuiltinsPromiseHandler::PromiseResolve(thread, catchFinallyConstructor, resultHandle); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 8. Let thrower be equivalent to a function that throws reason. + JSHandle reason = BuiltinsBase::GetCallArg(argv, 0); + JSHandle thenKey(globalConst->GetHandledPromiseThenString()); + JSHandle thrower = + factory->NewJSPromiseThrowerFunction(); + thrower->SetResult(thread, reason); + EcmaRuntimeCallInfo *invokeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promiseHandle, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + invokeInfo->SetCallArg(thrower.GetTaggedValue()); + // 9. Return ? Invoke(promise, "then", « thrower »). + return JSFunction::Invoke(invokeInfo, thenKey); +} + +JSHandle BuiltinsPromiseHandler::PromiseResolve(JSThread *thread, + const JSHandle &constructor, + const JSHandle &xValue) +{ + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + // 1. Assert: Type(C) is Object. + ASSERT_PRINT(constructor->IsECMAObject(), "PromiseResolve : is not callable"); + // 2. If IsPromise(x) is true, then + if (xValue->IsJSPromise()) { + // a. Let xConstructor be ? Get(x, "constructor"). + JSHandle ctorKey(globalConst->GetHandledConstructorString()); + JSHandle ctorValue = JSObject::GetProperty(thread, xValue, ctorKey).GetValue(); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ctorValue); + // b. If SameValue(xConstructor, C) is true, return x. + if (JSTaggedValue::SameValue(ctorValue, constructor)) { + return xValue; + } + } + // 3. Let promiseCapability be ? NewPromiseCapability(C). + // 4. ReturnIfAbrupt(promiseCapability) + JSHandle promiseCapability = JSPromise::NewPromiseCapability(thread, constructor); + JSHandle promiseCapaHandle = JSHandle::Cast(promiseCapability); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, promiseCapaHandle); + // 6. Let resolveResult be Call(promiseCapability.[[Resolve]], undefined, «x»). + // 7. ReturnIfAbrupt(resolveResult). + JSHandle resolve(thread, promiseCapability->GetResolve()); + JSHandle undefined(globalConst->GetHandledUndefined()); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, promiseCapaHandle); + info->SetCallArg(xValue.GetTaggedValue()); + JSTaggedValue resolveResult = JSFunction::Call(info); + JSHandle resolveResultHandle(thread, resolveResult); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, resolveResultHandle); + // 8. Return promiseCapability.[[Promise]]. + JSHandle promise(thread, promiseCapability->GetPromise()); + return promise; +} + +JSTaggedValue BuiltinsPromiseHandler::AllSettledResolveElementFunction(EcmaRuntimeCallInfo *argv) +{ + // 1. Let F be the active function object. + JSThread *thread = argv->GetThread(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle resolveElement = + JSHandle::Cast((GetConstructor(argv))); + // 2. Let alreadyCalled be F.[[AlreadyCalled]]. + JSHandle alreadyCalled = + JSHandle::Cast(JSHandle(thread, resolveElement->GetAlreadyCalled())); + // 3. If alreadyCalled.[[Value]] is true, return undefined. + if (alreadyCalled->GetValue().IsTrue()) { + return JSTaggedValue::Undefined(); + } + // 4. Set alreadyCalled.[[Value]] to true. + alreadyCalled->SetValue(thread, JSTaggedValue::True()); + // 5. Let index be F.[[Index]]. + uint32_t index = resolveElement->GetIndex(); + // 6. Let values be F.[[Values]]. + JSHandle values = + JSHandle::Cast(JSHandle(thread, resolveElement->GetValues())); + // 7. Let promiseCapability be F.[[Capability]]. + JSHandle capa = + JSHandle::Cast(JSHandle(thread, resolveElement->GetCapability())); + // 8. Let remainingElementsCount be F.[[RemainingElements]]. + JSHandle remainCnt = + JSHandle::Cast(JSHandle(thread, resolveElement->GetRemainingElements())); + // 9. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). + JSHandle proto = env->GetObjectFunctionPrototype(); + JSHandle obj = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(proto); + // 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "fulfilled"). + JSHandle statusKey = globalConst->GetHandledPromiseStatusString(); + JSHandle fulfilledKey = globalConst->GetHandledPromiseFulfilledString(); + JSObject::CreateDataPropertyOrThrow(thread, obj, statusKey, fulfilledKey); + // 11. Perform ! CreateDataPropertyOrThrow(obj, "value", x). + JSHandle valueKey = globalConst->GetHandledValueString(); + JSHandle xValue = GetCallArg(argv, 0); + JSObject::CreateDataPropertyOrThrow(thread, obj, valueKey, xValue); + // 12. Set values[index] to obj. + JSHandle arrayValues = + JSHandle::Cast(JSHandle(thread, values->GetValue())); + arrayValues->Set(thread, index, obj.GetTaggedValue()); + // 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + // 14. If remainingElementsCount.[[Value]] is 0, then + if (remainCnt->GetValue().IsZero()) { + // a. Let valuesArray be CreateArrayFromList(values). + JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, arrayValues); + // b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »). + JSHandle capaResolve(thread, capa->GetResolve()); + JSHandle undefined(globalConst->GetHandledUndefined()); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, capaResolve, undefined, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(jsArrayValues.GetTaggedValue()); + return JSFunction::Call(info); + } + // 15. Return undefined. + return JSTaggedValue::Undefined(); +} + +JSTaggedValue BuiltinsPromiseHandler::AllSettledRejectElementFunction(EcmaRuntimeCallInfo *argv) +{ + // 1. Let F be the active function object. + JSThread *thread = argv->GetThread(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle rejectElement = + JSHandle::Cast((GetConstructor(argv))); + // 2. Let alreadyCalled be F.[[AlreadyCalled]]. + JSHandle alreadyCalled = + JSHandle::Cast(JSHandle(thread, rejectElement->GetAlreadyCalled())); + // 3. If alreadyCalled.[[Value]] is true, return undefined. + if (alreadyCalled->GetValue().IsTrue()) { + return JSTaggedValue::Undefined(); + } + // 4. Set alreadyCalled.[[Value]] to true. + alreadyCalled->SetValue(thread, JSTaggedValue::True()); + // 5. Let index be F.[[Index]]. + uint32_t index = rejectElement->GetIndex(); + // 6. Let values be F.[[Values]]. + JSHandle values = + JSHandle::Cast(JSHandle(thread, rejectElement->GetValues())); + // 7. Let promiseCapability be F.[[Capability]]. + [[maybe_unused]] JSHandle capa = + JSHandle::Cast(JSHandle(thread, rejectElement->GetCapability())); + // 8. Let remainingElementsCount be F.[[RemainingElements]]. + [[maybe_unused]] JSHandle remainCnt = + JSHandle::Cast(JSHandle(thread, rejectElement->GetRemainingElements())); + // 9. Let obj be ! OrdinaryObjectCreate(%Object.prototype%). + JSHandle proto = env->GetObjectFunctionPrototype(); + JSHandle obj = thread->GetEcmaVM()->GetFactory()->OrdinaryNewJSObjectCreate(proto); + // 10. Perform ! CreateDataPropertyOrThrow(obj, "status", "rejected"). + JSHandle statusKey = globalConst->GetHandledPromiseStatusString(); + JSHandle rejectedKey = globalConst->GetHandledPromiseRejectedString(); + JSObject::CreateDataPropertyOrThrow(thread, obj, statusKey, rejectedKey); + // 11. Perform ! CreateDataPropertyOrThrow(obj, "reason", x). + JSHandle xReason = GetCallArg(argv, 0); + JSHandle reasonKey = globalConst->GetHandledPromiseReasonString(); + JSObject::CreateDataPropertyOrThrow(thread, obj, reasonKey, xReason); + // 12. Set values[index] to obj. + JSHandle arrayValues = + JSHandle::Cast(JSHandle(thread, values->GetValue())); + arrayValues->Set(thread, index, obj.GetTaggedValue()); + // 13. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + // 14. If remainingElementsCount.[[Value]] is 0, then + if (remainCnt->GetValue().IsZero()) { + // a. Let valuesArray be CreateArrayFromList(values). + JSHandle jsArrayValues = JSArray::CreateArrayFromList(thread, arrayValues); + // b. Return ? Call(promiseCapability.[[Resolve]], undefined, « valuesArray »). + JSHandle capaResolve(thread, capa->GetResolve()); + JSHandle undefined(globalConst->GetHandledUndefined()); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, capaResolve, undefined, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(jsArrayValues.GetTaggedValue()); + return JSFunction::Call(info); + } + // 15. Return undefined. + return JSTaggedValue::Undefined(); +} + +JSTaggedValue BuiltinsPromiseHandler::AnyRejectElementFunction(EcmaRuntimeCallInfo *argv) +{ + // 1. Let F be the active function object. + JSThread *thread = argv->GetThread(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle rejectElement = + JSHandle::Cast((GetConstructor(argv))); + // 2. If F.[[AlreadyCalled]] is true, return undefined. + JSTaggedValue alreadyCalled = rejectElement->GetAlreadyCalled(); + if (alreadyCalled.IsTrue()) { + return JSTaggedValue::Undefined(); + } + // 3. Set F.[[AlreadyCalled]] to true. + rejectElement->SetAlreadyCalled(thread, JSTaggedValue::True()); + // 4. Let index be F.[[Index]]. + uint32_t index = rejectElement->GetIndex(); + // 5. Let errors be F.[[Errors]]. + [[maybe_unused]] JSHandle errors = + JSHandle::Cast(JSHandle(thread, rejectElement->GetErrors())); + // 6. Let promiseCapability be F.[[Capability]]. + [[maybe_unused]] JSHandle capa = + JSHandle::Cast(JSHandle(thread, rejectElement->GetCapability())); + // 7. Let remainingElementsCount be F.[[RemainingElements]]. + JSHandle remainCnt = + JSHandle::Cast(JSHandle(thread, rejectElement->GetRemainingElements())); + // 8. Set errors[index] to x. + JSHandle xValue = GetCallArg(argv, 0); + JSHandle errorsArray = + JSHandle::Cast(JSHandle(thread, errors->GetValue())); + errorsArray->Set(thread, index, xValue.GetTaggedValue()); + // 9. Set remainingElementsCount.[[Value]] to remainingElementsCount.[[Value]] - 1. + remainCnt->SetValue(thread, --JSTaggedNumber(remainCnt->GetValue())); + // 10. If remainingElementsCount.[[Value]] is 0, then + if (remainCnt->GetValue().IsZero()) { + // a. Let error be a newly created AggregateError object. + JSHandle error = factory->NewJSAggregateError(); + // b. Perform ! DefinePropertyOrThrow(error, "errors", PropertyDescriptor { [[Configurable]]: true, + // [[Enumerable]]: false, [[Writable]]: true, [[Value]]: ! CreateArrayFromList(errors) }). + JSHandle errorsKey(thread, globalConst->GetErrorsString()); + JSHandle errorsValue(JSArray::CreateArrayFromList(thread, errorsArray)); + PropertyDescriptor msgDesc(thread, errorsValue, true, false, true); + JSHandle errorTagged = JSHandle::Cast(error); + JSTaggedValue::DefinePropertyOrThrow(thread, errorTagged, errorsKey, msgDesc); + // c. Return ? Call(promiseCapability.[[Reject]], undefined, « error »). + JSHandle capaReject(thread, capa->GetReject()); + JSHandle undefined(globalConst->GetHandledUndefined()); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, capaReject, undefined, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(error.GetTaggedValue()); + return JSFunction::Call(info); + } + // 11. Return undefined. + return JSTaggedValue::Undefined(); +} } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_promise_handler.h b/ecmascript/builtins/builtins_promise_handler.h index dabab82f93a3fcd78ada8bcf31a50383b3880284..49d310d72382c938e5b18cc99013926e950b7847 100644 --- a/ecmascript/builtins/builtins_promise_handler.h +++ b/ecmascript/builtins/builtins_promise_handler.h @@ -38,6 +38,23 @@ public: // es6 25.4.4.1.2 Promise.all Resolve Element Functions static JSTaggedValue ResolveElementFunction(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue ThenFinally(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue CatchFinally(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue valueThunkFunction(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue throwerFunction(EcmaRuntimeCallInfo *argv); + + static JSHandle PromiseResolve(JSThread *thread, const JSHandle &constructor, + const JSHandle &xValue); + + static JSTaggedValue AllSettledResolveElementFunction(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue AllSettledRejectElementFunction(EcmaRuntimeCallInfo *argv); + + static JSTaggedValue AnyRejectElementFunction(EcmaRuntimeCallInfo *argv); }; } // namespace panda::ecmascript::builtins diff --git a/ecmascript/builtins/builtins_promise_job.cpp b/ecmascript/builtins/builtins_promise_job.cpp index ec449ff46abb239adb0427047be2b61f9b9f66ae..f14b5d508b5037bc3175bc8721a412d214343d8c 100644 --- a/ecmascript/builtins/builtins_promise_job.cpp +++ b/ecmascript/builtins/builtins_promise_job.cpp @@ -42,7 +42,7 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) // 3. Let handler be reaction.[[Handler]]. JSHandle handler(thread, reaction->GetHandler()); JSMutableHandle call(thread, capability->GetResolve()); - const size_t argsLength = 1; + const int32_t argsLength = 1; JSHandle undefined = globalConst->GetHandledUndefined(); if (handler->IsString()) { // 4. If handler is "Identity", let handlerResult be NormalCompletion(argument). @@ -55,10 +55,11 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) } } else { // 6. Else, let handlerResult be Call(handler, undefined, «argument»). - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, handler, undefined, undefined, argsLength); - info.SetCallArg(argument.GetTaggedValue()); - JSTaggedValue taggedValue = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argument.GetTaggedValue()); + JSTaggedValue taggedValue = JSFunction::Call(info); argument.Update(taggedValue); // 7. If handlerResult is an abrupt completion, then // a. Let status be Call(promiseCapability.[[Reject]], undefined, «handlerResult.[[value]]»). @@ -71,10 +72,11 @@ JSTaggedValue BuiltinsPromiseJob::PromiseReactionJob(EcmaRuntimeCallInfo *argv) } } // 8. Let status be Call(promiseCapability.[[Resolve]], undefined, «handlerResult.[[value]]»). - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, call, undefined, undefined, argsLength); - runtimeInfo.SetCallArg(argument.GetTaggedValue()); - return JSFunction::Call(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(argument.GetTaggedValue()); + return JSFunction::Call(runtimeInfo); } JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) @@ -92,11 +94,12 @@ JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo JSHandle then = GetCallArg(argv, BuiltinsBase::ArgsPosition::THIRD); // 2. Let thenCallResult be Call(then, thenable, «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]»). - const size_t argsLength = 2; // 2: «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]» + const int32_t argsLength = 2; // 2: «resolvingFunctions.[[Resolve]], resolvingFunctions.[[Reject]]» JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, then, thenable, undefined, argsLength); - info.SetCallArg(resolvingFunctions->GetResolveFunction(), resolvingFunctions->GetRejectFunction()); - JSTaggedValue result = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, then, thenable, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(resolvingFunctions->GetResolveFunction(), resolvingFunctions->GetRejectFunction()); + JSTaggedValue result = JSFunction::Call(info); JSHandle thenResult(thread, result); // 3. If thenCallResult is an abrupt completion, // a. Let status be Call(resolvingFunctions.[[Reject]], undefined, «thenCallResult.[[value]]»). @@ -105,10 +108,11 @@ JSTaggedValue BuiltinsPromiseJob::PromiseResolveThenableJob(EcmaRuntimeCallInfo thenResult = JSPromise::IfThrowGetThrowValue(thread); thread->ClearException(); JSHandle reject(thread, resolvingFunctions->GetRejectFunction()); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); - runtimeInfo.SetCallArg(thenResult.GetTaggedValue()); - return JSFunction::Call(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(thenResult.GetTaggedValue()); + return JSFunction::Call(runtimeInfo); } // 4. NextJob Completion(thenCallResult). return result; diff --git a/ecmascript/builtins/builtins_reflect.cpp b/ecmascript/builtins/builtins_reflect.cpp index cc592bdd2eac703dbd9c3df4e6e6d4b3a18fae90..79545ab5710b4c0347604a5f333ad40d899b8a3d 100644 --- a/ecmascript/builtins/builtins_reflect.cpp +++ b/ecmascript/builtins/builtins_reflect.cpp @@ -39,12 +39,13 @@ JSTaggedValue BuiltinsReflect::ReflectApply(EcmaRuntimeCallInfo *argv) // 3. Perform PrepareForTailCall(). // 4. Return ? Call(target, thisArgument, args). - const size_t argsLength = args->GetLength(); + const int32_t argsLength = static_cast(args->GetLength()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, target, thisArgument, undefined, argsLength); - info.SetCallArg(argsLength, args); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, args); + return JSFunction::Call(info); } // ecma 26.1.2 Reflect.construct (target, argumentsList [ , newTarget]) @@ -73,11 +74,12 @@ JSTaggedValue BuiltinsReflect::ReflectConstruct(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle args = JSHandle::Cast(argOrAbrupt); // 5. Return ? Construct(target, args, newTarget). - const size_t argsLength = args->GetLength(); + const int32_t argsLength = static_cast(args->GetLength()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, target, undefined, newTarget, argsLength); - info.SetCallArg(argsLength, args); - return JSFunction::Construct(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, target, undefined, newTarget, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, args); + return JSFunction::Construct(info); } // ecma 26.1.3 Reflect.defineProperty (target, propertyKey, attributes) diff --git a/ecmascript/builtins/builtins_regexp.cpp b/ecmascript/builtins/builtins_regexp.cpp index de0950b7f262596bf4259821dadb2642a86a258f..4165dd4597003ff4a7a2c7edea9de144c6303469 100644 --- a/ecmascript/builtins/builtins_regexp.cpp +++ b/ecmascript/builtins/builtins_regexp.cpp @@ -65,7 +65,7 @@ JSTaggedValue BuiltinsRegExp::RegExpConstructor(EcmaRuntimeCallInfo *argv) // 4.b If patternIsRegExp is true and flags is undefined if (patternIsRegExp && flags->IsUndefined()) { // 4.b.i Let patternConstructor be Get(pattern, "constructor"). - JSTaggedValue patternConstructor = FastRuntimeStub::FastGetPropertyByName( + JSTaggedValue patternConstructor = FastRuntimeStub::FastGetPropertyByValue( thread, pattern.GetTaggedValue(), constructorString.GetTaggedValue()); // 4.b.ii ReturnIfAbrupt(patternConstructor). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -384,7 +384,7 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle global = globalConst->GetHandledGlobalString(); JSTaggedValue globalValue = - FastRuntimeStub::FastGetPropertyByName(thread, thisObj.GetTaggedValue(), global.GetTaggedValue()); + FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), global.GetTaggedValue()); // 6. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -422,15 +422,15 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). JSHandle unicode = globalConst->GetHandledUnicodeString(); JSTaggedValue uincodeValue = - FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), unicode.GetTaggedValue()); + FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), unicode.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool fullUnicode = uincodeValue.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). JSHandle lastIndexString(globalConst->GetHandledLastIndexString()); - FastRuntimeStub::FastSetProperty(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue(), - JSTaggedValue(0), true); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue(), + JSTaggedValue(0)); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // e. Let A be ArrayCreate(0). @@ -462,8 +462,9 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // iv. Else result is not null, // 1. Let matchStr be ToString(Get(result, "0")). JSHandle zeroString = globalConst->GetHandledZeroString(); - JSHandle matchStr( - thread, FastRuntimeStub::FastGetProperty(thread, result.GetTaggedValue(), zeroString.GetTaggedValue())); + JSTaggedValue matchVal = FastRuntimeStub::FastGetPropertyByValue( + thread, result.GetTaggedValue(), zeroString.GetTaggedValue()); + JSHandle matchStr(thread, matchVal); JSHandle matchString = JSTaggedValue::ToString(thread, matchStr); // 2. ReturnIfAbrupt(matchStr). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -473,9 +474,9 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // 5. If matchStr is the empty String, then if (JSTaggedValue::ToString(thread, matchValue)->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - JSHandle lastIndexHandle( - thread, - FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue())); + JSTaggedValue lastIndex = FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), + lastIndexString.GetTaggedValue()); + JSHandle lastIndexHandle(thread, lastIndex); JSTaggedNumber thisIndex = JSTaggedValue::ToLength(thread, lastIndexHandle); // b. ReturnIfAbrupt(thisIndex). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -483,8 +484,8 @@ JSTaggedValue BuiltinsRegExp::Match(EcmaRuntimeCallInfo *argv) // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). JSTaggedValue nextIndex = JSTaggedValue(AdvanceStringIndex(string, thisIndex.GetNumber(), fullUnicode)); - FastRuntimeStub::FastSetProperty(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue(), - nextIndex, true); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndexString.GetTaggedValue(), + nextIndex); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -528,10 +529,11 @@ JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) // 6. Let matcher be ? Construct(C, « R, flags »). JSHandle undefined = globalConstants->GetHandledUndefined(); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 2); // 2: two args - runtimeInfo.SetCallArg(thisObj.GetTaggedValue(), flagsStrHandle.GetTaggedValue()); - JSTaggedValue taggedMatcher = JSFunction::Construct(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(thisObj.GetTaggedValue(), flagsStrHandle.GetTaggedValue()); + JSTaggedValue taggedMatcher = JSFunction::Construct(runtimeInfo); JSHandle matcherHandle(thread, taggedMatcher); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -542,8 +544,8 @@ JSTaggedValue BuiltinsRegExp::MatchAll(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 8. Perform ? Set(matcher, "lastIndex", lastIndex, true). - FastRuntimeStub::FastSetProperty(thread, matcherHandle.GetTaggedValue(), lastIndexString.GetTaggedValue(), - thisLastIndex, true); + FastRuntimeStub::FastSetPropertyByValue(thread, matcherHandle.GetTaggedValue(), lastIndexString.GetTaggedValue(), + thisLastIndex); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9. If flags contains "g", let global be true. @@ -586,7 +588,7 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandle(thisIndex.GetInt()); } else { @@ -651,8 +653,8 @@ JSTaggedValue BuiltinsRegExp::RegExpReplaceFast(JSThread *thread, JSHandleGetEcmaVM()->GetFactory(); JSHandle global = globalConst->GetHandledGlobalString(); JSTaggedValue globalValue = - FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), global.GetTaggedValue()); + FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), global.GetTaggedValue()); // 9. ReturnIfAbrupt(global). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool isGlobal = globalValue.ToBoolean(); @@ -737,14 +739,14 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // a. Let fullUnicode be ToBoolean(Get(rx, "unicode")). JSHandle unicode = globalConst->GetHandledUnicodeString(); JSTaggedValue fullUnicodeTag = - FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), unicode.GetTaggedValue()); + FastRuntimeStub::FastGetPropertyByValue(thread, thisObj.GetTaggedValue(), unicode.GetTaggedValue()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); fullUnicode = fullUnicodeTag.ToBoolean(); // b. ReturnIfAbrupt(fullUnicode). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // c. Let setStatus be Set(rx, "lastIndex", 0, true). - FastRuntimeStub::FastSetProperty(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue(), JSTaggedValue(0), - true); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), + lastIndex.GetTaggedValue(), JSTaggedValue(0)); // d. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -814,16 +816,18 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) break; } // iii. Else, 1. Let matchStr be ToString(Get(result, "0")). - JSHandle getMatch( - thread, FastRuntimeStub::FastGetProperty(thread, execResult.GetTaggedValue(), matchedStr.GetTaggedValue())); + JSTaggedValue getMatchVal = FastRuntimeStub::FastGetPropertyByValue( + thread, execResult.GetTaggedValue(), matchedStr.GetTaggedValue()); + JSHandle getMatch(thread, getMatchVal); JSHandle matchString = JSTaggedValue::ToString(thread, getMatch); // 2. ReturnIfAbrupt(matchStr). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 3. If matchStr is the empty String, then if (matchString->GetLength() == 0) { // a. Let thisIndex be ToLength(Get(rx, "lastIndex")). - JSHandle thisIndexHandle( - thread, FastRuntimeStub::FastGetProperty(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue())); + JSTaggedValue thisIndexVal = FastRuntimeStub::FastGetPropertyByValue( + thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue()); + JSHandle thisIndexHandle(thread, thisIndexVal); uint32_t thisIndex = 0; if (thisIndexHandle->IsInt()) { thisIndex = static_cast(thisIndexHandle->GetInt()); @@ -836,8 +840,8 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) uint32_t nextIndex = AdvanceStringIndex(inputStr, thisIndex, fullUnicode); nextIndexHandle.Update(JSTaggedValue(nextIndex)); // d. Let setStatus be Set(rx, "lastIndex", nextIndex, true). - FastRuntimeStub::FastSetProperty(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue(), - nextIndexHandle.GetTaggedValue(), true); + FastRuntimeStub::FastSetPropertyByValue(thread, thisObj.GetTaggedValue(), lastIndex.GetTaggedValue(), + nextIndexHandle.GetTaggedValue()); // e. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -855,8 +859,8 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) resultValues.Update(FastRuntimeStub::FastGetPropertyByIndex(thread, resultsList.GetTaggedValue(), i)); // a. Let nCaptures be ToLength(Get(result, "length")). JSHandle lengthHandle = globalConst->GetHandledLengthString(); - ncapturesHandle.Update( - FastRuntimeStub::FastGetProperty(thread, resultValues.GetTaggedValue(), lengthHandle.GetTaggedValue())); + ncapturesHandle.Update(FastRuntimeStub::FastGetPropertyByValue( + thread, resultValues.GetTaggedValue(), lengthHandle.GetTaggedValue())); uint32_t ncaptures = JSTaggedValue::ToUint32(thread, ncapturesHandle); // b. ReturnIfAbrupt(nCaptures). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -872,8 +876,8 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) uint32_t matchLength = matchString->GetLength(); // g. Let position be ToInteger(Get(result, "index")). JSHandle resultIndex = globalConst->GetHandledIndexString(); - JSTaggedValue positionTag = - FastRuntimeStub::FastGetPropertyByName(thread, resultValues.GetTaggedValue(), resultIndex.GetTaggedValue()); + JSTaggedValue positionTag = FastRuntimeStub::FastGetPropertyByValue( + thread, resultValues.GetTaggedValue(), resultIndex.GetTaggedValue()); JSHandle positionHandle(thread, positionTag); uint32_t position = 0; if (positionHandle->IsInt()) { @@ -910,10 +914,23 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) // v. Let n be n+1 ++index; } + + // j. Let namedCaptures be ? Get(result, "groups"). + JSHandle groupsKey = globalConst->GetHandledGroupsString(); + JSTaggedValue named = + FastRuntimeStub::FastGetPropertyByValue(thread, resultValues.GetTaggedValue(), groupsKey.GetTaggedValue()); + JSHandle namedCaptures(thread, named); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // m. If functionalReplace is true, then CString replacement; + int emptyArrLength = 0; + if (namedCaptures->IsUndefined()) { + emptyArrLength = 3; // 3: «matched, pos, and string» + } else { + emptyArrLength = 4; // 4: «matched, pos, string, and groups» + } JSHandle replacerArgs = - factory->NewTaggedArray(3 + capturesList->GetLength()); // 3: «matched, pos, and string» + factory->NewTaggedArray(emptyArrLength + capturesList->GetLength()); if (functionalReplace) { // i. Let replacerArgs be «matched». replacerArgs->Set(thread, 0, getMatchString.GetTaggedValue()); @@ -926,13 +943,17 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) } replacerArgs->Set(thread, index + 1, JSTaggedValue(position)); replacerArgs->Set(thread, index + 2, inputStr.GetTaggedValue()); // 2: position of string + if (!namedCaptures->IsUndefined()) { + replacerArgs->Set(thread, index + 3, namedCaptures.GetTaggedValue()); // 3: position of groups + } // iv. Let replValue be Call(replaceValue, undefined, replacerArgs). - const size_t argsLength = replacerArgs->GetLength(); + const int32_t argsLength = static_cast(replacerArgs->GetLength()); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, inputReplaceValue, undefined, undefined, argsLength); - info.SetCallArg(argsLength, replacerArgs); - JSTaggedValue replaceResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, replacerArgs); + JSTaggedValue replaceResult = JSFunction::Call(info); JSHandle replValue(thread, replaceResult); // v. Let replacement be ToString(replValue). JSHandle replacementString = JSTaggedValue::ToString(thread, replValue); @@ -941,8 +962,14 @@ JSTaggedValue BuiltinsRegExp::Replace(EcmaRuntimeCallInfo *argv) replacement = ConvertToString(*replacementString, StringConvertedUsage::LOGICOPERATION); } else { // n. Else, + if (!namedCaptures->IsUndefined()) { + JSHandle namedCapturesObj = JSTaggedValue::ToObject(thread, namedCaptures); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + namedCaptures = JSHandle::Cast(namedCapturesObj); + } JSHandle replacementHandle( - thread, BuiltinsString::GetSubstitution(thread, matchString, srcString, position, capturesList, + thread, BuiltinsString::GetSubstitution(thread, matchString, srcString, + position, capturesList, namedCaptures, replaceValueHandle)); replacement = ConvertToString(EcmaString::Cast(replacementHandle->GetTaggedObject()), StringConvertedUsage::LOGICOPERATION); @@ -1127,10 +1154,11 @@ JSTaggedValue BuiltinsRegExp::Split(EcmaRuntimeCallInfo *argv) // 13. Let splitter be Construct(C, «rx, newFlags»). JSHandle globalObject(thread, thread->GetEcmaVM()->GetGlobalEnv()->GetGlobalObject()); JSHandle undefined = globalConstants->GetHandledUndefined(); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 2); // 2: two args - runtimeInfo.SetCallArg(thisObj.GetTaggedValue(), newFlagsHandle.GetTaggedValue()); - JSTaggedValue taggedSplitter = JSFunction::Construct(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(thisObj.GetTaggedValue(), newFlagsHandle.GetTaggedValue()); + JSTaggedValue taggedSplitter = JSFunction::Construct(runtimeInfo); // 14. ReturnIfAbrupt(splitter). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -1347,7 +1375,6 @@ bool BuiltinsRegExp::GetFlagsInternal(JSThread *thread, const JSHandle(regexpObj->GetOriginalFlags().GetInt()); return flags & mask; } - // 21.2.5.2.2 JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle ®exp, const JSHandle &inputStr, bool useCache) @@ -1358,7 +1385,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle const GlobalEnvConstants *globalConst = thread->GlobalConstants(); JSHandle lastIndexHandle = globalConst->GetHandledLastIndexString(); JSTaggedValue result = - FastRuntimeStub::FastGetProperty(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue()); + FastRuntimeStub::FastGetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue()); int32_t lastIndex = 0; if (result.IsInt()) { lastIndex = result.GetInt(); @@ -1370,12 +1397,12 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle } JSHandle globalHandle = globalConst->GetHandledGlobalString(); - bool global = - FastRuntimeStub::FastGetProperty(thread, regexp.GetTaggedValue(), globalHandle.GetTaggedValue()).ToBoolean(); + bool global = FastRuntimeStub::FastGetPropertyByValue( + thread, regexp.GetTaggedValue(), globalHandle.GetTaggedValue()).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle stickyHandle = globalConst->GetHandledStickyString(); - bool sticky = - FastRuntimeStub::FastGetProperty(thread, regexp.GetTaggedValue(), stickyHandle.GetTaggedValue()).ToBoolean(); + bool sticky = FastRuntimeStub::FastGetPropertyByValue( + thread, regexp.GetTaggedValue(), stickyHandle.GetTaggedValue()).ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!global && !sticky) { lastIndex = 0; @@ -1386,20 +1413,7 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle JSMutableHandle flags(thread, regexpObj->GetOriginalFlags()); JSHandle cacheTable(thread->GetEcmaVM()->GetRegExpCache()); - if (lastIndex == 0 && useCache) { - JSTaggedValue cacheResult = - cacheTable->FindCachedResult(thread, pattern, flags, inputStr, RegExpExecResultCache::EXEC_TYPE, regexp); - if (cacheResult != JSTaggedValue::Undefined()) { - return cacheResult; - } - } - uint32_t length = static_cast(inputStr->GetTaggedObject())->GetLength(); - uint8_t flagsBits = static_cast(regexpObj->GetOriginalFlags().GetInt()); - JSHandle flagsValue(thread, FlagsBitsToString(thread, flagsBits)); - JSHandle flagsStr = JSTaggedValue::ToString(thread, flagsValue); - JSHandle uString(globalConst->GetHandledUString()); - [[maybe_unused]] bool fullUnicode = base::StringHelper::Contains(*flagsStr, *uString); if (lastIndex > static_cast(length)) { FastRuntimeStub::FastSetPropertyByValue(thread, regexp.GetTaggedValue(), lastIndexHandle.GetTaggedValue(), JSTaggedValue(0)); @@ -1454,6 +1468,17 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle // 27. Perform CreateDataProperty(A, "0", matched_substr). JSHandle zeroValue(matchResult.captures_[0].second); JSObject::CreateDataProperty(thread, results, 0, zeroValue); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + + JSHandle groupName(thread, regexpObj->GetGroupName()); + JSMutableHandle groups(thread, JSTaggedValue::Undefined()); + if (!groupName->IsUndefined()) { + JSHandle nullHandle(thread, JSTaggedValue::Null()); + JSHandle nullObj = factory->OrdinaryNewJSObjectCreate(nullHandle); + groups.Update(nullObj.GetTaggedValue()); + } + JSHandle groupsKey = globalConst->GetHandledGroupsString(); + JSObject::CreateDataProperty(thread, results, groupsKey, groups); // 28. For each integer i such that i > 0 and i <= n for (uint32_t i = 1; i < capturesSize; i++) { // a. Let capture_i be ith element of r's captures List @@ -1465,6 +1490,14 @@ JSTaggedValue BuiltinsRegExp::RegExpBuiltinExec(JSThread *thread, const JSHandle } JSHandle iValue(thread, capturedValue); JSObject::CreateDataProperty(thread, results, i, iValue); + if (!groupName->IsUndefined()) { + JSHandle groupObject = JSHandle::Cast(groups); + TaggedArray *groupArray = TaggedArray::Cast(regexpObj->GetGroupName().GetTaggedObject()); + if (groupArray->GetLength() > i - 1) { + JSHandle skey(thread, groupArray->Get(i - 1)); + JSObject::CreateDataProperty(thread, groupObject, skey, iValue); + } + } } if (lastIndex == 0 && useCache) { RegExpExecResultCache::AddResultInCache(thread, cacheTable, pattern, flags, inputStr, @@ -1488,16 +1521,18 @@ JSTaggedValue BuiltinsRegExp::RegExpExec(JSThread *thread, const JSHandleGlobalConstants(); JSHandle execHandle = globalConst->GetHandledExecString(); - JSHandle exec( - thread, FastRuntimeStub::FastGetProperty(thread, regexp.GetTaggedValue(), execHandle.GetTaggedValue())); + JSTaggedValue execVal = FastRuntimeStub::FastGetPropertyByValue(thread, regexp.GetTaggedValue(), + execHandle.GetTaggedValue()); + JSHandle exec(thread, execVal); // 4. ReturnIfAbrupt(exec). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 5. If IsCallable(exec) is true, then if (exec->IsCallable()) { JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, exec, regexp, undefined, 1); - info.SetCallArg(inputStr.GetTaggedValue()); - JSTaggedValue result = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, exec, regexp, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(inputStr.GetTaggedValue()); + JSTaggedValue result = JSFunction::Call(info); // b. ReturnIfAbrupt(result). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!result.IsECMAObject() && !result.IsNull()) { @@ -1652,7 +1687,8 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< Chunk chunk(thread->GetNativeAreaAllocator()); RegExpParser parser = RegExpParser(&chunk); RegExpParserCache *regExpParserCache = thread->GetEcmaVM()->GetRegExpParserCache(); - auto getCache = regExpParserCache->GetCache(*patternStrHandle, flagsBits); + CVector groupName; + auto getCache = regExpParserCache->GetCache(*patternStrHandle, flagsBits, groupName); if (getCache.first == JSTaggedValue::Hole()) { parser.Init(const_cast(reinterpret_cast(patternStdStr.c_str())), patternStdStr.size(), flagsBits); @@ -1662,26 +1698,35 @@ JSTaggedValue BuiltinsRegExp::RegExpInitialize(JSThread *thread, const JSHandle< factory->GetJSError(base::ErrorType::SYNTAX_ERROR, parser.GetErrorMsg().c_str()); THROW_NEW_ERROR_AND_RETURN_VALUE(thread, syntaxError.GetTaggedValue(), JSTaggedValue::Exception()); } + groupName = parser.GetGroupNames(); } JSHandle regexp(thread, JSRegExp::Cast(obj->GetTaggedObject())); // 11. Set the value of obj’s [[OriginalSource]] internal slot to P. regexp->SetOriginalSource(thread, patternStrHandle.GetTaggedValue()); // 12. Set the value of obj’s [[OriginalFlags]] internal slot to F. regexp->SetOriginalFlags(thread, JSTaggedValue(flagsBits)); + if (!groupName.empty()) { + JSHandle taggedArray = factory->NewTaggedArray(groupName.size()); + for (size_t i = 0; i < groupName.size(); ++i) { + JSHandle flagsKey(factory->NewFromStdString(groupName[i].c_str())); + taggedArray->Set(thread, i, flagsKey); + } + regexp->SetGroupName(thread, taggedArray); + } // 13. Set obj’s [[RegExpMatcher]] internal slot. if (getCache.first == JSTaggedValue::Hole()) { auto bufferSize = parser.GetOriginBufferSize(); auto buffer = parser.GetOriginBuffer(); factory->NewJSRegExpByteCodeData(regexp, buffer, bufferSize); - regExpParserCache->SetCache(*patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(), bufferSize); + regExpParserCache->SetCache(*patternStrHandle, flagsBits, regexp->GetByteCodeBuffer(), bufferSize, groupName); } else { regexp->SetByteCodeBuffer(thread, getCache.first); regexp->SetLength(static_cast(getCache.second)); } // 14. Let setStatus be Set(obj, "lastIndex", 0, true). JSHandle lastIndexString = thread->GlobalConstants()->GetHandledLastIndexString(); - FastRuntimeStub::FastSetProperty(thread, obj.GetTaggedValue(), lastIndexString.GetTaggedValue(), JSTaggedValue(0), - true); + FastRuntimeStub::FastSetPropertyByValue(thread, obj.GetTaggedValue(), + lastIndexString.GetTaggedValue(), JSTaggedValue(0)); // 15. ReturnIfAbrupt(setStatus). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 16. Return obj. diff --git a/ecmascript/builtins/builtins_set.cpp b/ecmascript/builtins/builtins_set.cpp index 16857ae6804a814368b35e35b60ccc420a656e12..2ce5970bac86da46bbb92f814e097f86e4f65311 100644 --- a/ecmascript/builtins/builtins_set.cpp +++ b/ecmascript/builtins/builtins_set.cpp @@ -82,13 +82,14 @@ JSTaggedValue BuiltinsSet::SetConstructor(EcmaRuntimeCallInfo *argv) // ReturnIfAbrupt(nextValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, adder, setHandle, undefined, 1); - info.SetCallArg(nextValue.GetTaggedValue()); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, adder, setHandle, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); + info->SetCallArg(nextValue.GetTaggedValue()); if (nextValue->IsArray(thread)) { auto prop = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); - info.SetCallArg(prop.GetTaggedValue()); + info->SetCallArg(prop.GetTaggedValue()); } - JSFunction::Call(&info); + JSFunction::Call(info); // Let status be Call(adder, set, «nextValue.[[value]]»). if (thread->HasPendingException()) { return JSIterator::IteratorCloseAndReturn(thread, iter); @@ -199,7 +200,7 @@ JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) // 6.Let entries be the List that is the value of S’s [[SetData]] internal slot. JSMutableHandle hashSet(thread, set->GetLinkedSet()); - const size_t argsLength = 3; + const int32_t argsLength = 3; int index = 0; int totalElements = hashSet->NumberOfElements() + hashSet->NumberOfDeletedElements(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); @@ -208,11 +209,12 @@ JSTaggedValue BuiltinsSet::ForEach([[maybe_unused]] EcmaRuntimeCallInfo *argv) JSHandle key(thread, hashSet->GetKey(index++)); // a. If e is not empty, then if (!key->IsHole()) { - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo( + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo( thread, func, thisArg, undefined, argsLength); - info.SetCallArg(key.GetTaggedValue(), key.GetTaggedValue(), set.GetTaggedValue()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(key.GetTaggedValue(), key.GetTaggedValue(), set.GetTaggedValue()); // i. Let funcResult be Call(callbackfn, T, «e, e, S»). - JSTaggedValue ret = JSFunction::Call(&info); // 3: three args + JSTaggedValue ret = JSFunction::Call(info); // 3: three args // ii. ReturnIfAbrupt(funcResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // Maybe add or delete diff --git a/ecmascript/builtins/builtins_sharedarraybuffer.cpp b/ecmascript/builtins/builtins_sharedarraybuffer.cpp index 347f0a5c4c5212164103b1740251fa7db921516e..9c56348560c516b5485a56c48b35af5b020e9818 100644 --- a/ecmascript/builtins/builtins_sharedarraybuffer.cpp +++ b/ecmascript/builtins/builtins_sharedarraybuffer.cpp @@ -219,10 +219,11 @@ JSTaggedValue BuiltinsSharedArrayBuffer::Slice(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 15. Let new be Construct(ctor, «newLen»). JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(newLen)); - JSTaggedValue taggedNewArrBuf = JSFunction::Construct(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(JSTaggedValue(newLen)); + JSTaggedValue taggedNewArrBuf = JSFunction::Construct(info); JSHandle newArrBuf(thread, taggedNewArrBuf); // 16. ReturnIfAbrupt(new). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/builtins/builtins_string.cpp b/ecmascript/builtins/builtins_string.cpp index 7eca5cf8fb2e18487a3c33088c97435ed24a55a4..7e01a1db8aa8650f37592955c78cb514e0e441b8 100644 --- a/ecmascript/builtins/builtins_string.cpp +++ b/ecmascript/builtins/builtins_string.cpp @@ -86,7 +86,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t argLength = argv->GetArgsNumber(); + int32_t argLength = argv->GetArgsNumber(); if (argLength == 0) { return factory->GetEmptyString().GetTaggedValue(); } @@ -100,7 +100,7 @@ JSTaggedValue BuiltinsString::FromCharCode(EcmaRuntimeCallInfo *argv) std::u16string u16str = base::StringHelper::Utf16ToU16String(&codePointValue, 1); CVector valueTable; valueTable.reserve(argLength - 1); - for (uint32_t i = 1; i < argLength; i++) { + for (int32_t i = 1; i < argLength; i++) { JSHandle nextCp = BuiltinsString::GetCallArg(argv, i); uint16_t nextCv = JSTaggedValue::ToUint16(thread, nextCp); valueTable.emplace_back(nextCv); @@ -123,13 +123,13 @@ JSTaggedValue BuiltinsString::FromCodePoint(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - uint32_t argLength = argv->GetArgsNumber(); + int32_t argLength = argv->GetArgsNumber(); if (argLength == 0) { return factory->GetEmptyString().GetTaggedValue(); } std::u16string u16str; - uint32_t u16strSize = argLength; - for (uint32_t i = 0; i < argLength; i++) { + int32_t u16strSize = argLength; + for (int32_t i = 0; i < argLength; i++) { JSHandle nextCpTag = BuiltinsString::GetCallArg(argv, i); JSTaggedNumber nextCpVal = JSTaggedValue::ToNumber(thread, nextCpTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -198,7 +198,7 @@ JSTaggedValue BuiltinsString::Raw(EcmaRuntimeCallInfo *argv) } std::u16string u16str; - int argc = static_cast(argv->GetArgsNumber()) - 1; + int argc = argv->GetArgsNumber() - 1; bool canBeCompress = true; for (int i = 0, argsI = 1; i < length; ++i, ++argsI) { // Let nextSeg be ToString(Get(raw, nextKey)). @@ -331,7 +331,7 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) JSHandle thisHandle = JSTaggedValue::ToString(thread, thisTag); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t thisLen = thisHandle->GetLength(); - uint32_t argLength = argv->GetArgsNumber(); + int32_t argLength = argv->GetArgsNumber(); if (argLength == 0) { return thisHandle.GetTaggedValue(); } @@ -344,7 +344,7 @@ JSTaggedValue BuiltinsString::Concat(EcmaRuntimeCallInfo *argv) } else { u16strThis = base::StringHelper::Utf8ToU16String(thisHandle->GetDataUtf8(), thisLen); } - for (uint32_t i = 0; i < argLength; i++) { + for (int32_t i = 0; i < argLength; i++) { JSHandle nextTag = BuiltinsString::GetCallArg(argv, i); JSHandle nextHandle = JSTaggedValue::ToString(thread, nextTag); uint32_t nextLen = nextHandle->GetLength(); @@ -621,10 +621,11 @@ JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!matcher->IsUndefined()) { ASSERT(matcher->IsJSFunction()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, matcher, regexp, undefined, 1); - info.SetCallArg(thisTag.GetTaggedValue()); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisTag.GetTaggedValue()); + return JSFunction::Call(info); } } } @@ -633,9 +634,10 @@ JSTaggedValue BuiltinsString::Match(EcmaRuntimeCallInfo *argv) JSHandle undifinedHandle = globalConst->GetHandledUndefined(); JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undifinedHandle)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, rx, undefined, 1); - info.SetCallArg(thisVal.GetTaggedValue()); - return JSFunction::Invoke(&info, matchTag); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, rx, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisVal.GetTaggedValue()); + return JSFunction::Invoke(info, matchTag); } JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) @@ -662,8 +664,8 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) // b. If isRegExp is true, then if (isJSRegExp) { // i. Let flags be ? Get(searchValue, "flags"). - JSHandle flagsKey(factory->NewFromASCII("flags")); - JSHandle flags = JSObject::GetProperty(thread, regexp, flagsKey).GetValue(); + JSHandle flagsString(globalConst->GetHandledFlagsString()); + JSHandle flags = JSObject::GetProperty(thread, regexp, flagsString).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // ii. Perform ? RequireObjectCoercible(flags). JSTaggedValue::RequireObjectCoercible(thread, flags); @@ -687,10 +689,11 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) if (!matcher->IsUndefined()) { ASSERT(matcher->IsJSFunction()); // i. i. Return ? Call(matcher, regexp, « O »). - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, matcher, regexp, undefined, 1); - info.SetCallArg(thisTag.GetTaggedValue()); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisTag.GetTaggedValue()); + return JSFunction::Call(info); } } } @@ -700,9 +703,10 @@ JSTaggedValue BuiltinsString::MatchAll(EcmaRuntimeCallInfo *argv) // 4. Let rx be ? RegExpCreate(regexp, "g"). JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, gvalue)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, rx, undefined, 1); - info.SetCallArg(thisVal.GetTaggedValue()); - return JSFunction::Invoke(&info, matchAllTag); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, rx, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisVal.GetTaggedValue()); + return JSFunction::Invoke(info, matchAllTag); } // 21.1.3.12 @@ -778,7 +782,7 @@ JSTaggedValue BuiltinsString::PadStart(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle lengthTag = GetCallArg(argv, 0); int32_t intMaxLength = JSTaggedValue::ToInt32(thread, lengthTag); - int32_t stringLength = thisHandle->GetLength(); + int32_t stringLength = static_cast(thisHandle->GetLength()); if (intMaxLength < stringLength) { return thisHandle.GetTaggedValue(); } @@ -808,7 +812,7 @@ JSTaggedValue BuiltinsString::PadStart(EcmaRuntimeCallInfo *argv) } int32_t fillLen = intMaxLength - stringLength; - int32_t len = stringBuilder.length(); + int32_t len = static_cast(stringBuilder.length()); std::u16string fiString; for (int32_t i = 0; i < fillLen; ++i) { if (len == 0) { @@ -835,7 +839,7 @@ JSTaggedValue BuiltinsString::PadEnd(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle lengthTag = GetCallArg(argv, 0); int32_t intMaxLength = JSTaggedValue::ToInt32(thread, lengthTag); - int32_t stringLength = thisHandle->GetLength(); + int32_t stringLength = static_cast(thisHandle->GetLength()); if (intMaxLength < stringLength) { return thisHandle.GetTaggedValue(); } @@ -865,7 +869,7 @@ JSTaggedValue BuiltinsString::PadEnd(EcmaRuntimeCallInfo *argv) } int32_t fillLen = intMaxLength - stringLength; - int32_t len = stringBuilder.length(); + int32_t len = static_cast(stringBuilder.length()); std::u16string fiString; for (int32_t i = 0; i < fillLen; ++i) { if (len == 0) { @@ -960,12 +964,13 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) // If replacer is not undefined, then if (!replaceMethod->IsUndefined()) { // Return Call(replacer, searchValue, «O, replaceValue»). - const size_t argsLength = 2; + const int32_t argsLength = 2; JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, replaceMethod, searchTag, undefined, argsLength); - info.SetCallArg(thisTag.GetTaggedValue(), replaceTag.GetTaggedValue()); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisTag.GetTaggedValue(), replaceTag.GetTaggedValue()); + return JSFunction::Call(info); } } @@ -992,74 +997,204 @@ JSTaggedValue BuiltinsString::Replace(EcmaRuntimeCallInfo *argv) if (pos == -1) { return thisString.GetTaggedValue(); } - + JSHandle undefined = globalConst->GetHandledUndefined(); JSMutableHandle replHandle(thread, factory->GetEmptyString().GetTaggedValue()); // If functionalReplace is true, then if (replaceTag->IsCallable()) { // Let replValue be Call(replaceValue, undefined,«matched, pos, and string»). - const size_t argsLength = 3; // 3: «matched, pos, and string» - JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + const int32_t argsLength = 3; // 3: «matched, pos, and string» + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, replaceTag, undefined, undefined, argsLength); - info.SetCallArg(searchString.GetTaggedValue(), JSTaggedValue(pos), thisString.GetTaggedValue()); - JSTaggedValue replStrDeocodeValue = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(searchString.GetTaggedValue(), JSTaggedValue(pos), thisString.GetTaggedValue()); + JSTaggedValue replStrDeocodeValue = JSFunction::Call(info); replHandle.Update(replStrDeocodeValue); } else { // Let captures be an empty List. - JSHandle capturesList = factory->NewTaggedArray(0); + JSHandle capturesList = factory->EmptyArray(); ASSERT_PRINT(replaceTag->IsString(), "replace must be string"); JSHandle replacement(thread, replaceTag->GetTaggedObject()); // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) - replHandle.Update(GetSubstitution(thread, searchString, thisString, pos, capturesList, replacement)); + replHandle.Update(GetSubstitution(thread, searchString, thisString, pos, capturesList, undefined, replacement)); } JSHandle realReplaceStr = JSTaggedValue::ToString(thread, replHandle); // Let tailPos be pos + the number of code units in matched. int32_t tailPos = pos + static_cast(searchString->GetLength()); - // Let newString be the String formed by concatenating the first pos code units of string, replStr, and the trailing - // substring of string starting at index tailPos. If pos is 0, the first element of the concatenation will be the + // Let newString be the String formed by concatenating the first pos code units of string, + // replStr, and the trailing + // substring of string starting at index tailPos. If pos is 0, + // the first element of the concatenation will be the // empty String. // Return newString. JSHandle prefixString(thread, EcmaString::FastSubString(thisString, 0, pos, ecmaVm)); JSHandle suffixString( thread, EcmaString::FastSubString(thisString, tailPos, thisString->GetLength() - tailPos, ecmaVm)); - std::u16string stringBuilder; - bool canBeCompress = true; - if (prefixString->IsUtf16()) { - const uint16_t *data = prefixString->GetDataUtf16(); - stringBuilder += base::StringHelper::Utf16ToU16String(data, prefixString->GetLength()); - canBeCompress = false; - } else { - const uint8_t *data = prefixString->GetDataUtf8(); - stringBuilder += base::StringHelper::Utf8ToU16String(data, prefixString->GetLength()); - } + JSHandle tempString = factory->ConcatFromString(prefixString, realReplaceStr); + return factory->ConcatFromString(tempString, suffixString).GetTaggedValue(); +} - if (realReplaceStr->IsUtf16()) { - const uint16_t *data = realReplaceStr->GetDataUtf16(); - stringBuilder += base::StringHelper::Utf16ToU16String(data, realReplaceStr->GetLength()); - canBeCompress = false; - } else { - const uint8_t *data = realReplaceStr->GetDataUtf8(); - stringBuilder += base::StringHelper::Utf8ToU16String(data, realReplaceStr->GetLength()); +JSTaggedValue BuiltinsString::ReplaceAll(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, String, ReplaceAll); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisTag = JSTaggedValue::RequireObjectCoercible(thread, BuiltinsString::GetThis(argv)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + + auto ecmaVm = thread->GetEcmaVM(); + JSHandle env = ecmaVm->GetGlobalEnv(); + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + JSHandle searchTag = BuiltinsString::GetCallArg(argv, 0); + JSHandle replaceTag = BuiltinsString::GetCallArg(argv, 1); + + ObjectFactory *factory = ecmaVm->GetFactory(); + + if (!searchTag->IsUndefined() && !searchTag->IsNull()) { + // a. Let isRegExp be ? IsRegExp(searchValue). + bool isJSRegExp = JSObject::IsRegExp(thread, searchTag); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // b. If isRegExp is true, then + if (isJSRegExp) { + // i. Let flags be ? Get(searchValue, "flags"). + JSHandle flagsString(globalConst->GetHandledFlagsString()); + JSHandle flags = JSObject::GetProperty(thread, searchTag, flagsString).GetValue(); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // ii. Perform ? RequireObjectCoercible(flags). + JSTaggedValue::RequireObjectCoercible(thread, flags); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // iii. If ? ToString(flags) does not contain "g", throw a TypeError exception. + JSHandle flagString = JSTaggedValue::ToString(thread, flags); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle gString(globalConst->GetHandledGString()); + int32_t pos = flagString->IndexOf(*gString); + if (pos == -1) { + THROW_TYPE_ERROR_AND_RETURN(thread, + "string.prototype.replaceAll called with a non-global RegExp argument", + JSTaggedValue::Exception()); + } + } + // c. Let replacer be ? GetMethod(searchValue, @@replace). + JSHandle replaceKey = env->GetReplaceSymbol(); + JSHandle replaceMethod = JSObject::GetMethod(thread, searchTag, replaceKey); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // d. If replacer is not undefined, then + if (!replaceMethod->IsUndefined()) { + // i. Return ? Call(replacer, searchValue, «O, replaceValue»). + const size_t argsLength = 2; + JSHandle undefined = globalConst->GetHandledUndefined(); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, replaceMethod, searchTag, undefined, argsLength); + info->SetCallArg(thisTag.GetTaggedValue(), replaceTag.GetTaggedValue()); + return JSFunction::Call(info); + } } - if (suffixString->IsUtf16()) { - const uint16_t *data = suffixString->GetDataUtf16(); - stringBuilder += base::StringHelper::Utf16ToU16String(data, suffixString->GetLength()); - canBeCompress = false; - } else { - const uint8_t *data = suffixString->GetDataUtf8(); - stringBuilder += base::StringHelper::Utf8ToU16String(data, suffixString->GetLength()); + // 3. Let string be ? ToString(O). + JSHandle thisString = JSTaggedValue::ToString(thread, thisTag); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 4. Let searchString be ? ToString(searchValue). + JSHandle searchString = JSTaggedValue::ToString(thread, searchTag); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + // 5. Let functionalReplace be IsCallable(replaceValue). + // 6. If functionalReplace is false, then + if (!replaceTag->IsCallable()) { + // a. Set replaceValue to ? ToString(replaceValue). + replaceTag = JSHandle(JSTaggedValue::ToString(thread, replaceTag)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + } + + // 7. Let searchLength be the length of searchString. + // 8. Let advanceBy be max(1, searchLength). + int32_t searchLength = static_cast(searchString->GetLength()); + int32_t advanceBy = std::max(1, searchLength); + // 9. Let matchPositions be a new empty List. + std::u16string stringBuilder; + std::u16string stringPrefixString; + std::u16string stringRealReplaceStr; + std::u16string stringSuffixString; + // 10. Let position be ! StringIndexOf(string, searchString, 0). + int32_t pos = thisString->IndexOf(*searchString); + int32_t endOfLastMatch = 0; + bool canBeCompress = true; + JSHandle undefined = globalConst->GetHandledUndefined(); + JSMutableHandle replHandle(thread, factory->GetEmptyString().GetTaggedValue()); + while (pos != -1) { + // If functionalReplace is true, then + if (replaceTag->IsCallable()) { + // Let replValue be Call(replaceValue, undefined,«matched, pos, and string»). + const int32_t argsLength = 3; // 3: «matched, pos, and string» + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, replaceTag, undefined, undefined, argsLength); + info->SetCallArg(searchString.GetTaggedValue(), JSTaggedValue(pos), thisString.GetTaggedValue()); + JSTaggedValue replStrDeocodeValue = JSFunction::Call(info); + replHandle.Update(replStrDeocodeValue); + } else { + // Let captures be an empty List. + JSHandle capturesList = factory->NewTaggedArray(0); + ASSERT_PRINT(replaceTag->IsString(), "replace must be string"); + JSHandle replacement(thread, replaceTag->GetTaggedObject()); + // Let replStr be GetSubstitution(matched, string, pos, captures, replaceValue) + replHandle.Update(GetSubstitution(thread, searchString, thisString, pos, + capturesList, undefined, replacement)); + } + JSHandle realReplaceStr = JSTaggedValue::ToString(thread, replHandle); + // Let tailPos be pos + the number of code units in matched. + // Let newString be the String formed by concatenating the first pos code units of string, + // replStr, and the trailing substring of string starting at index tailPos. + // If pos is 0, the first element of the concatenation will be the + // empty String. + // Return newString. + JSHandle prefixString(thread, + EcmaString::FastSubString(thisString, endOfLastMatch, + pos - endOfLastMatch, ecmaVm)); + if (prefixString->IsUtf16()) { + const uint16_t *data = prefixString->GetDataUtf16(); + stringPrefixString = base::StringHelper::Utf16ToU16String(data, prefixString->GetLength()); + canBeCompress = false; + } else { + const uint8_t *data = prefixString->GetDataUtf8(); + stringPrefixString = base::StringHelper::Utf8ToU16String(data, prefixString->GetLength()); + } + if (realReplaceStr->IsUtf16()) { + const uint16_t *data = realReplaceStr->GetDataUtf16(); + stringRealReplaceStr = base::StringHelper::Utf16ToU16String(data, realReplaceStr->GetLength()); + canBeCompress = false; + } else { + const uint8_t *data = realReplaceStr->GetDataUtf8(); + stringRealReplaceStr = base::StringHelper::Utf8ToU16String(data, realReplaceStr->GetLength()); + } + stringBuilder = stringBuilder + stringPrefixString + stringRealReplaceStr; + endOfLastMatch = pos + searchLength; + pos = thisString->IndexOf(*searchString, pos + advanceBy); + } + + if (endOfLastMatch < static_cast(thisString->GetLength())) { + JSHandle suffixString(thread, + EcmaString::FastSubString(thisString, endOfLastMatch, + thisString->GetLength() - endOfLastMatch, ecmaVm)); + if (suffixString->IsUtf16()) { + const uint16_t *data = suffixString->GetDataUtf16(); + stringSuffixString = base::StringHelper::Utf16ToU16String(data, suffixString->GetLength()); + canBeCompress = false; + } else { + const uint8_t *data = suffixString->GetDataUtf8(); + stringSuffixString = base::StringHelper::Utf8ToU16String(data, suffixString->GetLength()); + } + stringBuilder = stringBuilder + stringSuffixString; } auto *char16tData = const_cast(stringBuilder.c_str()); auto *uint16tData = reinterpret_cast(char16tData); - return canBeCompress ? factory->NewFromUtf16LiteralCompress(uint16tData, stringBuilder.size()).GetTaggedValue() : - factory->NewFromUtf16LiteralNotCompress(uint16tData, stringBuilder.size()).GetTaggedValue(); + return canBeCompress ? + factory->NewFromUtf16LiteralCompress(uint16tData, stringBuilder.length()).GetTaggedValue() : + factory->NewFromUtf16LiteralNotCompress(uint16tData, stringBuilder.length()).GetTaggedValue(); } JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle &matched, const JSHandle &srcString, int position, const JSHandle &captureList, + const JSHandle &namedCaptures, const JSHandle &replacement) { BUILTINS_API_TRACE(thread, String, GetSubstitution); @@ -1073,7 +1208,6 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandle 0) { @@ -1099,6 +1233,7 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleAt(peekIndex); + int32_t p = 0; switch (peek) { case '$': // $$ stringBuilder += '$'; @@ -1193,6 +1328,42 @@ JSTaggedValue BuiltinsString::GetSubstitution(JSThread *thread, const JSHandleIsUndefined()) { + stringBuilder += '$'; + continueFromIndex = peekIndex; + break; + } + JSHandle greaterSymString = factory->NewFromASCII(">"); + int pos = replacement->IndexOf(*greaterSymString, peekIndex); + if (pos == -1) { + stringBuilder += '$'; + continueFromIndex = peekIndex; + break; + } + JSHandle groupName(thread, + EcmaString::FastSubString(replacement, + peekIndex + 1, pos - peekIndex - 1, ecmaVm)); + JSHandle names(groupName); + JSHandle capture = JSObject::GetProperty(thread, namedCaptures, names).GetValue(); + if (capture->IsUndefined()) { + continueFromIndex = pos + 1; + p = pos; + break; + } + JSHandle captureName(capture); + if (captureName->IsUtf16()) { + const uint16_t *data = captureName->GetDataUtf16(); + stringBuilder += base::StringHelper::Utf16ToU16String(data, captureName->GetLength()); + canBeCompress = false; + } else { + const uint8_t *data = captureName->GetDataUtf8(); + stringBuilder += base::StringHelper::Utf8ToU16String(data, captureName->GetLength()); + } + continueFromIndex = pos + 1; + p = pos; + break; + } default: stringBuilder += '$'; continueFromIndex = peekIndex; @@ -1254,10 +1425,11 @@ JSTaggedValue BuiltinsString::Search(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!searcher->IsUndefined()) { ASSERT(searcher->IsJSFunction()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, searcher, regexp, undefined, 1); - info.SetCallArg(thisTag.GetTaggedValue()); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisTag.GetTaggedValue()); + return JSFunction::Call(info); } } } @@ -1265,10 +1437,11 @@ JSTaggedValue BuiltinsString::Search(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle rx(thread, BuiltinsRegExp::RegExpCreate(thread, regexp, undefined)); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, rx, undefined, 1); - info.SetCallArg(thisVal.GetTaggedValue()); - return JSFunction::Invoke(&info, searchTag); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisVal.GetTaggedValue()); + return JSFunction::Invoke(info, searchTag); } // 21.1.3.16 @@ -1336,12 +1509,13 @@ JSTaggedValue BuiltinsString::Split(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!splitter->IsUndefined()) { // Return Call(splitter, separator, «‍O, limit»). - const size_t argsLength = 2; + const int32_t argsLength = 2; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, splitter, seperatorTag, undefined, argsLength); - info.SetCallArg(thisTag.GetTaggedValue(), limitTag.GetTaggedValue()); - return JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(thisTag.GetTaggedValue(), limitTag.GetTaggedValue()); + return JSFunction::Call(info); } } // Let S be ToString(O). diff --git a/ecmascript/builtins/builtins_string.h b/ecmascript/builtins/builtins_string.h index 34c82e149e8f52702748535cd11fa735c29ec311..80489a25df2352212ef7b3b864825e9ac063a152 100644 --- a/ecmascript/builtins/builtins_string.h +++ b/ecmascript/builtins/builtins_string.h @@ -43,6 +43,7 @@ public: static JSTaggedValue GetSubstitution(JSThread *thread, const JSHandle &matched, const JSHandle &srcString, int position, const JSHandle &captureList, + const JSHandle &namedCaptures, const JSHandle &replacement); // 21.1.3.1 static JSTaggedValue CharAt(EcmaRuntimeCallInfo *argv); @@ -78,6 +79,7 @@ public: // 21.1.3.14 static JSTaggedValue Replace(EcmaRuntimeCallInfo *argv); // 21.1.3.14.1 Runtime Semantics: GetSubstitution() + static JSTaggedValue ReplaceAll(EcmaRuntimeCallInfo *argv); // 21.1.3.15 static JSTaggedValue Search(EcmaRuntimeCallInfo *argv); // 21.1.3.16 diff --git a/ecmascript/builtins/builtins_typedarray.cpp b/ecmascript/builtins/builtins_typedarray.cpp index 3674011d4569568f582c5efd56ccfb3292ab64a0..045da52a68c2b3edca2b0f27ae927a700c9ed383 100644 --- a/ecmascript/builtins/builtins_typedarray.cpp +++ b/ecmascript/builtins/builtins_typedarray.cpp @@ -197,17 +197,18 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) // vi. Set k to k + 1. JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 2; + const int32_t argsLength = 2; double k = 0; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); while (k < len) { tKey.Update(JSTaggedValue(k)); JSHandle kValue = vec[k]; if (mapping) { - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, mapfn, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), tKey.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), tKey.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); mapValue.Update(callResult); } else { @@ -251,7 +252,7 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) // e. Perform ? Set(targetObj, Pk, mappedValue, true). // f. Set k to k + 1. JSMutableHandle tKey(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 2; + const int32_t argsLength = 2; double k = 0; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); while (k < len) { @@ -261,10 +262,11 @@ JSTaggedValue BuiltinsTypedArray::From(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSHandle mapValue; if (mapping) { - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, mapfn, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), tKey.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), tKey.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); mapValue = JSHandle(thread, callResult); } else { @@ -286,7 +288,7 @@ JSTaggedValue BuiltinsTypedArray::Of(EcmaRuntimeCallInfo *argv) JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); // 1. Let len be the actual number of arguments passed to this function. - uint32_t len = argv->GetArgsNumber(); + int32_t len = argv->GetArgsNumber(); // 2. Let items be the List of arguments passed to this function. // 3. Let C be the this value. JSHandle thisHandle = GetThis(argv); @@ -490,7 +492,7 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) // v. If testResult is false, return false. // e. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); uint32_t k = 0; while (k < len) { @@ -498,10 +500,11 @@ JSTaggedValue BuiltinsTypedArray::Every(EcmaRuntimeCallInfo *argv) JSHandle kValue = JSTaggedValue::GetProperty(thread, thisObjVal, k).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); bool boolResult = callResult.ToBoolean(); if (!boolResult) { @@ -573,11 +576,12 @@ JSTaggedValue BuiltinsTypedArray::Filter(EcmaRuntimeCallInfo *argv) JSHandle kKey(JSTaggedValue::ToString(thread, tKey)); JSHandle kValue = JSTaggedValue::GetProperty(thread, thisHandle, kKey).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3: «kValue, k, O» - info.SetCallArg(kValue.GetTaggedValue(), tKey.GetTaggedValue(), thisHandle.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), tKey.GetTaggedValue(), thisHandle.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); bool testResult = callResult.ToBoolean(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (testResult) { @@ -672,17 +676,18 @@ JSTaggedValue BuiltinsTypedArray::ForEach(EcmaRuntimeCallInfo *argv) // iv. ReturnIfAbrupt(funcResult). // e. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); uint32_t k = 0; while (k < len) { JSHandle kValue = JSTaggedValue::GetProperty(thread, thisObjVal, k).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); key.Update(JSTaggedValue(k)); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisObjVal.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); k++; } @@ -893,16 +898,17 @@ JSTaggedValue BuiltinsTypedArray::Map(EcmaRuntimeCallInfo *argv) // h. Increase k by 1. JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle mapValue(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (uint32_t k = 0; k < len; k++) { key.Update(JSTaggedValue(k)); JSHandle kValue = JSTaggedValue::GetProperty(thread, thisHandle, key).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackfnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); mapValue.Update(callResult); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); JSTaggedValue::SetProperty(thread, JSHandle(newArrObj), key, mapValue, true); @@ -1113,7 +1119,7 @@ JSTaggedValue BuiltinsTypedArray::Set(EcmaRuntimeCallInfo *argv) // 26. Let targetByteIndex be targetOffset × targetElementSize + targetByteOffset. int32_t targetByteIndex = static_cast(targetOffset * targetElementSize + targetByteOffset); // 27. Let limit be targetByteIndex + targetElementSize × srcLength. - int32_t limit = targetByteIndex + targetElementSize * srcLength; + int32_t limit = targetByteIndex + static_cast(targetElementSize * srcLength); // 28. If SameValue(srcType, targetType) is false, then // a. Repeat, while targetByteIndex < limit // i. Let value be GetValueFromBuffer(srcBuffer, srcByteIndex, srcType). @@ -1413,7 +1419,7 @@ JSTaggedValue BuiltinsTypedArray::Subarray(EcmaRuntimeCallInfo *argv) // 21. Let argumentsList be «buffer, beginByteOffset, newLength». // 5. Let buffer be the value of O’s [[ViewedArrayBuffer]] internal slot. // 22. Return Construct(constructor, argumentsList). - const size_t argsLength = 3; + const int32_t argsLength = 3; JSTaggedType args[argsLength] = { buffer.GetRawData(), JSTaggedValue(beginByteOffset).GetRawData(), diff --git a/ecmascript/builtins/builtins_weak_set.cpp b/ecmascript/builtins/builtins_weak_set.cpp index e67759f4af354f9b14c0c1a82d13b12422da56c1..bd0ee37181c873540576d928d450346dc60f6040 100644 --- a/ecmascript/builtins/builtins_weak_set.cpp +++ b/ecmascript/builtins/builtins_weak_set.cpp @@ -83,15 +83,16 @@ JSTaggedValue BuiltinsWeakSet::WeakSetConstructor(EcmaRuntimeCallInfo *argv) JSHandle nextValue(JSIterator::IteratorValue(thread, next)); // ReturnIfAbrupt(nextValue). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, nextValue.GetTaggedValue()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, adder, JSHandle(weakSet), undefined, 1); - info.SetCallArg(nextValue.GetTaggedValue()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(nextValue.GetTaggedValue()); if (nextValue->IsArray(thread)) { auto prop = JSObject::GetProperty(thread, nextValue, valueIndex).GetValue(); - info.SetCallArg(prop.GetTaggedValue()); + info->SetCallArg(prop.GetTaggedValue()); } // Let status be Call(adder, weakset, «nextValue.[[value]]»). - JSFunction::Call(&info); + JSFunction::Call(info); // If status is an abrupt completion, return IteratorClose(iter, status). if (thread->HasPendingException()) { return JSIterator::IteratorCloseAndReturn(thread, iter); diff --git a/ecmascript/builtins/tests/BUILD.gn b/ecmascript/builtins/tests/BUILD.gn index 01d582903415dfaa6def99c1f7160f650ed35de3..b5465c6a55b11178c9b0a194a7e41d22d22f18ca 100755 --- a/ecmascript/builtins/tests/BUILD.gn +++ b/ecmascript/builtins/tests/BUILD.gn @@ -17,7 +17,7 @@ import("//build/test.gni") module_output_path = "ark/js_runtime" -host_unittest_action("BuiltinsInternationalTest") { +host_unittest_action("BuiltinsInternational_001_Test") { module_out_path = module_output_path sources = [ @@ -26,9 +26,29 @@ host_unittest_action("BuiltinsInternationalTest") { "builtins_collator_test.cpp", "builtins_date_time_format_test.cpp", "builtins_displaynames_test.cpp", + ] + + configs = [ + "//ark/js_runtime:ecma_test_config", + "//ark/js_runtime:icu_path_test_config", + ] + + deps = [ + "$ark_root/libpandabase:libarkbase", + "//ark/js_runtime:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] +} + +host_unittest_action("BuiltinsInternational_002_Test") { + module_out_path = module_output_path + + sources = [ + # test file "builtins_intl_test.cpp", "builtins_list_format_test.cpp", "builtins_locale_test.cpp", + "builtins_number_format_test.cpp", "builtins_plural_rules_test.cpp", "builtins_relative_time_format_test.cpp", ] @@ -94,7 +114,8 @@ group("unittest") { # deps file deps = [ - ":BuiltinsInternationalTest", + ":BuiltinsInternational_001_Test", + ":BuiltinsInternational_002_Test", ":BuiltinsNaturalTest", ] } @@ -104,7 +125,8 @@ group("host_unittest") { # deps file deps = [ - ":BuiltinsInternationalTestAction", + ":BuiltinsInternational_001_TestAction", + ":BuiltinsInternational_002_TestAction", ":BuiltinsNaturalTestAction", ] } diff --git a/ecmascript/builtins/tests/builtins_array_test.cpp b/ecmascript/builtins/tests/builtins_array_test.cpp index d0235567f420644a52aeb438402005b45936853e..622597103e3ef4382d358b9feb8a253efde4e402 100644 --- a/ecmascript/builtins/tests/builtins_array_test.cpp +++ b/ecmascript/builtins/tests/builtins_array_test.cpp @@ -81,7 +81,7 @@ public: static JSTaggedValue TestEveryFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { if (GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case return GetTaggedBoolean(true); @@ -120,7 +120,7 @@ public: static JSTaggedValue TestFindFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -132,7 +132,7 @@ public: static JSTaggedValue TestFindIndexFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -158,7 +158,7 @@ public: static JSTaggedValue TestSomeFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { if (GetCallArg(argv, 0)->GetInt() > 10) { // 10 : test case return GetTaggedBoolean(true); @@ -198,8 +198,8 @@ HWTEST_F_L0(BuiltinsArrayTest, ArrayConstructor) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::ArrayConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::ArrayConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -246,8 +246,8 @@ HWTEST_F_L0(BuiltinsArrayTest, From) ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::From(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::From(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -279,8 +279,8 @@ HWTEST_F_L0(BuiltinsArrayTest, IsArray) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::IsArray(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::IsArray(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -289,8 +289,8 @@ HWTEST_F_L0(BuiltinsArrayTest, IsArray) ecmaRuntimeCallInfo2->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result = Array::IsArray(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result = Array::IsArray(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -309,8 +309,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Of) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Of(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Of(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -339,8 +339,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Species) ecmaRuntimeCallInfo1->SetFunction(array.GetTaggedValue()); ecmaRuntimeCallInfo1->SetThis(globalObject.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Species(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Species(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); } @@ -379,8 +379,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Concat) ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, obj1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Concat(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Concat(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -426,8 +426,8 @@ HWTEST_F_L0(BuiltinsArrayTest, CopyWithin) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::CopyWithin(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::CopyWithin(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -477,8 +477,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Every) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = Array::Every(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = Array::Every(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -513,8 +513,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Map) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Map(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Map(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -553,8 +553,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Reverse) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Reverse(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Reverse(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -607,8 +607,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Slice) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(4))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Slice(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Slice(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -655,8 +655,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Splice) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(2))); ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(100))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Splice(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Splice(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -702,8 +702,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Fill) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Fill(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Fill(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -750,8 +750,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Find) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = Array::Find(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = Array::Find(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue(102).GetRawData()); @@ -789,8 +789,8 @@ HWTEST_F_L0(BuiltinsArrayTest, FindIndex) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = Array::FindIndex(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = Array::FindIndex(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -827,8 +827,8 @@ HWTEST_F_L0(BuiltinsArrayTest, ForEach) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = Array::ForEach(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = Array::ForEach(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(jsArray->GetArrayLength(), 3U); @@ -865,8 +865,8 @@ HWTEST_F_L0(BuiltinsArrayTest, IndexOf) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::IndexOf(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::IndexOf(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -876,8 +876,8 @@ HWTEST_F_L0(BuiltinsArrayTest, IndexOf) ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result = Array::IndexOf(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result = Array::IndexOf(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); @@ -887,8 +887,8 @@ HWTEST_F_L0(BuiltinsArrayTest, IndexOf) ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo3->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - result = Array::IndexOf(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + result = Array::IndexOf(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); @@ -897,8 +897,8 @@ HWTEST_F_L0(BuiltinsArrayTest, IndexOf) ecmaRuntimeCallInfo4->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - result = Array::IndexOf(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + result = Array::IndexOf(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -935,8 +935,8 @@ HWTEST_F_L0(BuiltinsArrayTest, LastIndexOf) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(4))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::LastIndexOf(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::LastIndexOf(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); @@ -947,8 +947,8 @@ HWTEST_F_L0(BuiltinsArrayTest, LastIndexOf) ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result = Array::LastIndexOf(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result = Array::LastIndexOf(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); @@ -959,8 +959,8 @@ HWTEST_F_L0(BuiltinsArrayTest, LastIndexOf) ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo3->SetCallArg(1, JSTaggedValue(static_cast(4))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - result = Array::LastIndexOf(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + result = Array::LastIndexOf(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); @@ -970,8 +970,8 @@ HWTEST_F_L0(BuiltinsArrayTest, LastIndexOf) ecmaRuntimeCallInfo4->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(3))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - result = Array::LastIndexOf(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + result = Array::LastIndexOf(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(4)).GetRawData()); } @@ -989,8 +989,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Pop) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Pop(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Pop(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -1009,8 +1009,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Pop) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result = Array::Pop(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result = Array::Pop(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); } @@ -1040,8 +1040,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Push) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(4))); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Push(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Push(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetNumber(), 5); @@ -1081,8 +1081,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Reduce) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Reduce(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Reduce(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(16).GetRawData()); } @@ -1116,8 +1116,8 @@ HWTEST_F_L0(BuiltinsArrayTest, ReduceRight) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::ReduceRight(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::ReduceRight(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(16).GetRawData()); } @@ -1144,8 +1144,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Shift) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Shift(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Shift(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -1181,8 +1181,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Some) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = Array::Some(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = Array::Some(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -1209,8 +1209,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Sort) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = Array::Sort(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = Array::Sort(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsECMAObject()); @@ -1245,8 +1245,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Unshift) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(4))); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Unshift(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Unshift(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); @@ -1281,8 +1281,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Join) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Join(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Join(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); [[maybe_unused]] auto *res = EcmaString::Cast(resultHandle.GetTaggedValue().GetTaggedObject()); @@ -1313,8 +1313,8 @@ HWTEST_F_L0(BuiltinsArrayTest, ToString) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Join(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Join(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); [[maybe_unused]] auto *res = EcmaString::Cast(resultHandle.GetTaggedValue().GetTaggedObject()); @@ -1345,8 +1345,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Includes) ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - [[maybe_unused]] JSTaggedValue result = Array::Includes(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + [[maybe_unused]] JSTaggedValue result = Array::Includes(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(2) @@ -1356,8 +1356,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Includes) ecmaRuntimeCallInfo2->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result = Array::Includes(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result = Array::Includes(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(!result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(1) @@ -1368,8 +1368,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Includes) ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo3->SetCallArg(1, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - result = Array::Includes(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + result = Array::Includes(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(3, 1) @@ -1380,8 +1380,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Includes) ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(2))); ecmaRuntimeCallInfo4->SetCallArg(1, JSTaggedValue(static_cast(5))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - result = Array::Includes(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + result = Array::Includes(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(!result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(2, 5) @@ -1392,8 +1392,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Includes) ecmaRuntimeCallInfo5->SetCallArg(0, JSTaggedValue(static_cast(2))); ecmaRuntimeCallInfo5->SetCallArg(1, JSTaggedValue(static_cast(-2))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5.get()); - result = Array::Includes(ecmaRuntimeCallInfo5.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5); + result = Array::Includes(ecmaRuntimeCallInfo5); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(!result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(2, -2) @@ -1430,8 +1430,8 @@ HWTEST_F_L0(BuiltinsArrayTest, Flat) auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(obj1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::Flat(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::Flat(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); @@ -1476,8 +1476,8 @@ HWTEST_F_L0(BuiltinsArrayTest, FlatMap) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = Array::FlatMap(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = Array::FlatMap(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); diff --git a/ecmascript/builtins/tests/builtins_arraybuffer_test.cpp b/ecmascript/builtins/tests/builtins_arraybuffer_test.cpp index cbc33ea70153fd6cb8051db95fc0231e1281a9f1..ea6a6d72b361d93bb90b90e7340637ed937702e0 100644 --- a/ecmascript/builtins/tests/builtins_arraybuffer_test.cpp +++ b/ecmascript/builtins/tests/builtins_arraybuffer_test.cpp @@ -65,8 +65,9 @@ JSTaggedValue CreateBuiltinsArrayBuffer(JSThread *thread, int32_t length) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(length)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -81,9 +82,10 @@ HWTEST_F_L0(BuiltinsArrayBufferTest, Constructor1) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); + TestHelper::TearDownFrame(thread, prev); } // (new ArrayBuffer(5)).byteLength @@ -95,9 +97,10 @@ HWTEST_F_L0(BuiltinsArrayBufferTest, byteLength1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(arrBuf.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsArrayBuffer::GetByteLength(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsArrayBuffer::GetByteLength(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(5).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // (new ArrayBuffer(10)).slice(1, 5).bytelength @@ -111,17 +114,18 @@ HWTEST_F_L0(BuiltinsArrayBufferTest, slice1) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsArrayBuffer::Slice(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsArrayBuffer::Slice(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle arrBuf1(thread, JSArrayBuffer::Cast(reinterpret_cast(result1.GetRawData()))); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(arrBuf1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsArrayBuffer::GetByteLength(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsArrayBuffer::GetByteLength(ecmaRuntimeCallInfo1); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(4).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_atomics_test.cpp b/ecmascript/builtins/tests/builtins_atomics_test.cpp index b4f7a8678465da7cefe3479fb254615e9aac06eb..5bae0a1981c7c8ec62bfc2fe4e65ac1b08ef6d92 100644 --- a/ecmascript/builtins/tests/builtins_atomics_test.cpp +++ b/ecmascript/builtins/tests/builtins_atomics_test.cpp @@ -70,8 +70,9 @@ JSTypedArray *CreateTypedArray(JSThread *thread, const JSHandle &ar ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(*globalObject)); ecmaRuntimeCallInfo1->SetCallArg(0, jsarray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = TypedArray::Int8ArrayConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = TypedArray::Int8ArrayConstructor(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsECMAObject()); JSTypedArray *int8arr = JSTypedArray::Cast(reinterpret_cast(result.GetRawData())); @@ -95,8 +96,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Add_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 7); } @@ -115,8 +116,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Add_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 0); } @@ -135,8 +136,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Add_3) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 0); @@ -147,12 +148,36 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Add_3) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - JSTaggedValue results = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + JSTaggedValue results = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(results.GetInt(), 2); } +HWTEST_F_L0(BuiltinsAtomicsTest, SubAndAdd_1) +{ + ASSERT_NE(thread, nullptr); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + [[maybe_unused]] JSHandle array(factory->NewTaggedArray(3)); + array->Set(thread, 0, JSTaggedValue(5)); + array->Set(thread, 1, JSTaggedValue(0)); + array->Set(thread, 2, JSTaggedValue(0)); + + JSHandle obj = JSHandle(thread, CreateTypedArray(thread, array)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); + ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsAtomics::Sub(ecmaRuntimeCallInfo); + JSTaggedValue addResult = BuiltinsAtomics::Add(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + ASSERT_EQ(addResult.GetInt(), 3); +} + HWTEST_F_L0(BuiltinsAtomicsTest, And_1) { ASSERT_NE(thread, nullptr); @@ -170,8 +195,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, And_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Add(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 7); } @@ -193,8 +218,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, And_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::And(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::And(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 7); @@ -205,8 +230,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, And_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 2); } @@ -229,8 +254,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, CompareExchange_1) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::CompareExchange(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::CompareExchange(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); } @@ -253,8 +278,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, CompareExchange_2) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::CompareExchange(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::CompareExchange(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); @@ -265,8 +290,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, CompareExchange_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 2); } @@ -288,8 +313,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Exchange_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Exchange(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Exchange(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 3); } @@ -311,8 +336,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Exchange_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Exchange(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Exchange(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 3); @@ -323,8 +348,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Exchange_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 6); } @@ -346,8 +371,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Or_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Or(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Or(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); } @@ -369,8 +394,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Or_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Or(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Or(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); @@ -381,8 +406,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Or_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 7); } @@ -404,8 +429,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Sub_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Sub(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Sub(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); } @@ -427,8 +452,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Sub_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Sub(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Sub(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); @@ -438,8 +463,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Sub_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 3); } @@ -461,8 +486,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Xor_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Xor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Xor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 7); } @@ -484,8 +509,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Xor_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Xor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Xor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 7); @@ -495,8 +520,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Xor_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 5); } @@ -508,8 +533,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, IsLockFree_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.ToBoolean()); } @@ -521,8 +546,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, IsLockFree_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.ToBoolean()); } @@ -534,8 +559,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, IsLockFree_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(4))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.ToBoolean()); } @@ -547,8 +572,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, IsLockFree_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_FALSE(result.ToBoolean()); } @@ -560,8 +585,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, IsLockFree_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::IsLockFree(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.ToBoolean()); } @@ -584,8 +609,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Store_1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Store(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Store(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetDouble(), 2); } @@ -607,8 +632,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Store_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsAtomics::Store(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsAtomics::Store(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetDouble(), 2); @@ -618,8 +643,8 @@ HWTEST_F_L0(BuiltinsAtomicsTest, Store_2) ecmaRuntimeCallInfos->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfos->SetCallArg(1, JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos.get()); - result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfos); + result = BuiltinsAtomics::Load(ecmaRuntimeCallInfos); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetInt(), 2); } diff --git a/ecmascript/builtins/tests/builtins_bigint_test.cpp b/ecmascript/builtins/tests/builtins_bigint_test.cpp index 110ee3a261e9606d1765969b18ae663bf78bc954..77711630cb5edfdeab17b6b3b457e4550cb9a9a9 100644 --- a/ecmascript/builtins/tests/builtins_bigint_test.cpp +++ b/ecmascript/builtins/tests/builtins_bigint_test.cpp @@ -70,8 +70,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, BigIntConstructor_001) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -88,8 +88,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, BigIntConstructor_002) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -108,8 +108,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, AsIntN_001) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBigInt::AsIntN(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBigInt::AsIntN(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -132,8 +132,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, AsIntN_002) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBigInt::AsIntN(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBigInt::AsIntN(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -156,8 +156,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, AsUintN_001) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBigInt::AsUintN(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBigInt::AsUintN(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -180,8 +180,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, AsUintN_002) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(bit))); ecmaRuntimeCallInfo->SetCallArg(1, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBigInt::AsUintN(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBigInt::AsUintN(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsBigInt()); @@ -202,8 +202,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToLocaleString_001) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -215,8 +215,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToLocaleString_001) ecmaRuntimeCallInfo2->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToLocaleString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ToLocaleString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -242,8 +242,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToLocaleString_002) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -257,8 +257,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToLocaleString_002) ecmaRuntimeCallInfo2->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, optionsObj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToLocaleString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ToLocaleString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -277,8 +277,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_001) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -287,8 +287,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_001) ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -307,8 +307,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_002) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -317,8 +317,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_002) ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -337,8 +337,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_003) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -348,8 +348,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_003) ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, radix.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -368,8 +368,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_004) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -379,8 +379,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ToString_004) ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, radix.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result2.IsString()); @@ -399,8 +399,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ValueOf_001) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -408,8 +408,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ValueOf_001) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(bigIntHandle.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ValueOf(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ValueOf(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(BigInt::SameValue(result1, result2), true); @@ -426,8 +426,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ValueOf_002) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, numericValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle bigIntHandle(thread, result1); @@ -438,8 +438,8 @@ HWTEST_F_L0(BuiltinsBigIntTest, ValueOf_002) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(jsPrimitiveRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsBigInt::ValueOf(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsBigInt::ValueOf(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(BigInt::SameValue(bigIntHandle.GetTaggedValue(), result2), true); diff --git a/ecmascript/builtins/tests/builtins_boolean_test.cpp b/ecmascript/builtins/tests/builtins_boolean_test.cpp index f6b094a1e3ae35c34f37b6d07341472ca25c5195..7eaf757750f3fe252ccff89a0116b2b56280071a 100644 --- a/ecmascript/builtins/tests/builtins_boolean_test.cpp +++ b/ecmascript/builtins/tests/builtins_boolean_test.cpp @@ -69,8 +69,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanConstructor) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsTrue(), 1); @@ -89,8 +89,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanConstructor1) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(JSPrimitiveRef::Cast(result.GetTaggedObject())->GetValue().IsFalse(), 1); @@ -110,8 +110,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanConstructor2) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(true); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); @@ -124,8 +124,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanPrototypeToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeToString(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); auto ruler = thread->GetEcmaVM()->GetFactory()->NewFromASCII("false"); @@ -146,8 +146,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanPrototypeToString1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(boolean.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeToString(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); auto ruler = thread->GetEcmaVM()->GetFactory()->NewFromASCII("true"); @@ -161,8 +161,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanPrototypeValueOf) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeValueOf(ecmaRuntimeCallInfo); JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(true); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); @@ -182,8 +182,8 @@ HWTEST_F_L0(BuiltinsBooleanTest, BooleanPrototypeValueOf1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(boolean.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsBoolean::BooleanPrototypeValueOf(ecmaRuntimeCallInfo); JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(false); ASSERT_EQ(result.GetRawData(), ruler.GetRawData()); diff --git a/ecmascript/builtins/tests/builtins_collator_test.cpp b/ecmascript/builtins/tests/builtins_collator_test.cpp index 1f819f6d0f48e85c8c4b4417f8f1cabc4cb47fa7..dda2a9cff51e3525e4f503a701b411b04e3a2d98 100644 --- a/ecmascript/builtins/tests/builtins_collator_test.cpp +++ b/ecmascript/builtins/tests/builtins_collator_test.cpp @@ -97,8 +97,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, CollatorConstructor) ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); // set option tag - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsCollator::CollatorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsCollator::CollatorConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSCollator()); @@ -117,9 +117,10 @@ static JSTaggedValue JSCollatorCreateWithLocaleTest(JSThread *thread, JSHandleSetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsCollator::CollatorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsCollator::CollatorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsJSCollator()); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -146,9 +147,10 @@ static JSTaggedValue JSCollatorCreateWithLocaleAndOptionsTest(JSThread *thread, ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsCollator::CollatorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsCollator::CollatorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsJSCollator()); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -163,8 +165,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_001) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsCollator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsCollator::Compare(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsCollator::Compare(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle jsFunction(thread, result1); @@ -190,8 +192,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_001) ecmaRuntimeCallInfo2->SetThis(jsObject.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, jsFunction.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsArray::Sort(ecmaRuntimeCallInfo2.get()); // sort in language(de) + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsArray::Sort(ecmaRuntimeCallInfo2); // sort in language(de) TestHelper::TearDownFrame(thread, prev); JSHandle resultArr = @@ -212,8 +214,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_002) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsCollator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsCollator::Compare(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsCollator::Compare(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle jsFunction(thread, result1); @@ -239,8 +241,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_002) ecmaRuntimeCallInfo2->SetThis(jsObject.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, jsFunction.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsArray::Sort(ecmaRuntimeCallInfo2.get()); // sort in language(sv) + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsArray::Sort(ecmaRuntimeCallInfo2); // sort in language(sv) TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result2); @@ -249,8 +251,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_002) ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo3->SetThis(resultObj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result = BuiltinsArray::Join(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result = BuiltinsArray::Join(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_EQ(resultHandle->Compare(*str), 0); @@ -268,8 +270,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_003) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsCollator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsCollator::Compare(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsCollator::Compare(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle jsFunction(thread, result1); @@ -289,8 +291,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, Compare_003) ecmaRuntimeCallInfo2->SetCallArg(0, value0.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, value1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsArray::ToString(ecmaRuntimeCallInfo2.get()); // search in language(sv) + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsArray::ToString(ecmaRuntimeCallInfo2); // search in language(sv) TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result2); EXPECT_EQ(resultHandle->GetInt(), 0); // Congrès and congres is matching @@ -307,8 +309,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, ResolvedOptions) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsCollator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsCollator::ResolvedOptions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsCollator::ResolvedOptions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj = @@ -344,8 +346,8 @@ HWTEST_F_L0(BuiltinsCollatorTest, SupportedLocalesOf) ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsCollator::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsCollator::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); diff --git a/ecmascript/builtins/tests/builtins_dataview_test.cpp b/ecmascript/builtins/tests/builtins_dataview_test.cpp index 569613ccb7e0001a0401ca1803da56e704c90dd9..c53eb1d8049ff6b0362f38e6d71bfdae7b699a14 100644 --- a/ecmascript/builtins/tests/builtins_dataview_test.cpp +++ b/ecmascript/builtins/tests/builtins_dataview_test.cpp @@ -67,8 +67,9 @@ JSTaggedValue CreateBuiltinsDataviewArrayBuffer(JSThread *thread, int32_t length ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(length)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsArrayBuffer::ArrayBufferConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -86,8 +87,9 @@ JSTaggedValue CreateBuiltinsDataView(JSThread *thread, int32_t length, int32_t b ecmaRuntimeCallInfo->SetCallArg(0, arrBuf.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(byte_offset)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::DataViewConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::DataViewConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -99,8 +101,9 @@ void SetUint8(JSThread *thread, const JSHandle &view, int32_t offset ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(offset)); ecmaRuntimeCallInfo->SetCallArg(1, value); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDataView::SetUint8(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDataView::SetUint8(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(10), 1) @@ -117,9 +120,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, Constructor) ecmaRuntimeCallInfo->SetCallArg(0, arrBuf.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::DataViewConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::DataViewConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(10), 1).byteOffset @@ -131,9 +135,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, byteOffset) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetOffset(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetOffset(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(10), 2).byteLength @@ -145,9 +150,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, byteLength) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetByteLength(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetByteLength(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(8).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(10), 1).buffer @@ -159,9 +165,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, buffer) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetBuffer(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetBuffer(ecmaRuntimeCallInfo); ASSERT_EQ(result.IsArrayBuffer(), true); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(8), 0).SetUint16/GetUint16 @@ -176,9 +183,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, getUint16) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1870724872)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetUint16(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetUint16(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -186,8 +194,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, getUint16) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::True()); - JSTaggedValue result1 = BuiltinsDataView::GetUint16(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetUint16(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(63488).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } // new DataView(new ArrayBuffer(8), 0).SetInt16/GetInt16 @@ -202,9 +212,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, getInt16) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1870724872)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetInt16(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetInt16(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -212,8 +223,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, getInt16) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::True()); - JSTaggedValue result1 = BuiltinsDataView::GetInt16(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetInt16(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(-2048).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } // new DataView(new ArrayBuffer(8), 0).SetUint8/GetUint32 @@ -232,9 +245,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, GetUint32) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetUint32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetUint32(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(2147483647).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(8), 0).SetUint8/GetInt32 @@ -253,9 +267,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, GetInt32) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetInt32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetInt32(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(2147483647).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(8), 0).SetUint8/GetInt8 @@ -270,9 +285,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, GetInt8) ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetInt8(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetInt8(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(8), 0).SetUint8/GetUint8 @@ -287,9 +303,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, GetUint8) ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetUint8(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetUint8(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(127).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(8), 4).SetUint8/GetFloat32 @@ -308,9 +325,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, GetFloat32) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(4)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetFloat32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetFloat32(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(13323083)).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(12), 4).SetUint8/GetFloat64 @@ -333,9 +351,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, GetFloat64) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(4)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::GetFloat64(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::GetFloat64(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(10846169068898440)).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new DataView(new ArrayBuffer(8), 0).SetUint32/GetUint32 @@ -350,9 +369,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetUint32) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(0x907f00f8)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetUint32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetUint32(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -360,8 +380,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetUint32) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetUint32(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetUint32(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(0xf8007f90)).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } // new DataView(new ArrayBuffer(8), 0).SetInt32/GetInt32 @@ -376,9 +398,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetInt32) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1870724872)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetInt32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetInt32(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -386,8 +409,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetInt32) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetInt32(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetInt32(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(-134185072).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } // new DataView(new ArrayBuffer(8), 0).SetInt8/GetUint8 @@ -400,16 +425,20 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetInt8) ecmaRuntimeCallInfo->SetThis(view.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetInt8(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetInt8(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(view.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); - JSTaggedValue result1 = BuiltinsDataView::GetUint8(ecmaRuntimeCallInfo1.get()); + + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetUint8(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(255).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } // new DataView(new ArrayBuffer(4), 0).SetFloat32/GetFloat32 @@ -424,9 +453,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetFloat32) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(42)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetFloat32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetFloat32(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -434,8 +464,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetFloat32) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetFloat32(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetFloat32(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1.4441781973331565e-41)).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } // new DataView(new ArrayBuffer(8), 0).SetFloat64/GetFloat64 @@ -450,9 +482,10 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetFloat64) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(42)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDataView::SetFloat64(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDataView::SetFloat64(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); @@ -460,7 +493,9 @@ HWTEST_F_L0(BuiltinsDataViewTest, SetFloat64) ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(0)); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue::False()); - JSTaggedValue result1 = BuiltinsDataView::GetFloat64(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDataView::GetFloat64(ecmaRuntimeCallInfo1); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(8.759e-320)).GetRawData()); + TestHelper::TearDownFrame(thread, prev1); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_date_test.cpp b/ecmascript/builtins/tests/builtins_date_test.cpp index c1bde824663c57cb0240c77e503c6abd0b504bc2..75b6c93659362911ae342ad4ddf9179e37e15c99 100644 --- a/ecmascript/builtins/tests/builtins_date_test.cpp +++ b/ecmascript/builtins/tests/builtins_date_test.cpp @@ -79,9 +79,9 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetDate) ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - [[maybe_unused]] JSTaggedValue result1 = BuiltinsDate::SetDate(ecmaRuntimeCallInfo.get()); - JSTaggedValue result2 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + [[maybe_unused]] JSTaggedValue result1 = BuiltinsDate::SetDate(ecmaRuntimeCallInfo); + JSTaggedValue result2 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -94,9 +94,9 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCDate) ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - [[maybe_unused]] JSTaggedValue result3 = BuiltinsDate::SetUTCDate(ecmaRuntimeCallInfo.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + [[maybe_unused]] JSTaggedValue result3 = BuiltinsDate::SetUTCDate(ecmaRuntimeCallInfo); + JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -109,9 +109,9 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMinusUTCDate) ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - [[maybe_unused]] JSTaggedValue result3 = BuiltinsDate::SetUTCDate(ecmaRuntimeCallInfo.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + [[maybe_unused]] JSTaggedValue result3 = BuiltinsDate::SetUTCDate(ecmaRuntimeCallInfo); + JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(29)).GetRawData()); } @@ -129,17 +129,17 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetFullYear) // 2, 6 : test case ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo); // 2018 : test case ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo); // 10 : test case ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo); // 6 : test case ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); } @@ -158,17 +158,17 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCFullYear) // 2, 6 : test case ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCFullYear(ecmaRuntimeCallInfo.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCFullYear(ecmaRuntimeCallInfo); + JSTaggedValue result4 = BuiltinsDate::GetUTCFullYear(ecmaRuntimeCallInfo); // 2018 : test case ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result5 = BuiltinsDate::GetUTCMonth(ecmaRuntimeCallInfo.get()); + JSTaggedValue result5 = BuiltinsDate::GetUTCMonth(ecmaRuntimeCallInfo); // 10 : test case ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result6 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo); // 6 : test case ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); } @@ -183,15 +183,15 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMinusFullYear) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-10))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-2019)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(1)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(22)).GetRawData()); } @@ -206,15 +206,15 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMinusUTCFullYear) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-10))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCFullYear(ecmaRuntimeCallInfo.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCFullYear(ecmaRuntimeCallInfo); + JSTaggedValue result4 = BuiltinsDate::GetUTCFullYear(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(-2019)).GetRawData()); - JSTaggedValue result5 = BuiltinsDate::GetUTCMonth(ecmaRuntimeCallInfo.get()); + JSTaggedValue result5 = BuiltinsDate::GetUTCMonth(ecmaRuntimeCallInfo); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(1)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result6 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(22)).GetRawData()); } @@ -230,18 +230,18 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetHours) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetHours(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetHours(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetHours(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetHours(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(18)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMinutes(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetMinutes(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -257,18 +257,18 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCHours) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCHours(ecmaRuntimeCallInfo.get()); - JSTaggedValue result5 = BuiltinsDate::GetUTCHours(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCHours(ecmaRuntimeCallInfo); + JSTaggedValue result5 = BuiltinsDate::GetUTCHours(ecmaRuntimeCallInfo); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(18)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCMinutes(ecmaRuntimeCallInfo.get()); + JSTaggedValue result6 = BuiltinsDate::GetUTCMinutes(ecmaRuntimeCallInfo); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result7 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result7 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result8 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result8 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result8.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -284,18 +284,18 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMinusHours) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(-111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetHours(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetHours(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetHours(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetHours(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMinutes(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetMinutes(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(49)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(53)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(889)).GetRawData()); } @@ -311,18 +311,18 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMinusUTCHours) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(-6))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(-111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCHours(ecmaRuntimeCallInfo.get()); - JSTaggedValue result5 = BuiltinsDate::GetUTCHours(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCHours(ecmaRuntimeCallInfo); + JSTaggedValue result5 = BuiltinsDate::GetUTCHours(ecmaRuntimeCallInfo); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(5)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCMinutes(ecmaRuntimeCallInfo.get()); + JSTaggedValue result6 = BuiltinsDate::GetUTCMinutes(ecmaRuntimeCallInfo); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(49)).GetRawData()); - JSTaggedValue result7 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result7 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(53)).GetRawData()); - JSTaggedValue result8 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result8 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result8.GetRawData(), JSTaggedValue(static_cast(889)).GetRawData()); } @@ -335,11 +335,11 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMilliseconds) ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(100))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::SetMilliseconds(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::SetMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); } @@ -352,11 +352,11 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCMilliseconds) ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(100))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result3 = BuiltinsDate::SetUTCMilliseconds(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result3 = BuiltinsDate::SetUTCMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(100)).GetRawData()); } @@ -371,15 +371,15 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMinutes) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(6))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetMinutes(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetMinutes(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetMinutes(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetMinutes(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result3 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result3 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -394,15 +394,15 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCMinutes) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(6))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(111))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCMinutes(ecmaRuntimeCallInfo.get()); - JSTaggedValue result4 = BuiltinsDate::GetUTCMinutes(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCMinutes(ecmaRuntimeCallInfo); + JSTaggedValue result4 = BuiltinsDate::GetUTCMinutes(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); - JSTaggedValue result5 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result5 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result5.GetRawData(), JSTaggedValue(static_cast(6)).GetRawData()); - JSTaggedValue result6 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result6 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(111)).GetRawData()); } @@ -416,12 +416,12 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetMonth) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetMonth(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetMonth(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(8)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetDate(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(3)).GetRawData()); } @@ -435,12 +435,12 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCMonth) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(8))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCMonth(ecmaRuntimeCallInfo.get()); - JSTaggedValue result3 = BuiltinsDate::GetUTCMonth(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCMonth(ecmaRuntimeCallInfo); + JSTaggedValue result3 = BuiltinsDate::GetUTCMonth(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(8)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = BuiltinsDate::GetUTCDate(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(3)).GetRawData()); } @@ -454,12 +454,12 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetSeconds) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(59))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetSeconds(ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetSeconds(ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::GetSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(59)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(123)).GetRawData()); } @@ -473,12 +473,12 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetUTCSeconds) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(59))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetUTCSeconds(ecmaRuntimeCallInfo.get()); - JSTaggedValue result3 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetUTCSeconds(ecmaRuntimeCallInfo); + JSTaggedValue result3 = BuiltinsDate::GetUTCSeconds(ecmaRuntimeCallInfo); ASSERT_EQ(result3.GetRawData(), JSTaggedValue(static_cast(59)).GetRawData()); - JSTaggedValue result4 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo.get()); + JSTaggedValue result4 = BuiltinsDate::GetUTCMilliseconds(ecmaRuntimeCallInfo); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(123)).GetRawData()); } @@ -491,11 +491,11 @@ HWTEST_F_L0(BuiltinsDateTest, SetGetTime) ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::SetTime(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::SetTime(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); - JSTaggedValue result2 = BuiltinsDate::GetTime(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsDate::GetTime(ecmaRuntimeCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(static_cast(2)).GetRawData()); } @@ -509,8 +509,8 @@ HWTEST_F_L0(BuiltinsDateTest, UTC) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(4.32)); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(11.32)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604487600000)).GetRawData()); @@ -525,8 +525,8 @@ HWTEST_F_L0(BuiltinsDateTest, UTC) ecmaRuntimeCallInfo1->SetCallArg(5, JSTaggedValue(34.321)); ecmaRuntimeCallInfo1->SetCallArg(6, JSTaggedValue(static_cast(231))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604490334231)).GetRawData()); @@ -537,8 +537,8 @@ HWTEST_F_L0(BuiltinsDateTest, UTC) ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue(4.32)); ecmaRuntimeCallInfo2->SetCallArg(2, JSTaggedValue(11.32)); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-1882224000000)).GetRawData()); @@ -547,8 +547,8 @@ HWTEST_F_L0(BuiltinsDateTest, UTC) ecmaRuntimeCallInfo3->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(1994.982)); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(757382400000)).GetRawData()); @@ -557,8 +557,8 @@ HWTEST_F_L0(BuiltinsDateTest, UTC) ecmaRuntimeCallInfo4->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(19999944.982)); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + result1 = BuiltinsDate::UTC(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(base::NAN_VALUE)).GetRawData()); } @@ -575,8 +575,8 @@ void SetAllYearAndHours(JSThread *thread, const JSHandle &jsDate) // 2, 6 : test case ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(6))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 12); @@ -591,8 +591,8 @@ void SetAllYearAndHours(JSThread *thread, const JSHandle &jsDate) // 3, 111 : test case ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(static_cast(111))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsDate::SetHours(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsDate::SetHours(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); } @@ -608,8 +608,8 @@ void SetAll1(JSThread *thread, const JSHandle &jsDate) // 2, 31 : test case ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(31))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 12); @@ -624,8 +624,8 @@ void SetAll1(JSThread *thread, const JSHandle &jsDate) // 3, 888 : test case ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(static_cast(888))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsDate::SetHours(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsDate::SetHours(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); } @@ -638,8 +638,8 @@ void SetAll2(JSThread *thread, const JSHandle &jsDate) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(1))); // 2 : test case - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); // 12 : test case @@ -651,8 +651,8 @@ void SetAll2(JSThread *thread, const JSHandle &jsDate) ecmaRuntimeCallInfo1->SetCallArg(2, JSTaggedValue(static_cast(21))); // 2, 21 : test case ecmaRuntimeCallInfo1->SetCallArg(3, JSTaggedValue(static_cast(129))); // 3, 129 : test case - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsDate::SetHours(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsDate::SetHours(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); } @@ -665,8 +665,8 @@ HWTEST_F_L0(BuiltinsDateTest, parse) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298132)).GetRawData()); JSHandle str1 = thread->GetEcmaVM()->GetFactory()->NewFromASCII("2020-11-19Z"); @@ -675,8 +675,8 @@ HWTEST_F_L0(BuiltinsDateTest, parse) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, str1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605744000000)).GetRawData()); @@ -687,8 +687,8 @@ HWTEST_F_L0(BuiltinsDateTest, parse) ecmaRuntimeCallInfo2->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetCallArg(0, str2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1604204297231)).GetRawData()); @@ -699,8 +699,8 @@ HWTEST_F_L0(BuiltinsDateTest, parse) ecmaRuntimeCallInfo3->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo3->SetCallArg(0, str3.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298000)).GetRawData()); @@ -711,8 +711,8 @@ HWTEST_F_L0(BuiltinsDateTest, parse) ecmaRuntimeCallInfo4->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo4->SetCallArg(0, str4.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(3894841080000)).GetRawData()); @@ -721,8 +721,8 @@ HWTEST_F_L0(BuiltinsDateTest, parse) ecmaRuntimeCallInfo5->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo5->SetCallArg(0, JSTaggedValue::Null()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5.get()); - result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo5.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5); + result1 = BuiltinsDate::Parse(ecmaRuntimeCallInfo5); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(base::NAN_VALUE)).GetRawData()); } @@ -738,8 +738,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToDateString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDate::ToDateString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDate::ToDateString(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -756,8 +756,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToISOString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ToISOString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ToISOString(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); @@ -774,8 +774,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToISOStringMinus) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ToISOString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ToISOString(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); @@ -792,8 +792,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToJSON) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ToJSON(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ToJSON(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); @@ -809,8 +809,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToJSONMinus) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ToJSON(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ToJSON(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -826,7 +826,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); SetAllYearAndHours(thread, jsDate); if (static_cast(JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->GetTimeValue().GetDouble()) < @@ -842,7 +842,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToString) } localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - JSTaggedValue result1 = BuiltinsDate::ToString(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsDate::ToString(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); TestHelper::TearDownFrame(thread, prev); JSHandle result1_val(thread, reinterpret_cast(result1.GetRawData())); @@ -854,7 +854,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToString) auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(js_date1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); SetAll1(thread, js_date1); localTime = ""; @@ -872,7 +872,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToString) } localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - JSTaggedValue result2 = BuiltinsDate::ToString(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = BuiltinsDate::ToString(ecmaRuntimeCallInfo1); ASSERT_TRUE(result2.IsString()); TestHelper::TearDownFrame(thread, prev); JSHandle result2_val(thread, reinterpret_cast(result2.GetRawData())); @@ -884,7 +884,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToString) auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(js_date2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); SetAll2(thread, js_date2); localTime = ""; @@ -902,7 +902,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToString) } localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - JSTaggedValue result3 = BuiltinsDate::ToString(ecmaRuntimeCallInfo2.get()); + JSTaggedValue result3 = BuiltinsDate::ToString(ecmaRuntimeCallInfo2); ASSERT_TRUE(result3.IsString()); TestHelper::TearDownFrame(thread, prev); JSHandle result3_val(thread, reinterpret_cast(result3.GetRawData())); @@ -922,7 +922,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToTimeString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); SetAllYearAndHours(thread, jsDate); if (static_cast(JSDate::Cast(jsDate.GetTaggedValue().GetTaggedObject())->GetTimeValue().GetDouble()) < @@ -938,7 +938,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToTimeString) } localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - JSTaggedValue result1 = BuiltinsDate::ToTimeString(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsDate::ToTimeString(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); JSHandle result1_val(thread, reinterpret_cast(result1.GetRawData())); CString str = "18:10:06 GMT" + localTime; @@ -949,7 +950,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToTimeString) auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(js_date1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); SetAll1(thread, js_date1); localTime = ""; localMin = JSDate::GetLocalOffsetFromOS(localMin, true); @@ -966,7 +967,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToTimeString) } localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - JSTaggedValue result2 = BuiltinsDate::ToTimeString(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result2 = BuiltinsDate::ToTimeString(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result2.IsString()); JSHandle result2_val(thread, reinterpret_cast(result2.GetRawData())); str = "23:54:16 GMT" + localTime; @@ -976,7 +978,7 @@ HWTEST_F_L0(BuiltinsDateTest, ToTimeString) auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(js_date2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); SetAll2(thread, js_date2); localTime = ""; localMin = JSDate::GetLocalOffsetFromOS(localMin, true); @@ -993,7 +995,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToTimeString) } localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin / MINUTE_PER_HOUR), STR_LENGTH_OTHERS); localTime = localTime + JSDate::StrToTargetLength(ToCString(localMin % MINUTE_PER_HOUR), STR_LENGTH_OTHERS); - JSTaggedValue result3 = BuiltinsDate::ToTimeString(ecmaRuntimeCallInfo2.get()); + JSTaggedValue result3 = BuiltinsDate::ToTimeString(ecmaRuntimeCallInfo2); + TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result3.IsString()); JSHandle result3_val(thread, reinterpret_cast(result3.GetRawData())); str = "00:03:21 GMT" + localTime; @@ -1011,8 +1014,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToUTCString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -1027,8 +1030,8 @@ HWTEST_F_L0(BuiltinsDateTest, ToUTCStringMinus) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ToUTCString(ecmaRuntimeCallInfo); ASSERT_TRUE(result1.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result1.GetRawData()), *expect_value)); } @@ -1041,8 +1044,8 @@ HWTEST_F_L0(BuiltinsDateTest, ValueOf) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ValueOf(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(1605788298132)).GetRawData()); } @@ -1054,8 +1057,8 @@ HWTEST_F_L0(BuiltinsDateTest, ValueOfMinus) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDate.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsDate::ValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsDate::ValueOf(ecmaRuntimeCallInfo); ASSERT_EQ(result1.GetRawData(), JSTaggedValue(static_cast(-4357419161618)).GetRawData()); } @@ -1069,8 +1072,8 @@ HWTEST_F_L0(BuiltinsDateTest, DateConstructor) ecmaRuntimeCallInfo1->SetFunction(date_func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsString()); @@ -1079,8 +1082,8 @@ HWTEST_F_L0(BuiltinsDateTest, DateConstructor) ecmaRuntimeCallInfo2->SetFunction(date_func.GetTaggedValue()); ecmaRuntimeCallInfo2->SetThis(jsDate.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result2.IsObject()); @@ -1090,13 +1093,13 @@ HWTEST_F_L0(BuiltinsDateTest, DateConstructor) ecmaRuntimeCallInfo3->SetThis(jsDate.GetTaggedValue()); ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(2018))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result3 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result3 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result3.IsObject()); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo3.get()); - JSTaggedValue result4 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo3.get()); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo3); + JSTaggedValue result4 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo3); ASSERT_EQ(result4.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); // case3: length > 1 @@ -1106,15 +1109,16 @@ HWTEST_F_L0(BuiltinsDateTest, DateConstructor) ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(2018))); ecmaRuntimeCallInfo4->SetCallArg(1, JSTaggedValue(static_cast(10))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - JSTaggedValue result5 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + JSTaggedValue result5 = BuiltinsDate::DateConstructor(ecmaRuntimeCallInfo4); ASSERT_TRUE(result5.IsObject()); SetAllYearAndHours(thread, jsDate); - BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo4.get()); - JSTaggedValue result6 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo4.get()); + BuiltinsDate::SetFullYear(ecmaRuntimeCallInfo4); + TestHelper::TearDownFrame(thread, prev); + JSTaggedValue result6 = BuiltinsDate::GetFullYear(ecmaRuntimeCallInfo4); ASSERT_EQ(result6.GetRawData(), JSTaggedValue(static_cast(2018)).GetRawData()); - JSTaggedValue result7 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo4.get()); + JSTaggedValue result7 = BuiltinsDate::GetMonth(ecmaRuntimeCallInfo4); ASSERT_EQ(result7.GetRawData(), JSTaggedValue(static_cast(10)).GetRawData()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_date_time_format_test.cpp b/ecmascript/builtins/tests/builtins_date_time_format_test.cpp index f9cb5d0cea966231cbfd8d5dc88faa6a458afbb2..ca240dbe2dc2690be1117a5193d047fe3254b09e 100644 --- a/ecmascript/builtins/tests/builtins_date_time_format_test.cpp +++ b/ecmascript/builtins/tests/builtins_date_time_format_test.cpp @@ -77,8 +77,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, DateTimeFormatConstructor) // option tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::DateTimeFormatConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::DateTimeFormatConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSDateTimeFormat()); } @@ -136,9 +136,10 @@ static JSTaggedValue JSDateTimeFormatCreateWithLocaleTest(JSThread *thread, JSHa ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::DateTimeFormatConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::DateTimeFormatConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsJSDateTimeFormat()); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -163,8 +164,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, Format_001) ecmaRuntimeCallInfo1->SetThis(jsDateTimeFormat.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsDateTimeFormat::Format(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDateTimeFormat::Format(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); // jsDate supports zero to eleven, the month should be added with one JSHandle jsFunction(thread, result1); @@ -183,8 +184,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, Format_001) ecmaRuntimeCallInfo2->SetThis(jsObject.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, value.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsArray::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsArray::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); JSHandle resultStr(thread, result2); EXPECT_STREQ("Sun, 11/1/2020, 24:00:00", CString(resultStr->GetCString().get()).c_str()); @@ -203,8 +204,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, Format_002) ecmaRuntimeCallInfo1->SetThis(jsDateTimeFormat.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsDateTimeFormat::Format(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsDateTimeFormat::Format(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle jsFunction(thread, result1); @@ -223,8 +224,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, Format_002) ecmaRuntimeCallInfo2->SetThis(jsObject.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, value.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsArray::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsArray::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); JSHandle resultStr(thread, result2); CString resStr = resultStr->GetCString().get(); @@ -246,8 +247,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, FormatToParts) ecmaRuntimeCallInfo->SetThis(jsDateTimeFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); @@ -271,8 +272,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, FormatRange_001) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(days1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(days2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::FormatRange(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::FormatRange(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleStr(thread, result); @@ -296,8 +297,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, FormatRange_002) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(days1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(days2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::FormatRange(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::FormatRange(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleStr(thread, result); @@ -320,8 +321,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, FormatRangeToParts) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(days1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(days2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::FormatRangeToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::FormatRangeToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); @@ -341,8 +342,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, ResolvedOptions) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDateTimeFormat.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDateTimeFormat::ResolvedOptions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDateTimeFormat::ResolvedOptions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj = @@ -371,8 +372,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, SupportedLocalesOf_001) // set the tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsDateTimeFormat::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsDateTimeFormat::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); @@ -403,8 +404,8 @@ HWTEST_F_L0(BuiltinsDateTimeFormatTest, SupportedLocalesOf_002) ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsDateTimeFormat::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsDateTimeFormat::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); diff --git a/ecmascript/builtins/tests/builtins_displaynames_test.cpp b/ecmascript/builtins/tests/builtins_displaynames_test.cpp index 3250778354ae4ebef138af9add82a7e77fce714c..ae410b951166eb0459787090b8645d588a8f45c1 100644 --- a/ecmascript/builtins/tests/builtins_displaynames_test.cpp +++ b/ecmascript/builtins/tests/builtins_displaynames_test.cpp @@ -86,8 +86,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, DisplayNamesConstructor) ecmaRuntimeCallInfo->SetCallArg(0, localeString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDisplayNames::DisplayNamesConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDisplayNames::DisplayNamesConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSDisplayNames()); } @@ -111,8 +111,8 @@ static JSTaggedValue JSDisplayNamesCreateWithOptionTest(JSThread *thread, JSHand ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDisplayNames::DisplayNamesConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDisplayNames::DisplayNamesConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSDisplayNames()); @@ -134,8 +134,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, Of_001) ecmaRuntimeCallInfo->SetThis(jsDisplayNames.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, stringValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDisplayNames::Of(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDisplayNames::Of(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -158,8 +158,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, Of_002) ecmaRuntimeCallInfo->SetThis(jsDisplayNames.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, stringValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDisplayNames::Of(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDisplayNames::Of(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -182,8 +182,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, Of_003) ecmaRuntimeCallInfo->SetThis(jsDisplayNames.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, stringValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDisplayNames::Of(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDisplayNames::Of(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -204,8 +204,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, SupportedLocalesOf_001) // set the tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsDisplayNames::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsDisplayNames::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); @@ -234,8 +234,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, SupportedLocalesOf_002) ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsDisplayNames::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsDisplayNames::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); @@ -258,8 +258,8 @@ HWTEST_F_L0(BuiltinsDisplayNamesTest, ResolvedOptions) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsDisplayNames.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsDisplayNames::ResolvedOptions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsDisplayNames::ResolvedOptions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj = diff --git a/ecmascript/builtins/tests/builtins_errors_test.cpp b/ecmascript/builtins/tests/builtins_errors_test.cpp index 7639a9442635426ec7a9dd16334d227f717c5dce..0eca50e45b43ad1b7868c7fb987493bf5b4d9654 100644 --- a/ecmascript/builtins/tests/builtins_errors_test.cpp +++ b/ecmascript/builtins/tests/builtins_errors_test.cpp @@ -145,8 +145,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = Error::ErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = Error::ErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); @@ -185,8 +185,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = Error::ErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = Error::ErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); @@ -224,8 +224,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = Error::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = Error::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -257,8 +257,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = Error::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = Error::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -284,8 +284,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = RangeError::RangeErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = RangeError::RangeErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); @@ -323,8 +323,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = RangeError::RangeErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = RangeError::RangeErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); @@ -362,8 +362,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = RangeError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = RangeError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, result); EXPECT_TRUE(result.IsString()); @@ -395,8 +395,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, RangeErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = RangeError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = RangeError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -420,8 +420,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -459,8 +459,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = ReferenceError::ReferenceErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -496,8 +496,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = ReferenceError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = ReferenceError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( @@ -527,8 +527,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, ReferenceErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = ReferenceError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = ReferenceError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(factory->NewFromASCII("ReferenceError: This is ReferenceError!")->Compare(*resultHandle), @@ -551,8 +551,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = TypeError::TypeErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = TypeError::TypeErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -589,8 +589,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = TypeError::TypeErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = TypeError::TypeErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -627,8 +627,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = TypeError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = TypeError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( @@ -658,8 +658,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, TypeErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = TypeError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = TypeError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(factory->NewFromASCII("TypeError: This is TypeError!")->Compare(*resultHandle), 0); @@ -681,8 +681,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, URIErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = URIError::URIErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = URIError::URIErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -720,8 +720,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, URIErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = URIError::URIErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = URIError::URIErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -758,8 +758,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, URIErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = URIError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = URIError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -791,8 +791,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, URIErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = URIError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = URIError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -819,8 +819,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -858,8 +858,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = SyntaxError::SyntaxErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -896,8 +896,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = SyntaxError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = SyntaxError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -928,8 +928,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, SyntaxErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = SyntaxError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = SyntaxError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); @@ -952,8 +952,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorNoParameterConstructor) ecmaRuntimeCallInfo->SetFunction(error.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = EvalError::EvalErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = EvalError::EvalErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -991,8 +991,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorParameterConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = EvalError::EvalErrorConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = EvalError::EvalErrorConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsECMAObject()); JSHandle errorObject(thread, reinterpret_cast(result.GetRawData())); @@ -1028,8 +1028,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = EvalError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = EvalError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(reinterpret_cast( @@ -1060,8 +1060,8 @@ HWTEST_F_L0(BuiltinsErrorsTest, EvalErrorToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue(*error)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = EvalError::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = EvalError::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); EXPECT_TRUE(result.IsString()); EXPECT_EQ(factory->NewFromASCII("EvalError: This is EvalError!")->Compare(*resultHandle), 0); diff --git a/ecmascript/builtins/tests/builtins_finalizationregistry_test.cpp b/ecmascript/builtins/tests/builtins_finalizationregistry_test.cpp index 7a864ddfe500a734a24477fb6842985a81e2ed17..c4b62e1dea1bee6e4d4b20325a5752c7ea90d24f 100644 --- a/ecmascript/builtins/tests/builtins_finalizationregistry_test.cpp +++ b/ecmascript/builtins/tests/builtins_finalizationregistry_test.cpp @@ -89,8 +89,10 @@ JSTaggedValue CreateFinalizationRegistryConstructor(JSThread *thread) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, handleFunc.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - return JSTaggedValue(BuiltinsFinalizationRegistry::FinalizationRegistryConstructor(ecmaRuntimeCallInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue res = BuiltinsFinalizationRegistry::FinalizationRegistryConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + return res; } // new FinalizationRegistry (cleanupCallback) @@ -107,8 +109,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, FinalizationRegistryConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, handleFunc.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFinalizationRegistry::FinalizationRegistryConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFinalizationRegistry::FinalizationRegistryConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); } @@ -133,8 +135,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register0) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); ASSERT_EQ(testValue, 0); } @@ -160,8 +162,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); ASSERT_EQ(testValue, 0); } @@ -181,7 +183,7 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register2) { [[maybe_unused]] EcmaHandleScope handleScope(thread); auto obj = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); target = obj.GetTaggedValue(); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); @@ -190,8 +192,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); } vm->CollectGarbage(TriggerGCType::FULL_GC); @@ -220,9 +222,9 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register3) { [[maybe_unused]] EcmaHandleScope handleScope(thread); auto obj = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); auto obj1 = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); target = obj.GetTaggedValue(); target1 = obj1.GetTaggedValue(); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); @@ -232,8 +234,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register3) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); @@ -243,8 +245,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register3) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo1->SetCallArg(2, target1); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev1); } vm->CollectGarbage(TriggerGCType::FULL_GC); @@ -274,9 +276,9 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register4) { [[maybe_unused]] EcmaHandleScope handleScope(thread); auto obj = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); auto obj1 = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); target = obj.GetTaggedValue(); target1 = obj1.GetTaggedValue(); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); @@ -286,8 +288,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register4) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); @@ -297,8 +299,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register4) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo1->SetCallArg(2, target1); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev1); } vm->CollectGarbage(TriggerGCType::FULL_GC); @@ -326,9 +328,9 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register5) { [[maybe_unused]] EcmaHandleScope handleScope(thread); auto obj = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); auto obj1 = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); target = obj.GetTaggedValue(); target1 = obj1.GetTaggedValue(); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); @@ -338,8 +340,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register5) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); @@ -349,8 +351,8 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Register5) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo1->SetCallArg(2, target); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev1); } vm->CollectGarbage(TriggerGCType::FULL_GC); @@ -383,16 +385,17 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Unregister1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsfinalizationRegistry.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsFinalizationRegistry::Unregister(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsFinalizationRegistry::Unregister(ecmaRuntimeCallInfo1); ASSERT_EQ(testValue, 0); } @@ -411,7 +414,7 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Unregister2) { [[maybe_unused]] EcmaHandleScope handleScope(thread); auto obj = - factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); target = obj.GetTaggedValue(); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 10); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); @@ -420,15 +423,15 @@ HWTEST_F_L0(BuiltinsFinalizationRegistryTest, Unregister2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(10)); ecmaRuntimeCallInfo->SetCallArg(2, target); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + BuiltinsFinalizationRegistry::Register(ecmaRuntimeCallInfo); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsfinalizationRegistry.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, target); - BuiltinsFinalizationRegistry::Unregister(ecmaRuntimeCallInfo1.get()); + BuiltinsFinalizationRegistry::Unregister(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); } vm->CollectGarbage(TriggerGCType::FULL_GC); diff --git a/ecmascript/builtins/tests/builtins_function_test.cpp b/ecmascript/builtins/tests/builtins_function_test.cpp index c7a4d321d561bfc6836e399527193a7fa3b75039..1d4495fd4e867bd0635a430f42b7cb3004d2b573 100644 --- a/ecmascript/builtins/tests/builtins_function_test.cpp +++ b/ecmascript/builtins/tests/builtins_function_test.cpp @@ -68,7 +68,7 @@ JSTaggedValue TestFunctionApplyAndCall(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; - for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { + for (int32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += BuiltinsBase::GetCallArg(argv, index)->GetInt(); } JSHandle thisValue(BuiltinsBase::GetThis(argv)); @@ -111,8 +111,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeApply) ecmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeApply(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeApply(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); @@ -155,8 +155,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeApply1) ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); ecmaRuntimeCallInfo->SetCallArg(1, array.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeApply(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeApply(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(100).GetRawData()); @@ -186,8 +186,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeBind) ecmaRuntimeCallInfo->SetThis(target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); @@ -235,8 +235,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeBind1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); @@ -291,8 +291,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeBind2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(123))); ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeBind(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); @@ -348,8 +348,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeCall) ecmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, (thisArg.GetTaggedValue())); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeCall(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeCall(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(3).GetRawData()); @@ -387,8 +387,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeCall1) ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(456))); ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(static_cast(789))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsFunction::FunctionPrototypeCall(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsFunction::FunctionPrototypeCall(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1371).GetRawData()); @@ -409,8 +409,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeHasInstance) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(123))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle booleanInstance(thread, result); @@ -420,8 +420,8 @@ HWTEST_F_L0(BuiltinsFunctionTest, FunctionPrototypeHasInstance) ecmaRuntimeCallInfo2->SetThis(booleanCtor.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, booleanInstance.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - EXPECT_TRUE(BuiltinsFunction::FunctionPrototypeHasInstance(ecmaRuntimeCallInfo2.get()).GetRawData()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + EXPECT_TRUE(BuiltinsFunction::FunctionPrototypeHasInstance(ecmaRuntimeCallInfo2).GetRawData()); TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_intl_test.cpp b/ecmascript/builtins/tests/builtins_intl_test.cpp index f7a9d94c03cfa262ea0451c7b0ce30efb45dce7a..96d343d7965418667d3ff03bcde0186f12dbb290 100644 --- a/ecmascript/builtins/tests/builtins_intl_test.cpp +++ b/ecmascript/builtins/tests/builtins_intl_test.cpp @@ -66,8 +66,8 @@ HWTEST_F_L0(BuiltinsIntlTest, GetCanonicalLocales_001) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, resultObj); EXPECT_EQ(resultHandle->GetArrayLength(), 0U); } @@ -82,8 +82,8 @@ HWTEST_F_L0(BuiltinsIntlTest, GetCanonicalLocales_002) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, handleStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, resultObj); JSHandle elements(thread, resultHandle->GetElements()); @@ -109,8 +109,8 @@ HWTEST_F_L0(BuiltinsIntlTest, GetCanonicalLocales_003) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultObj = BuiltinsIntl::GetCanonicalLocales(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, resultObj); JSHandle elements(thread, resultHandle->GetElements()); diff --git a/ecmascript/builtins/tests/builtins_json_test.cpp b/ecmascript/builtins/tests/builtins_json_test.cpp index bebbeb08a2ac195bedba2c5f07b5eb8bbd04e819..9cffeb204beabb054287f5d1980cd4fd4e924649 100644 --- a/ecmascript/builtins/tests/builtins_json_test.cpp +++ b/ecmascript/builtins/tests/builtins_json_test.cpp @@ -18,6 +18,7 @@ #include "algorithm" #include "ecmascript/base/builtins_base.h" +#include "ecmascript/builtins/builtins_bigint.h" #include "ecmascript/builtins/builtins_errors.h" #include "ecmascript/builtins/builtins_json.h" #include "ecmascript/builtins/builtins_proxy.h" @@ -71,7 +72,7 @@ public: public: static JSTaggedValue TestForParse(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { } JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); @@ -88,7 +89,7 @@ public: static JSTaggedValue TestForParse1(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { } return JSTaggedValue::Undefined(); @@ -96,7 +97,7 @@ public: static JSTaggedValue TestForStringfy(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { JSTaggedValue key = GetCallArg(argv, 0).GetTaggedValue(); if (key.IsUndefined()) { @@ -156,8 +157,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Parse10) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); } @@ -177,8 +178,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Parse21) ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); } @@ -195,8 +196,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Parse) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle valueHandle(thread, value); @@ -217,8 +218,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Parse2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle valueHandle(thread, value); @@ -243,8 +244,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Parse3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo); uint32_t length = EcmaString::Cast(result.GetTaggedObject())->GetLength(); ASSERT_EQ(length, 1U); } @@ -260,8 +261,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Parse4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Parse(ecmaRuntimeCallInfo); JSHandle value = JSTaggedValue::GetProperty(thread, JSHandle(thread, result), JSHandle(key)) .GetValue(); @@ -284,8 +285,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify11) ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -304,8 +305,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify12) ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -326,8 +327,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify13) ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -355,8 +356,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify14) ecmaRuntimeCallInfo->SetCallArg(1, obj1.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -368,8 +369,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -408,8 +409,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify1) ecmaRuntimeCallInfo->SetCallArg(1, handleFunc.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -439,8 +440,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); } @@ -459,8 +460,8 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(EcmaString::StringsAreEqual(*test, EcmaString::Cast(result.GetTaggedObject()))); } @@ -489,8 +490,9 @@ JSHandle CreateProxy(JSThread *thread) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, handler.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsProxy::ProxyConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsProxy::ProxyConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return JSHandle(thread, result); } @@ -507,12 +509,13 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify4) // Test for proxy object ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, proxy.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); ASSERT_TRUE(EcmaString::StringsAreEqual(*test, EcmaString::Cast(result.GetTaggedObject()))); + TestHelper::TearDownFrame(thread, prev); } -HWTEST_F_L0(BuiltinsJsonTest, Stringify5) // Test for proxy object +HWTEST_F_L0(BuiltinsJsonTest, Stringify5) // Test for typedarray object { auto ecmaVM = thread->GetEcmaVM(); ObjectFactory *factory = ecmaVM->GetFactory(); @@ -530,8 +533,9 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify5) // Test for proxy object ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(*globalObject)); ecmaRuntimeCallInfo1->SetCallArg(0, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSHandle int8Array(thread, BuiltinsTypedArray::Int8ArrayConstructor(ecmaRuntimeCallInfo1.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSHandle int8Array(thread, BuiltinsTypedArray::Int8ArrayConstructor(ecmaRuntimeCallInfo1)); + TestHelper::TearDownFrame(thread, prev); JSHandle test = factory->NewFromStdString("{\"0\":2,\"1\":3,\"2\":4}"); @@ -540,9 +544,39 @@ HWTEST_F_L0(BuiltinsJsonTest, Stringify5) // Test for proxy object ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, int8Array.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(*test, EcmaString::Cast(result.GetTaggedObject()))); } + +HWTEST_F_L0(BuiltinsJsonTest, Stringify6) // Test for bigint object +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle numericValue(factory->NewFromASCII("123456789123456789")); + + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, numericValue.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsBigInt::BigIntConstructor(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); + + JSHandle bigIntHandle(thread, result1); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, bigIntHandle.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsJson::Stringify(ecmaRuntimeCallInfo); + CString str = ConvertToString(EcmaString::Cast(result.GetTaggedObject())); + ASSERT_TRUE(result.IsString()); + ASSERT_TRUE(EcmaString::StringsAreEqual(EcmaString::Cast(numericValue.GetTaggedValue().GetTaggedObject()), + EcmaString::Cast(result.GetTaggedObject()))); +} } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_list_format_test.cpp b/ecmascript/builtins/tests/builtins_list_format_test.cpp index 4b62c1469ca4a72a15663c3e044af3e3eac1cc61..0226d227d84da2386aa5cf6e4f32e23792ad64de 100644 --- a/ecmascript/builtins/tests/builtins_list_format_test.cpp +++ b/ecmascript/builtins/tests/builtins_list_format_test.cpp @@ -75,8 +75,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, ListFormatConstructor) // option tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::ListFormatConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::ListFormatConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSListFormat()); } @@ -99,8 +99,8 @@ static JSTaggedValue JSListFormatCreateWithOptionTest(JSThread *thread, JSHandle ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::ListFormatConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::ListFormatConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSListFormat()); @@ -122,8 +122,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_001) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, listValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -160,8 +160,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_002) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -198,8 +198,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_003) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -228,8 +228,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_004) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -266,8 +266,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, Format_005) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -286,8 +286,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_001) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); @@ -325,8 +325,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_002) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); @@ -364,8 +364,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_003) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSTaggedValue valueList(static_cast(result.GetRawData())); @@ -400,8 +400,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_004) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, result); @@ -444,8 +444,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, FormatToParts_005) ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSTaggedValue valueList(static_cast(result.GetRawData())); @@ -467,8 +467,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, SupportedLocalesOf_001) // set the tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsListFormat::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsListFormat::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); @@ -498,8 +498,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, SupportedLocalesOf_002) ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsListFormat::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsListFormat::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); @@ -523,8 +523,8 @@ HWTEST_F_L0(BuiltinsListFormatTest, ResolvedOptions) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jSListFormat.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsListFormat::ResolvedOptions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsListFormat::ResolvedOptions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj = diff --git a/ecmascript/builtins/tests/builtins_locale_test.cpp b/ecmascript/builtins/tests/builtins_locale_test.cpp index 28c624a7b4a099852782e81e9973972865cf3c4c..71eb275cbc656f3ccb0917500022970e0af36d59 100644 --- a/ecmascript/builtins/tests/builtins_locale_test.cpp +++ b/ecmascript/builtins/tests/builtins_locale_test.cpp @@ -89,8 +89,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, LocaleConstructor) ecmaRuntimeCallInfo->SetCallArg(0, localeString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSLocale()); @@ -142,8 +142,9 @@ static JSTaggedValue JSLocaleCreateWithOptionTest(JSThread *thread) ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -156,8 +157,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, ToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::ToString(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -175,8 +176,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetBaseName) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -192,8 +193,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetHourCycle) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetHourCycle(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetHourCycle(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -209,8 +210,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetCalendar) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetCalendar(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetCalendar(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -226,8 +227,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetCaseFirst) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetCaseFirst(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetCaseFirst(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -243,8 +244,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetCollation) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetCollation(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetCollation(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -260,8 +261,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetNumeric) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetNumeric(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetNumeric(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -275,8 +276,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetNumberingSystem) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetNumberingSystem(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetNumberingSystem(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -292,8 +293,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetLanguage) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetLanguage(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetLanguage(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -309,8 +310,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetScript) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetScript(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetScript(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -326,8 +327,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, GetRegion) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsLocale.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::GetRegion(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::GetRegion(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -355,9 +356,10 @@ static JSTaggedValue JSLocaleCreateWithOptionsTagsTest(JSThread *thread, JSHandl ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsJSLocale()); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -372,8 +374,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Maximize_001) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsLocale.GetTaggedValue()); // test "zh" to "zh-Hans-CN" - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue resultObj = BuiltinsLocale::Maximize(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue resultObj = BuiltinsLocale::Maximize(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultLocale(thread, resultObj); @@ -381,8 +383,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Maximize_001) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(resultLocale.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -399,8 +401,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Maximize_002) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsLocale.GetTaggedValue()); // test "en-Latn-US" to "en-Latn-US" - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue resultObj = BuiltinsLocale::Maximize(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue resultObj = BuiltinsLocale::Maximize(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultLocale(thread, resultObj); @@ -408,8 +410,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Maximize_002) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(resultLocale.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -426,8 +428,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Minimize_001) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsLocale.GetTaggedValue()); // test "en-Latn-US" to "en" - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue resultObj = BuiltinsLocale::Minimize(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue resultObj = BuiltinsLocale::Minimize(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultLocale(thread, resultObj); @@ -435,8 +437,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Minimize_001) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(resultLocale.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result = BuiltinsLocale::GetBaseName(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -455,8 +457,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Minimize_002) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsLocale.GetTaggedValue()); // test "zh" to "zh" - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue resultObj = BuiltinsLocale::Minimize(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue resultObj = BuiltinsLocale::Minimize(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultLocale(thread, resultObj); @@ -464,8 +466,8 @@ HWTEST_F_L0(BuiltinsLocaleTest, Minimize_002) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(resultLocale.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result = BuiltinsLocale::ToString(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result = BuiltinsLocale::ToString(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -494,8 +496,9 @@ HWTEST_F_L0(BuiltinsLocaleTest, NormalizeKeywordValue) ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsLocale::LocaleConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); JSHandle jsInitLocale(thread, result); JSHandle keyWords = JSLocale::NormalizeKeywordValue(thread, jsInitLocale, "kf"); diff --git a/ecmascript/builtins/tests/builtins_map_test.cpp b/ecmascript/builtins/tests/builtins_map_test.cpp index a2500080ea5990969bf1cd7f00471c36f0db6309..0e890bfa2a9e67826ec2890f3bf65412012ad0ae 100644 --- a/ecmascript/builtins/tests/builtins_map_test.cpp +++ b/ecmascript/builtins/tests/builtins_map_test.cpp @@ -87,8 +87,9 @@ JSMap *CreateBuiltinsMap(JSThread *thread) ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMap::MapConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMap::MapConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsECMAObject()); JSMap *jsMap = JSMap::Cast(reinterpret_cast(result.GetRawData())); @@ -108,8 +109,9 @@ HWTEST_F_L0(BuiltinsMapTest, CreateAndGetSize) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMap::GetSize(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMap::GetSize(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -128,8 +130,9 @@ HWTEST_F_L0(BuiltinsMapTest, CreateAndGetSize) ecmaRuntimeCallInfo1->SetCallArg(0, values.GetTaggedValue()); ecmaRuntimeCallInfo1->SetNewTarget(newTarget.GetTaggedValue()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsMap::MapConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsMap::MapConstructor(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(JSMap::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); } @@ -150,13 +153,13 @@ HWTEST_F_L0(BuiltinsMapTest, SetAndHas) JSMap *jsMap; { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsMap::Has(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsMap::Has(ecmaRuntimeCallInfo); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Set() - JSTaggedValue result2 = BuiltinsMap::Set(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsMap::Set(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); jsMap = JSMap::Cast(reinterpret_cast(result2.GetRawData())); @@ -170,8 +173,8 @@ HWTEST_F_L0(BuiltinsMapTest, SetAndHas) ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(1))); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result3 = BuiltinsMap::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result3 = BuiltinsMap::Has(ecmaRuntimeCallInfo1); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -193,8 +196,9 @@ HWTEST_F_L0(BuiltinsMapTest, ForEach) ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(i))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsMap::Set(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsMap::Set(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsECMAObject()); JSMap *jsMap = JSMap::Cast(reinterpret_cast(result1.GetRawData())); EXPECT_EQ(jsMap->GetSize(), static_cast(i) + 1); @@ -209,8 +213,9 @@ HWTEST_F_L0(BuiltinsMapTest, ForEach) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsMap::ForEach(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsMap::ForEach(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(jsArray->GetArrayLength(), 10U); @@ -233,8 +238,9 @@ HWTEST_F_L0(BuiltinsMapTest, DeleteAndRemove) ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(i))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsMap::Set(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsMap::Set(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsECMAObject()); JSMap *jsMap = JSMap::Cast(reinterpret_cast(result1.GetRawData())); @@ -249,26 +255,27 @@ HWTEST_F_L0(BuiltinsMapTest, DeleteAndRemove) ecmaRuntimeCallInfo1->SetThis(map.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, deleteKey.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsMap::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsMap::Has(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsMap::Delete(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = BuiltinsMap::Delete(ecmaRuntimeCallInfo1); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsMap::Has(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result4 = BuiltinsMap::Has(ecmaRuntimeCallInfo1); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); - JSTaggedValue result5 = BuiltinsMap::GetSize(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result5 = BuiltinsMap::GetSize(ecmaRuntimeCallInfo1); EXPECT_EQ(result5.GetRawData(), JSTaggedValue(39).GetRawData()); // clear - JSTaggedValue result6 = BuiltinsMap::Clear(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result6 = BuiltinsMap::Clear(ecmaRuntimeCallInfo1); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(map->GetSize(), 0); } @@ -335,25 +342,26 @@ HWTEST_F_L0(BuiltinsMapTest, GetIterator) auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(map.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // test Values() - JSTaggedValue result = BuiltinsMap::Values(ecmaRuntimeCallInfo.get()); + JSTaggedValue result = BuiltinsMap::Values(ecmaRuntimeCallInfo); JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSMapIterator()); EXPECT_EQ(IterationKind::VALUE, iter->GetIterationKind()); EXPECT_EQ(JSMap::Cast(map.GetTaggedValue().GetTaggedObject())->GetLinkedMap(), iter->GetIteratedMap()); // test Keys() - JSTaggedValue result1 = BuiltinsMap::Keys(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsMap::Keys(ecmaRuntimeCallInfo); JSHandle iter1(thread, result1); EXPECT_TRUE(iter1->IsJSMapIterator()); EXPECT_EQ(IterationKind::KEY, iter1->GetIterationKind()); // test entries() - JSTaggedValue result2 = BuiltinsMap::Entries(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsMap::Entries(ecmaRuntimeCallInfo); JSHandle iter2(thread, result2); EXPECT_TRUE(iter2->IsJSMapIterator()); EXPECT_EQ(IterationKind::KEY_AND_VALUE, iter2->GetIterationKind()); + TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_math_test.cpp b/ecmascript/builtins/tests/builtins_math_test.cpp index 44be99a814c28c6e676529f2d78dede82673afbe..d3f44339b19639af7c4cbb3e7c6934229f97366f 100644 --- a/ecmascript/builtins/tests/builtins_math_test.cpp +++ b/ecmascript/builtins/tests/builtins_math_test.cpp @@ -57,8 +57,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -72,8 +72,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -87,8 +87,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -102,8 +102,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -119,8 +119,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -135,8 +135,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::MAX_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -151,8 +151,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -167,8 +167,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -183,8 +183,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -199,8 +199,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_9) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(testValue)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -214,8 +214,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_10) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -229,8 +229,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_11) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -244,8 +244,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_12) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -259,8 +259,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_13) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Hole()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -275,8 +275,8 @@ HWTEST_F_L0(BuiltinsMathTest, Abs_14) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Abs(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(100.12); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -290,8 +290,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -305,8 +305,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -320,8 +320,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -335,8 +335,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -350,8 +350,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -365,8 +365,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -380,8 +380,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -396,8 +396,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.4706289056333368); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -412,8 +412,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -427,8 +427,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acos_9) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -442,8 +442,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.4435682543851154); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -457,8 +457,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -472,8 +472,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -487,8 +487,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -502,8 +502,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -517,8 +517,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -532,8 +532,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -547,8 +547,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Hole()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -563,8 +563,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -579,8 +579,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_9) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -594,8 +594,8 @@ HWTEST_F_L0(BuiltinsMathTest, Acosh_10) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Acosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -609,8 +609,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -624,8 +624,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -639,8 +639,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -654,8 +654,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -669,8 +669,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -684,8 +684,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -699,8 +699,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -715,8 +715,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -731,8 +731,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asin_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -746,8 +746,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -761,8 +761,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.881373587019543); @@ -777,8 +777,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); @@ -793,8 +793,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -808,8 +808,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -823,8 +823,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.881373587019543); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -838,8 +838,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -854,8 +854,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -870,8 +870,8 @@ HWTEST_F_L0(BuiltinsMathTest, Asinh_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Asinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-2.44122070725561); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -885,8 +885,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -900,8 +900,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -915,8 +915,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -930,8 +930,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -945,8 +945,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI / 2); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -960,8 +960,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -975,8 +975,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -991,8 +991,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1007,8 +1007,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.7853981633974483); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1022,8 +1022,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1037,8 +1037,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1052,8 +1052,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1067,8 +1067,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1082,8 +1082,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1097,8 +1097,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1112,8 +1112,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1128,8 +1128,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1144,8 +1144,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atanh_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1160,8 +1160,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1176,8 +1176,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_1) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.5880026035475675); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1192,8 +1192,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_2) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI / 2); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1208,8 +1208,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_3) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1224,8 +1224,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_4) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(BuiltinsMath::PI); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1240,8 +1240,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_5) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1256,8 +1256,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_6) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-BuiltinsMath::PI); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1272,8 +1272,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_7) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1288,8 +1288,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_8) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1306,8 +1306,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_9) ecmaRuntimeCallInfo->SetCallArg(0, test_1.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, test_2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.5707963267948966); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1324,8 +1324,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_10) ecmaRuntimeCallInfo->SetCallArg(0, test_1.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, test_2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.3091989123270746); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1340,8 +1340,8 @@ HWTEST_F_L0(BuiltinsMathTest, Atan2_11) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Atan2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1355,8 +1355,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1370,8 +1370,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1385,8 +1385,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1400,8 +1400,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1415,8 +1415,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1430,8 +1430,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1445,8 +1445,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1461,8 +1461,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1477,8 +1477,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0714412696907731); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1492,8 +1492,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cbrt_9) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cbrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1507,8 +1507,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(3.25)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1522,8 +1522,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1537,8 +1537,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1552,8 +1552,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1567,8 +1567,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1582,8 +1582,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1597,8 +1597,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1613,8 +1613,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1629,8 +1629,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1644,8 +1644,8 @@ HWTEST_F_L0(BuiltinsMathTest, Ceil_9) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Ceil(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1659,8 +1659,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1674,8 +1674,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1689,8 +1689,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1704,8 +1704,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1719,8 +1719,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.5403023058681398); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1734,8 +1734,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1750,8 +1750,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1766,8 +1766,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cos_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cos(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9960946152060809); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1781,8 +1781,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1796,8 +1796,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1811,8 +1811,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1826,8 +1826,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1841,8 +1841,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5430806348152437); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1856,8 +1856,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1872,8 +1872,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1888,8 +1888,8 @@ HWTEST_F_L0(BuiltinsMathTest, Cosh_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Cosh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(12.659607234875645); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1903,8 +1903,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1918,8 +1918,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1933,8 +1933,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1948,8 +1948,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1963,8 +1963,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(2.718281828459045); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1978,8 +1978,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -1994,8 +1994,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2010,8 +2010,8 @@ HWTEST_F_L0(BuiltinsMathTest, Exp_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Exp(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.039557498788398725); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2025,8 +2025,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2040,8 +2040,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2055,8 +2055,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2070,8 +2070,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2085,8 +2085,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2100,8 +2100,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); double expect = 1.718281828459045; ASSERT_TRUE(result.IsDouble()); @@ -2116,8 +2116,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2132,8 +2132,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2148,8 +2148,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9604425012116012); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2164,8 +2164,8 @@ HWTEST_F_L0(BuiltinsMathTest, Expm1_9) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Expm1(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(65659968.13733051); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2179,8 +2179,8 @@ HWTEST_F_L0(BuiltinsMathTest, Floor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2194,8 +2194,8 @@ HWTEST_F_L0(BuiltinsMathTest, Floor_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2209,8 +2209,8 @@ HWTEST_F_L0(BuiltinsMathTest, Floor_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2224,8 +2224,8 @@ HWTEST_F_L0(BuiltinsMathTest, Floor_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2240,8 +2240,8 @@ HWTEST_F_L0(BuiltinsMathTest, Floor_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Floor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-4.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2255,8 +2255,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2270,8 +2270,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2285,8 +2285,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2300,8 +2300,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2316,8 +2316,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2331,8 +2331,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.12)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-2.120263536200091); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2346,8 +2346,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log1p) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2361,8 +2361,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log1p_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2376,8 +2376,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log1p_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2391,8 +2391,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log1p_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.6931471805599453); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2407,8 +2407,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log1p_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2422,8 +2422,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log1p_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.12)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log1p(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.11332868530700317); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2437,8 +2437,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log10) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2452,8 +2452,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log10_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2467,8 +2467,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log10_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2482,8 +2482,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log10_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2498,8 +2498,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log10_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.3010299956639812); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2513,8 +2513,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log10_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.12)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log10(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9208187539523752); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2528,8 +2528,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2543,8 +2543,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log2_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2558,8 +2558,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log2_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2573,8 +2573,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log2_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2589,8 +2589,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log2_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2604,8 +2604,8 @@ HWTEST_F_L0(BuiltinsMathTest, Log2_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Log2(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2621,8 +2621,8 @@ HWTEST_F_L0(BuiltinsMathTest, Max) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2635,8 +2635,8 @@ HWTEST_F_L0(BuiltinsMathTest, Max_1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2653,8 +2653,8 @@ HWTEST_F_L0(BuiltinsMathTest, Max_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(100))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(2.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(100); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2671,8 +2671,8 @@ HWTEST_F_L0(BuiltinsMathTest, Max_3) ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(-101.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(100.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2689,8 +2689,8 @@ HWTEST_F_L0(BuiltinsMathTest, Max_4) ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Max(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2706,8 +2706,8 @@ HWTEST_F_L0(BuiltinsMathTest, Min) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2720,8 +2720,8 @@ HWTEST_F_L0(BuiltinsMathTest, Min_1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2738,8 +2738,8 @@ HWTEST_F_L0(BuiltinsMathTest, Min_2) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(100))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(2.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(2.5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2756,8 +2756,8 @@ HWTEST_F_L0(BuiltinsMathTest, Min_3) ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(-101.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-101.5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2773,8 +2773,8 @@ HWTEST_F_L0(BuiltinsMathTest, Min_4) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(100))); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue::False()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Min(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2790,8 +2790,8 @@ HWTEST_F_L0(BuiltinsMathTest, Pow) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); ecmaRuntimeCallInfo->SetCallArg(1, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.25); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2806,8 +2806,8 @@ HWTEST_F_L0(BuiltinsMathTest, Pow_1) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2820,8 +2820,8 @@ HWTEST_F_L0(BuiltinsMathTest, Pow_2) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2836,8 +2836,8 @@ HWTEST_F_L0(BuiltinsMathTest, Pow_3) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::False()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Pow(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2850,10 +2850,10 @@ HWTEST_F_L0(BuiltinsMathTest, Random) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsMath::Random(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsMath::Random(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue result2 = BuiltinsMath::Random(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsMath::Random(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); ASSERT_NE(result1.GetRawData(), result2.GetRawData()); } @@ -2865,10 +2865,10 @@ HWTEST_F_L0(BuiltinsMathTest, Random_1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsMath::Random(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsMath::Random(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); - JSTaggedValue result2 = BuiltinsMath::Random(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsMath::Random(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); double value1 = JSTaggedValue(static_cast(result1.GetRawData())).GetDouble(); double value2 = JSTaggedValue(static_cast(result2.GetRawData())).GetDouble(); @@ -2886,8 +2886,8 @@ HWTEST_F_L0(BuiltinsMathTest, Round) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2901,8 +2901,8 @@ HWTEST_F_L0(BuiltinsMathTest, Round_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.25)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2916,8 +2916,8 @@ HWTEST_F_L0(BuiltinsMathTest, Round_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.14)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2931,8 +2931,8 @@ HWTEST_F_L0(BuiltinsMathTest, Round_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.7)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2946,8 +2946,8 @@ HWTEST_F_L0(BuiltinsMathTest, Round_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Round(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2961,8 +2961,8 @@ HWTEST_F_L0(BuiltinsMathTest, Fround) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2976,8 +2976,8 @@ HWTEST_F_L0(BuiltinsMathTest, Fround_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -2991,8 +2991,8 @@ HWTEST_F_L0(BuiltinsMathTest, Fround_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3006,8 +3006,8 @@ HWTEST_F_L0(BuiltinsMathTest, Fround_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(1.337)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.3370000123977661); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3021,8 +3021,8 @@ HWTEST_F_L0(BuiltinsMathTest, Fround_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-668523145.253485)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Fround(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-668523136.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3036,8 +3036,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3051,8 +3051,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3066,8 +3066,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(31); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3081,8 +3081,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(568243))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(12); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3096,8 +3096,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(4294967295))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3111,8 +3111,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(10000000000.123)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3125,8 +3125,8 @@ HWTEST_F_L0(BuiltinsMathTest, Clz32_6) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Clz32(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(32); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3139,8 +3139,8 @@ HWTEST_F_L0(BuiltinsMathTest, Hypot) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3154,8 +3154,8 @@ HWTEST_F_L0(BuiltinsMathTest, Hypot_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-2.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(2.1); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3169,8 +3169,8 @@ HWTEST_F_L0(BuiltinsMathTest, Hypot_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); ASSERT_TRUE(result.IsDouble()); ASSERT_TRUE(std::isnan(result.GetDouble())); @@ -3188,8 +3188,8 @@ HWTEST_F_L0(BuiltinsMathTest, Hypot_3) ecmaRuntimeCallInfo->SetCallArg(3, JSTaggedValue(-0.2)); ecmaRuntimeCallInfo->SetCallArg(4, JSTaggedValue(static_cast(90000))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Hypot(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(90000.00050022222); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3202,8 +3202,8 @@ HWTEST_F_L0(BuiltinsMathTest, Imul) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3219,8 +3219,8 @@ HWTEST_F_L0(BuiltinsMathTest, Imul_1) ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(9.256)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(-18); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3235,8 +3235,8 @@ HWTEST_F_L0(BuiltinsMathTest, Imul_2) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0xffffffff))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(-5); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3251,8 +3251,8 @@ HWTEST_F_L0(BuiltinsMathTest, Imul_3) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(0xfffffffe))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Imul(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedInt(-10); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3266,8 +3266,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.8414709848078965); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3281,8 +3281,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.9974949866040544); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3296,8 +3296,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3311,8 +3311,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3326,8 +3326,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.8414709848078965); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3342,8 +3342,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.09983341664682815); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3357,8 +3357,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3372,8 +3372,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sin_8) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sin(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3387,8 +3387,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.1752011936438014); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3402,8 +3402,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-1.5)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-2.1292794550948173); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3417,8 +3417,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3432,8 +3432,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3447,8 +3447,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.1752011936438014); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3463,8 +3463,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.10016675001984403); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3478,8 +3478,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3493,8 +3493,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sinh_7) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sinh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3508,8 +3508,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3523,8 +3523,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3538,8 +3538,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3553,8 +3553,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3569,8 +3569,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.31622776601683794); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3584,8 +3584,8 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3597,10 +3597,10 @@ HWTEST_F_L0(BuiltinsMathTest, Sqrt_6) auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread_, JSTaggedValue::Undefined(), 6); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-base::NAN_VALUE))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Sqrt(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3614,8 +3614,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.5574077246549023); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3629,8 +3629,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3644,8 +3644,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3659,8 +3659,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.5574077246549023); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3675,8 +3675,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.10033467208545055); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3690,8 +3690,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3705,8 +3705,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tan_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tan(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3720,8 +3720,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.7615941559557649); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3735,8 +3735,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3750,8 +3750,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3765,8 +3765,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.7615941559557649); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3781,8 +3781,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0.09966799462495582); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3796,8 +3796,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3811,8 +3811,8 @@ HWTEST_F_L0(BuiltinsMathTest, Tanh_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Tanh(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3826,8 +3826,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3841,8 +3841,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc_1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-0.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3856,8 +3856,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc_2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3871,8 +3871,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc_3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::True()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(1.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3887,8 +3887,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc_4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(-0.0); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3902,8 +3902,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc_5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::POSITIVE_INFINITY); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); @@ -3917,8 +3917,8 @@ HWTEST_F_L0(BuiltinsMathTest, Trunc_6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(-base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread_, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsMath::Trunc(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread_, prev); JSTaggedValue expect = BuiltinsBase::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), expect.GetRawData()); diff --git a/ecmascript/builtins/tests/builtins_number_format_test.cpp b/ecmascript/builtins/tests/builtins_number_format_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a3ad7c8ff081406f8baad05d017c64e9ac4a413 --- /dev/null +++ b/ecmascript/builtins/tests/builtins_number_format_test.cpp @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/builtins/builtins_number_format.h" +#include "ecmascript/builtins/builtins_array.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_number_format.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda::ecmascript; +using namespace panda::ecmascript::builtins; + +namespace panda::test { +class BuiltinsNumberFormatTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + JSRuntimeOptions options; +#if PANDA_TARGET_LINUX + // for consistency requirement, use ohos_icu4j/data as icu-data-path + options.SetIcuDataPath(ICU_PATH); +#endif + options.SetEnableForceGC(true); + instance = JSNApi::CreateEcmaVM(options); + instance->SetEnableForceGC(true); + ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM"; + thread = instance->GetJSThread(); + scope = new EcmaHandleScope(thread); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +// new DateTimeFormat(newTarget is undefined) +HWTEST_F_L0(BuiltinsNumberFormatTest, NumberFormatConstructor) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle newTarget(env->GetNumberFormatFunction()); + + JSHandle localesString(factory->NewFromASCII("en-US")); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 8); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); + // option tag is default value + ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumberFormat::NumberFormatConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + + EXPECT_TRUE(result.IsJSNumberFormat()); +} + +static JSTaggedValue BuiltinsFormatTest(JSThread *thread, JSHandle &options, + JSHandle &number, JSHandle &locale) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle newTarget(env->GetNumberFormatFunction()); + + auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 8); + ecmaRuntimeCallInfo1->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo1->SetCallArg(0, locale.GetTaggedValue()); + ecmaRuntimeCallInfo1->SetCallArg(1, options.GetTaggedValue()); + // construct numberformat + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue numberFormat = BuiltinsNumberFormat::NumberFormatConstructor(ecmaRuntimeCallInfo1); + JSHandle numberFormatVal(thread, numberFormat); + TestHelper::TearDownFrame(thread, prev); + // get function by calling Format function + auto ecmaRuntimeCallInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 4); + ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo2->SetThis(numberFormatVal.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue resultFunc = BuiltinsNumberFormat::Format(ecmaRuntimeCallInfo2); + JSHandle jsFunction(thread, resultFunc); + TestHelper::TearDownFrame(thread, prev); + JSArray *jsArray = + JSArray::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0)).GetTaggedValue().GetTaggedObject()); + JSHandle jsObject(thread, jsArray); + PropertyDescriptor desc(thread, JSHandle(jsFunction), true, true, true); + JSHandle joinKey(factory->NewFromASCII("join")); + JSArray::DefineOwnProperty(thread, jsObject, joinKey, desc); + + auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo3->SetThis(jsObject.GetTaggedValue()); + ecmaRuntimeCallInfo3->SetCallArg(0, number.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result = BuiltinsArray::ToString(ecmaRuntimeCallInfo3); + TestHelper::TearDownFrame(thread, prev); + return result; +} + +// format decimal +HWTEST_F_L0(BuiltinsNumberFormatTest, Format_001) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle styleValue(factory->NewFromASCII("decimal")); + JSHandle localeString(factory->NewFromASCII("en-US")); + JSHandle numberVal(thread, JSTaggedValue(3500)); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); + + JSHandle resultEcmaStr(thread, formatResult); + EXPECT_STREQ("3,500", CString(resultEcmaStr->GetCString().get()).c_str()); +} + +// format currency +HWTEST_F_L0(BuiltinsNumberFormatTest, Format_002) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle currencyKey = globalConst->GetHandledCurrencyString(); + JSHandle currencyDisplayKey = globalConst->GetHandledCurrencyDisplayString(); + JSHandle currencySignDisplayKey = globalConst->GetHandledCurrencySignString(); + + JSHandle styleValue(factory->NewFromASCII("currency")); + JSHandle currencyValue(factory->NewFromASCII("USD")); + JSHandle currencyDisplayValue(factory->NewFromASCII("name")); + JSHandle currencySignDisplayValue(factory->NewFromASCII("accounting")); + JSHandle localeString(factory->NewFromASCII("en-US")); + JSHandle numberVal(thread, JSTaggedValue(static_cast(-3500))); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSObject::SetProperty(thread, optionsObj, currencyKey, currencyValue); + JSObject::SetProperty(thread, optionsObj, currencyDisplayKey, currencyDisplayValue); + JSObject::SetProperty(thread, optionsObj, currencySignDisplayKey, currencySignDisplayValue); + JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); + + JSHandle resultEcmaStr(thread, formatResult); + EXPECT_STREQ("($3,500.00)", CString(resultEcmaStr->GetCString().get()).c_str()); +} + +// format percent +HWTEST_F_L0(BuiltinsNumberFormatTest, Format_003) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle signDisplayKey = globalConst->GetHandledSignDisplayString(); + + JSHandle styleValue(factory->NewFromASCII("percent")); + JSHandle signDisplayValue(factory->NewFromASCII("exceptZero")); + JSHandle localeString(factory->NewFromASCII("en-US")); + JSHandle numberVal(thread, JSTaggedValue(static_cast(0.55))); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSObject::SetProperty(thread, optionsObj, signDisplayKey, signDisplayValue); + JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); + + JSHandle resultEcmaStr(thread, formatResult); + EXPECT_STREQ("+55%", CString(resultEcmaStr->GetCString().get()).c_str()); +} + +// format unit +HWTEST_F_L0(BuiltinsNumberFormatTest, Format_004) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle unitKey = globalConst->GetHandledUnitString(); + + JSHandle styleValue(factory->NewFromASCII("unit")); + JSHandle unitValue(factory->NewFromASCII("liter")); + JSHandle localeString(factory->NewFromASCII("en-US")); + JSHandle numberVal(thread, JSTaggedValue(3500)); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSObject::SetProperty(thread, optionsObj, unitKey, unitValue); + JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); + + JSHandle resultEcmaStr(thread, formatResult); + EXPECT_STREQ("3,500 L", CString(resultEcmaStr->GetCString().get()).c_str()); +} + +// format notation +HWTEST_F_L0(BuiltinsNumberFormatTest, Format_005) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle notationKey = globalConst->GetHandledNotationString(); + JSHandle notationValue(factory->NewFromASCII("compact")); + JSHandle localeString(factory->NewFromASCII("zh-CN")); + JSHandle numberVal(thread, JSTaggedValue(987654321)); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, notationKey, notationValue); + JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); + + JSHandle resultEcmaStr(thread, formatResult); + EXPECT_STREQ("9.9亿", CString(resultEcmaStr->GetCString().get()).c_str()); +} + +static JSTaggedValue NumberFormatCreateTest(JSThread *thread, JSHandle &options, + JSHandle &locale) +{ + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle newTarget(env->GetNumberFormatFunction()); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 8); + ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, locale.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(1, options.GetTaggedValue()); + // construct numberformat + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue numberFormat = BuiltinsNumberFormat::NumberFormatConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + return numberFormat; +} + +HWTEST_F_L0(BuiltinsNumberFormatTest, FormatToParts) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle currencyKey = globalConst->GetHandledCurrencyString(); + + JSHandle styleValue(factory->NewFromASCII("currency")); + JSHandle currencyValue(factory->NewFromASCII("EUR")); + JSHandle localeString(factory->NewFromASCII("de-DE")); + JSHandle numberVal(thread, JSTaggedValue(3500)); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSObject::SetProperty(thread, optionsObj, currencyKey, currencyValue); + JSTaggedValue numberFormat = NumberFormatCreateTest(thread, optionsObj, localeString); + JSHandle numberFormatVal(thread, numberFormat); + // format currency + JSTaggedValue formatResult = BuiltinsFormatTest(thread, optionsObj, numberVal, localeString); + JSHandle resultEcmaStr(thread, formatResult); + EXPECT_STREQ("3.500,00 €", CString(resultEcmaStr->GetCString().get()).c_str()); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(numberFormatVal.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, numberVal.GetTaggedValue()); + // format currency to part + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumberFormat::FormatToParts(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + + JSHandle resultHandle(thread, result); + JSHandle elements(thread, resultHandle->GetElements()); + EXPECT_EQ(elements->GetLength(), 10U); // "3","." ,"5" ,"0" ,"0" ,"," ,"0" ,0" ," " ,"€" +} + +HWTEST_F_L0(BuiltinsNumberFormatTest, ResolvedOptions) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + JSHandle objFun = env->GetObjectFunction(); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle currencyKey = globalConst->GetHandledCurrencyString(); + + JSHandle styleValue(factory->NewFromASCII("currency")); + JSHandle currencyValue(factory->NewFromASCII("USD")); + JSHandle localeString(factory->NewFromASCII("en-US")); + + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSObject::SetProperty(thread, optionsObj, currencyKey, currencyValue); + JSTaggedValue numberFormat = NumberFormatCreateTest(thread, optionsObj, localeString); + JSHandle numberFormatVal(thread, numberFormat); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(numberFormatVal.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumberFormat::ResolvedOptions(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + + JSHandle resultObj = + JSHandle(thread, JSTaggedValue(static_cast(result.GetRawData()))); + // judge whether the properties of the object are the same as those of jsnumberformat tag + EXPECT_EQ(JSTaggedValue::SameValue( + JSObject::GetProperty(thread, resultObj, styleKey).GetValue(), styleValue), true); + EXPECT_EQ(JSTaggedValue::SameValue( + JSObject::GetProperty(thread, resultObj, currencyKey).GetValue(), currencyValue), true); +} +} \ No newline at end of file diff --git a/ecmascript/builtins/tests/builtins_number_test.cpp b/ecmascript/builtins/tests/builtins_number_test.cpp index 184d7f237f6a1650ef37626502a696bd4922623c..65e5f4234758db993ada3fb34634be89c46555c2 100644 --- a/ecmascript/builtins/tests/builtins_number_test.cpp +++ b/ecmascript/builtins/tests/builtins_number_test.cpp @@ -76,8 +76,9 @@ HWTEST_F_L0(BuiltinsNumberTest, NumberConstructor) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::NumberConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::NumberConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSPrimitiveRef *ref = JSPrimitiveRef::Cast(value.GetTaggedObject()); @@ -93,9 +94,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(value))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isFinite(Number.MAX_VALUE) @@ -106,9 +108,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::MAX_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isFinite("helloworld") @@ -120,9 +123,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite2) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, test.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isFinite(NaN) @@ -133,9 +137,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite3) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::NAN_VALUE)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isFinite(Infinity) @@ -146,9 +151,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite4) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(base::POSITIVE_INFINITY)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isFinite(undefined) @@ -159,9 +165,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite5) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isFinite(null) @@ -172,9 +179,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsFinite6) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Null()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsFinite(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isInteger(0.1) @@ -185,9 +193,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsInteger) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsInteger(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsInteger(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.isNaN(0.1) @@ -198,9 +207,10 @@ HWTEST_F_L0(BuiltinsNumberTest, IsNaN) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(0.1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::IsNaN(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::IsNaN(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // new Number(123.456).toString(7) @@ -219,14 +229,15 @@ HWTEST_F_L0(BuiltinsNumberTest, ToString) ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(7.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ToString(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("234.312256641535441"); CVector test(res->GetLength() + 1); res->CopyDataUtf8(test.data(), res->GetLength()); ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); + TestHelper::TearDownFrame(thread, prev); } // new Number(123.456).toExponential(5) @@ -245,14 +256,15 @@ HWTEST_F_L0(BuiltinsNumberTest, IsExponential) ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(5.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ToExponential(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ToExponential(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("1.23456e+2"); CVector test(res->GetLength() + 1); res->CopyDataUtf8(test.data(), res->GetLength()); ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); + TestHelper::TearDownFrame(thread, prev); } // new Number(123.456).toFixed(10) @@ -271,12 +283,13 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed) ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(10.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ToFixed(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ToFixed(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("123.4560000000"); ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); + TestHelper::TearDownFrame(thread, prev); } // new Number(123.456).toFixed(30) @@ -295,12 +308,13 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed1) ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(30.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ToFixed(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ToFixed(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("123.456000000000003069544618483633"); ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); + TestHelper::TearDownFrame(thread, prev); } // new Number(1e21).toFixed(20) @@ -319,8 +333,8 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed2) { ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(20.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ToFixed(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ToFixed(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("1e+21"); @@ -328,6 +342,7 @@ HWTEST_F_L0(BuiltinsNumberTest, ToFixed2) { res->CopyDataUtf8(test.data(), res->GetLength()); std::cout << test.data(); ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); + TestHelper::TearDownFrame(thread, prev); } // new Number(123.456).toPrecision(8) @@ -346,12 +361,13 @@ HWTEST_F_L0(BuiltinsNumberTest, ToPrecision) ecmaRuntimeCallInfo->SetThis(number.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(8.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ToPrecision(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ToPrecision(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle res(thread, reinterpret_cast(result.GetRawData())); JSHandle correctResult = factory->NewFromASCII("123.45600"); ASSERT_TRUE(EcmaString::StringsAreEqual(*res, *correctResult)); + TestHelper::TearDownFrame(thread, prev); } // Number.parseFloat(0x123) @@ -363,9 +379,10 @@ HWTEST_F_L0(BuiltinsNumberTest, parseFloat) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, param.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ParseFloat(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ParseFloat(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(0)).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.parseFloat(0x123xx) @@ -377,9 +394,10 @@ HWTEST_F_L0(BuiltinsNumberTest, parseFloat1) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, param.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ParseFloat(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ParseFloat(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(0)).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Number.parseInt(0x123) @@ -394,9 +412,10 @@ HWTEST_F_L0(BuiltinsNumberTest, parseInt) ecmaRuntimeCallInfo->SetCallArg(0, param.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(16.0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsNumber::ParseInt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsNumber::ParseInt(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(static_cast(291)).GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // testcases of StringToDouble flags diff --git a/ecmascript/builtins/tests/builtins_object_test.cpp b/ecmascript/builtins/tests/builtins_object_test.cpp index 8a0f1852a21362a40370c64121e7abb8122006be..817244f60408e5e9d969b9e8a8940ffec189da96 100644 --- a/ecmascript/builtins/tests/builtins_object_test.cpp +++ b/ecmascript/builtins/tests/builtins_object_test.cpp @@ -26,7 +26,6 @@ #include "ecmascript/js_thread.h" #include "ecmascript/object_factory.h" #include "ecmascript/tests/test_helper.h" -#include "file_items.h" #include "utils/bit_utils.h" using namespace panda::ecmascript; @@ -102,8 +101,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ObjectConstructor) objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::ObjectConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::ObjectConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -122,8 +121,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ObjectConstructor) tgObjCallInfo->SetThis(JSTaggedValue::Undefined()); tgObjCallInfo->SetNewTarget(JSTaggedValue(*objFun)); - prev = TestHelper::SetupFrame(thread, tgObjCallInfo.get()); - JSTaggedValue resultTg = BuiltinsObject::ObjectConstructor(tgObjCallInfo.get()); + prev = TestHelper::SetupFrame(thread, tgObjCallInfo); + JSTaggedValue resultTg = BuiltinsObject::ObjectConstructor(tgObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultTg.IsObject()); JSHandle jtHandleTg(thread, JSTaggedValue(reinterpret_cast(resultTg.GetRawData()))); @@ -142,8 +141,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ObjectConstructor) vnObjCallInfo->SetCallArg(0, JSTaggedValue::Null()); vnObjCallInfo->SetNewTarget(JSTaggedValue(*objFun)); - prev = TestHelper::SetupFrame(thread, vnObjCallInfo.get()); - JSTaggedValue resultVn = BuiltinsObject::ObjectConstructor(vnObjCallInfo.get()); + prev = TestHelper::SetupFrame(thread, vnObjCallInfo); + JSTaggedValue resultVn = BuiltinsObject::ObjectConstructor(vnObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultVn.IsObject()); @@ -179,8 +178,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Assign) assignObjCallInfo->SetCallArg(0, objHandle1.GetTaggedValue()); assignObjCallInfo->SetCallArg(1, objHandle2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, assignObjCallInfo.get()); - JSTaggedValue result = BuiltinsObject::Assign(assignObjCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, assignObjCallInfo); + JSTaggedValue result = BuiltinsObject::Assign(assignObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -202,8 +201,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Create) objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, funcProto.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::Create(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::Create(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -230,8 +229,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Create) hpObjCallInfo->SetCallArg(0, funcProto.GetTaggedValue()); hpObjCallInfo->SetCallArg(1, objHandle.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, hpObjCallInfo.get()); - JSTaggedValue resultHp = BuiltinsObject::Create(hpObjCallInfo.get()); + prev = TestHelper::SetupFrame(thread, hpObjCallInfo); + JSTaggedValue resultHp = BuiltinsObject::Create(hpObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultHp.IsObject()); @@ -246,8 +245,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Create) unCallInfo->SetThis(JSTaggedValue::Undefined()); unCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread, unCallInfo.get()); - JSTaggedValue resultUn = BuiltinsObject::Create(unCallInfo.get()); + prev = TestHelper::SetupFrame(thread, unCallInfo); + JSTaggedValue resultUn = BuiltinsObject::Create(unCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(resultUn.GetRawData(), JSTaggedValue::VALUE_EXCEPTION); } @@ -277,8 +276,8 @@ HWTEST_F_L0(BuiltinsObjectTest, DefineProperties) objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); objCallInfo->SetCallArg(1, jsobjHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::DefineProperties(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::DefineProperties(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -319,8 +318,8 @@ HWTEST_F_L0(BuiltinsObjectTest, DefineProperty) objCallInfo->SetCallArg(1, key.GetTaggedValue()); objCallInfo->SetCallArg(2, attHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::DefineProperty(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::DefineProperty(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -343,13 +342,13 @@ HWTEST_F_L0(BuiltinsObjectTest, Freeze) nofreezeObjCallInfo->SetThis(JSTaggedValue::Undefined()); nofreezeObjCallInfo->SetCallArg(0, emptyObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, nofreezeObjCallInfo.get()); - JSTaggedValue result = BuiltinsObject::IsFrozen(nofreezeObjCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, nofreezeObjCallInfo); + JSTaggedValue result = BuiltinsObject::IsFrozen(nofreezeObjCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); - BuiltinsObject::Freeze(nofreezeObjCallInfo.get()); - JSTaggedValue resultIs = BuiltinsObject::IsFrozen(nofreezeObjCallInfo.get()); + BuiltinsObject::Freeze(nofreezeObjCallInfo); + JSTaggedValue resultIs = BuiltinsObject::IsFrozen(nofreezeObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(resultIs.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -373,8 +372,8 @@ HWTEST_F_L0(BuiltinsObjectTest, GetOwnPropertyDescriptor) objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); objCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertyDescriptor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::GetOwnPropertyDescriptor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -402,8 +401,8 @@ HWTEST_F_L0(BuiltinsObjectTest, GetOwnPropertyNames) objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertyNames(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::GetOwnPropertyNames(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -426,8 +425,8 @@ HWTEST_F_L0(BuiltinsObjectTest, GetOwnPropertySymbols) objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, objHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = BuiltinsObject::GetOwnPropertySymbols(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = BuiltinsObject::GetOwnPropertySymbols(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -450,14 +449,14 @@ HWTEST_F_L0(BuiltinsObjectTest, Is) objCallInfo1->SetCallArg(0, obj1.GetTaggedValue()); objCallInfo1->SetCallArg(1, obj2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo1.get()); - JSTaggedValue objResult1 = BuiltinsObject::Is(objCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo1); + JSTaggedValue objResult1 = BuiltinsObject::Is(objCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(objResult1.GetRawData(), JSTaggedValue::False().GetRawData()); objCallInfo1->SetCallArg(1, obj1.GetTaggedValue()); - JSTaggedValue objResult2 = BuiltinsObject::Is(objCallInfo1.get()); + JSTaggedValue objResult2 = BuiltinsObject::Is(objCallInfo1); ASSERT_EQ(objResult2.GetRawData(), JSTaggedValue::True().GetRawData()); // string compare @@ -470,8 +469,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Is) strCallInfo->SetCallArg(0, testStrValue1.GetTaggedValue()); strCallInfo->SetCallArg(1, testStrValue2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, strCallInfo.get()); - JSTaggedValue strResult = BuiltinsObject::Is(strCallInfo.get()); + prev = TestHelper::SetupFrame(thread, strCallInfo); + JSTaggedValue strResult = BuiltinsObject::Is(strCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(strResult.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -483,8 +482,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Is) boolCallInfo->SetCallArg(0, JSTaggedValue::True()); boolCallInfo->SetCallArg(1, JSTaggedValue::False()); - prev = TestHelper::SetupFrame(thread, boolCallInfo.get()); - JSTaggedValue boolResult = BuiltinsObject::Is(boolCallInfo.get()); + prev = TestHelper::SetupFrame(thread, boolCallInfo); + JSTaggedValue boolResult = BuiltinsObject::Is(boolCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(boolResult.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -496,8 +495,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Is) numCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); numCallInfo->SetCallArg(1, JSTaggedValue(-0.0)); - prev = TestHelper::SetupFrame(thread, numCallInfo.get()); - JSTaggedValue numResult = BuiltinsObject::Is(numCallInfo.get()); + prev = TestHelper::SetupFrame(thread, numCallInfo); + JSTaggedValue numResult = BuiltinsObject::Is(numCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(numResult.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -509,8 +508,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Is) nullCallInfo->SetCallArg(0, JSTaggedValue::Null()); nullCallInfo->SetCallArg(1, JSTaggedValue::Null()); - prev = TestHelper::SetupFrame(thread, nullCallInfo.get()); - JSTaggedValue nullResult = BuiltinsObject::Is(nullCallInfo.get()); + prev = TestHelper::SetupFrame(thread, nullCallInfo); + JSTaggedValue nullResult = BuiltinsObject::Is(nullCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(nullResult.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -521,8 +520,8 @@ HWTEST_F_L0(BuiltinsObjectTest, Is) undefineCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); undefineCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - prev = TestHelper::SetupFrame(thread, undefineCallInfo.get()); - JSTaggedValue undefineResult = BuiltinsObject::Is(undefineCallInfo.get()); + prev = TestHelper::SetupFrame(thread, undefineCallInfo); + JSTaggedValue undefineResult = BuiltinsObject::Is(undefineCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(undefineResult.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -542,14 +541,14 @@ HWTEST_F_L0(BuiltinsObjectTest, IsExtensible) emptyObjCallInfo->SetThis(JSTaggedValue::Undefined()); emptyObjCallInfo->SetCallArg(0, emptyObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, emptyObjCallInfo.get()); - JSTaggedValue result = BuiltinsObject::IsExtensible(emptyObjCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, emptyObjCallInfo); + JSTaggedValue result = BuiltinsObject::IsExtensible(emptyObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); emptyObj->GetJSHClass()->SetExtensible(false); - JSTaggedValue result2 = BuiltinsObject::IsExtensible(emptyObjCallInfo.get()); + JSTaggedValue result2 = BuiltinsObject::IsExtensible(emptyObjCallInfo); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -569,15 +568,15 @@ HWTEST_F_L0(BuiltinsObjectTest, IsFrozen) emptyObjCallInfo->SetThis(JSTaggedValue::Undefined()); emptyObjCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, emptyObjCallInfo.get()); - JSTaggedValue result = BuiltinsObject::IsFrozen(emptyObjCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, emptyObjCallInfo); + JSTaggedValue result = BuiltinsObject::IsFrozen(emptyObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); obj->GetJSHClass()->SetExtensible(false); - prev = TestHelper::SetupFrame(thread, emptyObjCallInfo.get()); - JSTaggedValue resultNex = BuiltinsObject::IsFrozen(emptyObjCallInfo.get()); + prev = TestHelper::SetupFrame(thread, emptyObjCallInfo); + JSTaggedValue resultNex = BuiltinsObject::IsFrozen(emptyObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(resultNex.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -592,8 +591,8 @@ HWTEST_F_L0(BuiltinsObjectTest, IsFrozen) emptyObjCallInfo2->SetThis(JSTaggedValue::Undefined()); emptyObjCallInfo2->SetCallArg(0, obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, emptyObjCallInfo2.get()); - JSTaggedValue resultNw = BuiltinsObject::IsFrozen(emptyObjCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, emptyObjCallInfo2); + JSTaggedValue resultNw = BuiltinsObject::IsFrozen(emptyObjCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(resultNw.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -607,8 +606,8 @@ HWTEST_F_L0(BuiltinsObjectTest, IsFrozen) emptyObjCallInfo3->SetThis(JSTaggedValue::Undefined()); emptyObjCallInfo3->SetCallArg(0, obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, emptyObjCallInfo3.get()); - JSTaggedValue resultNc = BuiltinsObject::IsFrozen(emptyObjCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, emptyObjCallInfo3); + JSTaggedValue resultNc = BuiltinsObject::IsFrozen(emptyObjCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(resultNc.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -628,8 +627,8 @@ HWTEST_F_L0(BuiltinsObjectTest, IsSealed) emptyObjCallInfo->SetThis(JSTaggedValue::Undefined()); emptyObjCallInfo->SetCallArg(0, emptyObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, emptyObjCallInfo.get()); - JSTaggedValue result = BuiltinsObject::IsSealed(emptyObjCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, emptyObjCallInfo); + JSTaggedValue result = BuiltinsObject::IsSealed(emptyObjCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -644,8 +643,24 @@ HWTEST_F_L0(BuiltinsObjectTest, Keys) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::Keys(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::Keys(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + + ASSERT_TRUE(result.IsECMAObject()); +} + +// Object.values(obj) +HWTEST_F_L0(BuiltinsObjectTest, Values) +{ + JSHandle obj(thread, CreateBuiltinJSObject(thread, "x")); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::Values(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -661,8 +676,8 @@ HWTEST_F_L0(BuiltinsObjectTest, PreventExtensions) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::PreventExtensions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::PreventExtensions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -680,14 +695,14 @@ HWTEST_F_L0(BuiltinsObjectTest, Seal) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::Seal(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::Seal(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); ASSERT_EQ(result.GetRawData(), obj->GetRawData()); // test isSealed(). - JSTaggedValue res = BuiltinsObject::IsSealed(ecmaRuntimeCallInfo.get()); + JSTaggedValue res = BuiltinsObject::IsSealed(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(res.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -704,8 +719,8 @@ HWTEST_F_L0(BuiltinsObjectTest, SetPrototypeOf) ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, objFather.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::SetPrototypeOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::SetPrototypeOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); @@ -729,8 +744,8 @@ HWTEST_F_L0(BuiltinsObjectTest, HasOwnProperty) ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::HasOwnProperty(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::HasOwnProperty(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -747,8 +762,8 @@ HWTEST_F_L0(BuiltinsObjectTest, IsPrototypeOfFalse) ecmaRuntimeCallInfo->SetThis(objFather.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsObject::IsPrototypeOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsObject::IsPrototypeOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); @@ -765,8 +780,8 @@ HWTEST_F_L0(BuiltinsObjectTest, IsPrototypeOfTrue) ecmaRuntimeCallInfo1->SetCallArg(0, obj.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, objFather.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsObject::SetPrototypeOf(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsObject::SetPrototypeOf(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result1.IsObject()); @@ -777,8 +792,8 @@ HWTEST_F_L0(BuiltinsObjectTest, IsPrototypeOfTrue) ecmaRuntimeCallInfo2->SetThis(objFather.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, obj.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsObject::IsPrototypeOf(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsObject::IsPrototypeOf(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -795,8 +810,8 @@ HWTEST_F_L0(BuiltinsObjectTest, PropertyIsEnumerable) ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::PropertyIsEnumerable(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::PropertyIsEnumerable(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); @@ -820,8 +835,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToLocaleString) ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::ToLocaleString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::ToLocaleString(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -839,8 +854,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::ToString(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -854,8 +869,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) arrEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); arrEcmaRuntimeCallInfo->SetThis(arr.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, arrEcmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsObject::ToString(arrEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, arrEcmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsObject::ToString(arrEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultArr.IsString()); @@ -869,8 +884,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) strEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); strEcmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, strEcmaRuntimeCallInfo.get()); - JSTaggedValue resultStr = BuiltinsObject::ToString(strEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, strEcmaRuntimeCallInfo); + JSTaggedValue resultStr = BuiltinsObject::ToString(strEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultStr.IsString()); @@ -884,8 +899,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) funcEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); funcEcmaRuntimeCallInfo->SetThis(func.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, funcEcmaRuntimeCallInfo.get()); - JSTaggedValue resultFunc = BuiltinsObject::ToString(funcEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, funcEcmaRuntimeCallInfo); + JSTaggedValue resultFunc = BuiltinsObject::ToString(funcEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultFunc.IsString()); @@ -902,8 +917,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) errorEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); errorEcmaRuntimeCallInfo->SetThis(error.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, errorEcmaRuntimeCallInfo.get()); - JSTaggedValue resultError = BuiltinsObject::ToString(errorEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, errorEcmaRuntimeCallInfo); + JSTaggedValue resultError = BuiltinsObject::ToString(errorEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultError.IsString()); @@ -919,8 +934,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) boolEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); boolEcmaRuntimeCallInfo->SetThis(boolean.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, boolEcmaRuntimeCallInfo.get()); - JSTaggedValue resultBool = BuiltinsObject::ToString(boolEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, boolEcmaRuntimeCallInfo); + JSTaggedValue resultBool = BuiltinsObject::ToString(boolEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultBool.IsString()); @@ -933,8 +948,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ToString) numEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); numEcmaRuntimeCallInfo->SetThis(JSTaggedValue(static_cast(0))); - prev = TestHelper::SetupFrame(thread, numEcmaRuntimeCallInfo.get()); - JSTaggedValue resultNum = BuiltinsObject::ToString(numEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, numEcmaRuntimeCallInfo); + JSTaggedValue resultNum = BuiltinsObject::ToString(numEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(resultNum.IsString()); @@ -950,8 +965,8 @@ HWTEST_F_L0(BuiltinsObjectTest, ValueOf) ecmaRuntimeCallInfo->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, obj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsObject::ValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsObject::ValueOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsECMAObject()); diff --git a/ecmascript/builtins/tests/builtins_plural_rules_test.cpp b/ecmascript/builtins/tests/builtins_plural_rules_test.cpp index 0941fed37794369322dd93dd2d44dfd02892a3d3..2eade825d74ce313d142b9e91ec5f549c5a3a53e 100644 --- a/ecmascript/builtins/tests/builtins_plural_rules_test.cpp +++ b/ecmascript/builtins/tests/builtins_plural_rules_test.cpp @@ -74,8 +74,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, PluralRulesConstructor) // option tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::PluralRulesConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::PluralRulesConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSPluralRules()); @@ -100,8 +100,8 @@ static JSTaggedValue JSPluralRulesCreateWithLocaleTest(JSThread *thread, JSHandl ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::PluralRulesConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::PluralRulesConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSPluralRules()); @@ -123,8 +123,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_001) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -147,8 +147,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_002) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -171,8 +171,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_003) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -195,8 +195,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_004) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -219,8 +219,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_005) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -243,8 +243,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_006) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -267,8 +267,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, Select_007) ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::Select(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsString()); @@ -288,8 +288,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, SupportedLocalesOf) // set the tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue resultArr = BuiltinsPluralRules::SupportedLocalesOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue resultArr = BuiltinsPluralRules::SupportedLocalesOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, resultArr); @@ -312,8 +312,8 @@ HWTEST_F_L0(BuiltinsPluralRulesTest, ResolvedOptions) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPluralRules::ResolvedOptions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPluralRules::ResolvedOptions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj = diff --git a/ecmascript/builtins/tests/builtins_promise_test.cpp b/ecmascript/builtins/tests/builtins_promise_test.cpp index 7e7f5f802fe1b11a5bf0b5d56b6df1fd56ec0e2a..d1a63186dbfc72f682c5296562ccd9b8a094e945 100644 --- a/ecmascript/builtins/tests/builtins_promise_test.cpp +++ b/ecmascript/builtins/tests/builtins_promise_test.cpp @@ -141,11 +141,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject1) /** * @tc.steps: var p1 = Promise.reject(3). */ - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); + TestHelper::TearDownFrame(thread, prevReject); } /* @@ -171,11 +172,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject2) ecmaRuntimeCallInfo->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo); JSHandle promise1(thread, result); EXPECT_EQ(promise1->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prev); /** * @tc.steps: step2. var p2 = Promise.reject(p1) @@ -184,15 +186,16 @@ HWTEST_F_L0(BuiltinsPromiseTest, Reject2) ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, promise1.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); - JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1); JSHandle promise2(thread, result1); EXPECT_NE(*promise1, *promise2); EXPECT_EQ(promise2->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ( JSTaggedValue::SameValue(promise2->GetPromiseResult(), JSTaggedValue(promise1.GetTaggedValue().GetRawData())), true); + TestHelper::TearDownFrame(thread, prev); } /* @@ -215,11 +218,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve1) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(5)), true); + TestHelper::TearDownFrame(thread, prevReject); } /* @@ -245,11 +249,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve2) ecmaRuntimeCallInfo->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo); JSHandle promise1(thread, result); EXPECT_EQ(promise1->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(promise1->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prev); // promise1 Enter Reject() as a parameter. /** @@ -259,13 +264,14 @@ HWTEST_F_L0(BuiltinsPromiseTest, Resolve2) ecmaRuntimeCallInfo1->SetFunction(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, promise1.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); - JSTaggedValue result1 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result1 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1); JSHandle promise2(thread, result1); EXPECT_EQ(*promise1, *promise2); EXPECT_EQ(promise2->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(promise2->GetPromiseResult(), paramMsg1.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prev1); } /* @@ -289,11 +295,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1); JSHandle rejectPromise(thread, result1); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); + TestHelper::TearDownFrame(thread, prevReject); /** * @tc.steps: step2. var p2 = Promise.resolve(6789) @@ -303,11 +310,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) ecmaRuntimeCallInfo2->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, paramMsg2.GetTaggedValue()); - [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2); JSHandle resolvePromise(thread, result2); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); + TestHelper::TearDownFrame(thread, prevResolve); /** * @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] @@ -327,11 +335,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race1) ecmaRuntimeCallInfo4->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(0, array.GetTaggedValue()); - [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - JSTaggedValue result4 = BuiltinsPromise::Race(ecmaRuntimeCallInfo4.get()); + [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + JSTaggedValue result4 = BuiltinsPromise::Race(ecmaRuntimeCallInfo4); JSHandle racePromise(thread, result4); EXPECT_EQ(racePromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); + TestHelper::TearDownFrame(thread, prev4); } /* @@ -357,11 +366,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1); JSHandle rejectPromise(thread, result1); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(12345)), true); + TestHelper::TearDownFrame(thread, prevReject); /** * @tc.steps: step2. var p2 = Promise.resolve(6789) @@ -371,11 +381,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) ecmaRuntimeCallInfo2->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, paramMsg2.GetTaggedValue()); - [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2); JSHandle resolvePromise(thread, result2); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), JSTaggedValue(6789)), true); + TestHelper::TearDownFrame(thread, prevResolve); /** * @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] @@ -395,11 +406,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) ecmaRuntimeCallInfo4->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(0, array.GetTaggedValue()); - [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - JSTaggedValue result4 = BuiltinsPromise::Race(ecmaRuntimeCallInfo4.get()); + [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + JSTaggedValue result4 = BuiltinsPromise::Race(ecmaRuntimeCallInfo4); JSHandle racePromise(thread, result4); EXPECT_EQ(racePromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(racePromise->GetPromiseResult().IsUndefined(), true); + TestHelper::TearDownFrame(thread, prev4); /** * @tc.steps: step5. p3.then((resolve)=>{print(resolve)}, (reject)=>{print(reject)}) @@ -412,12 +424,13 @@ HWTEST_F_L0(BuiltinsPromiseTest, Race2) ecmaRuntimeCallInfo5->SetCallArg(0, JSTaggedValue::Undefined()); ecmaRuntimeCallInfo5->SetCallArg(1, native_func_race_then_onrejected.GetTaggedValue()); - [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5.get()); - JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo5.get()); + [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5); + JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo5); JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); + TestHelper::TearDownFrame(thread, prev5); /** * @tc.steps: step6. execute promise queue @@ -451,11 +464,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1); JSHandle resolvePromise1(thread, result1); EXPECT_EQ(resolvePromise1->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise1->GetPromiseResult(), JSTaggedValue(111)), true); + TestHelper::TearDownFrame(thread, prevReject); /** * @tc.steps: step2. var p2 = Promise.resolve(222) @@ -465,11 +479,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) ecmaRuntimeCallInfo2->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, paramMsg2.GetTaggedValue()); - [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prevResolve = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo2); JSHandle resolvePromise2(thread, result2); EXPECT_EQ(resolvePromise2->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise2->GetPromiseResult(), JSTaggedValue(222)), true); + TestHelper::TearDownFrame(thread, prevResolve); /** * @tc.steps: step3. Construct an array with two elements p1 and p2. array = [p1. p2] @@ -489,11 +504,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) ecmaRuntimeCallInfo4->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(0, array.GetTaggedValue()); - [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - JSTaggedValue result4 = BuiltinsPromise::All(ecmaRuntimeCallInfo4.get()); + [[maybe_unused]] auto prev4 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + JSTaggedValue result4 = BuiltinsPromise::All(ecmaRuntimeCallInfo4); JSHandle allPromise(thread, result4); EXPECT_EQ(allPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(allPromise->GetPromiseResult().IsUndefined(), true); + TestHelper::TearDownFrame(thread, prev4); /** * @tc.steps: step5. p3.then((resolve)=>{print(resolve)}, (reject)=>{print(reject)}); @@ -506,12 +522,13 @@ HWTEST_F_L0(BuiltinsPromiseTest, All) ecmaRuntimeCallInfo5->SetCallArg(0, nativeFuncRaceThenOnResolved.GetTaggedValue()); ecmaRuntimeCallInfo5->SetCallArg(1, nativeFuncRaceThenOnResolved.GetTaggedValue()); - [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5.get()); - JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo5.get()); + [[maybe_unused]] auto prev5 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5); + JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo5); JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_TRUE(thenPromise->GetPromiseResult().IsUndefined()); + TestHelper::TearDownFrame(thread, prev5); /** * @tc.steps: step6. execute promise queue @@ -543,11 +560,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, Catch) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg1.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), JSTaggedValue(3)), true); + TestHelper::TearDownFrame(thread, prevReject); /** * @tc.steps: step2. p1 invokes catch() @@ -558,12 +576,13 @@ HWTEST_F_L0(BuiltinsPromiseTest, Catch) ecmaRuntimeCallInfo2->SetThis(rejectPromise.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, testPromiseCatch.GetTaggedValue()); - [[maybe_unused]] auto prevCatch = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue catchResult = BuiltinsPromise::Catch(ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prevCatch = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue catchResult = BuiltinsPromise::Catch(ecmaRuntimeCallInfo2); JSHandle catchPromise(thread, catchResult); EXPECT_EQ(catchPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(catchPromise->GetPromiseResult().IsUndefined(), true); + TestHelper::TearDownFrame(thread, prevCatch); /** * @tc.steps: step3. execute promise queue @@ -595,11 +614,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenResolve) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = BuiltinsPromise::Resolve(ecmaRuntimeCallInfo1); JSHandle resolvePromise(thread, result); EXPECT_EQ(resolvePromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(resolvePromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prevReject); /** * @tc.steps: step2. p1 invokes then() @@ -612,12 +632,13 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenResolve) ecmaRuntimeCallInfo2->SetCallArg(0, testPromiseThenOnResolved.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prevThen = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prevThen = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo2); JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); + TestHelper::TearDownFrame(thread, prevThen); /** * @tc.steps: step3. execute promise queue @@ -649,11 +670,12 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenReject) ecmaRuntimeCallInfo1->SetThis(promise.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, paramMsg.GetTaggedValue()); - [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevReject = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = BuiltinsPromise::Reject(ecmaRuntimeCallInfo1); JSHandle rejectPromise(thread, result); EXPECT_EQ(rejectPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(rejectPromise->GetPromiseResult(), paramMsg.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prevReject); /** * @tc.steps: step1. p1 invokes then() @@ -666,12 +688,13 @@ HWTEST_F_L0(BuiltinsPromiseTest, ThenReject) ecmaRuntimeCallInfo2->SetCallArg(0, testPromiseThenOnRejected.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, testPromiseThenOnRejected.GetTaggedValue()); - [[maybe_unused]] auto prevThen = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo2.get()); + [[maybe_unused]] auto prevThen = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue thenResult = BuiltinsPromise::Then(ecmaRuntimeCallInfo2); JSHandle thenPromise(thread, thenResult); EXPECT_EQ(thenPromise->GetPromiseState(), PromiseState::PENDING); EXPECT_EQ(thenPromise->GetPromiseResult().IsUndefined(), true); + TestHelper::TearDownFrame(thread, prevThen); /** * @tc.steps: step3. execute promise queue */ diff --git a/ecmascript/builtins/tests/builtins_proxy_test.cpp b/ecmascript/builtins/tests/builtins_proxy_test.cpp index 37448823a41f3dfc3ff43d0cf07c4a594df45a73..a1c98e71c14718741fc22f7a8dad8f331ab16f81 100644 --- a/ecmascript/builtins/tests/builtins_proxy_test.cpp +++ b/ecmascript/builtins/tests/builtins_proxy_test.cpp @@ -24,7 +24,6 @@ #include "ecmascript/js_thread.h" #include "ecmascript/object_factory.h" #include "ecmascript/tests/test_helper.h" -#include "file_items.h" #include "utils/bit_utils.h" using namespace panda::ecmascript; @@ -81,11 +80,12 @@ HWTEST_F_L0(BuiltinsProxyTest, ProxyConstructor) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, handler.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsProxy::ProxyConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsProxy::ProxyConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultHandle(thread, result); EXPECT_TRUE(resultHandle->IsJSProxy()); + TestHelper::TearDownFrame(thread, prev); } // 26.2.2.1 Proxy.revocable ( target, handler ) @@ -108,8 +108,8 @@ HWTEST_F_L0(BuiltinsProxyTest, Revocable) ecmaRuntimeCallInfo->SetCallArg(1, handler.GetTaggedValue()); ecmaRuntimeCallInfo->SetNewTarget(JSTaggedValue(*proxyFun)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsProxy::Revocable(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsProxy::Revocable(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultHandle(thread, result); @@ -134,5 +134,6 @@ HWTEST_F_L0(BuiltinsProxyTest, Revocable) PropertyDescriptor descRes(thread); JSObject::GetOwnProperty(thread, resultHandle, revokeKey, descRes); EXPECT_TRUE(descRes.GetValue()->IsProxyRevocFunction()); + TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_reflect_test.cpp b/ecmascript/builtins/tests/builtins_reflect_test.cpp index 98f676623a667dcaa7aa750ff0ceb7357970e8d2..0b322f9f325b0d3da3448229176b53456dcb33bb 100644 --- a/ecmascript/builtins/tests/builtins_reflect_test.cpp +++ b/ecmascript/builtins/tests/builtins_reflect_test.cpp @@ -74,7 +74,7 @@ JSTaggedValue TestReflectApply(EcmaRuntimeCallInfo *argv) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); int result = 0; - for (uint32_t index = 0; index < argv->GetArgsNumber(); ++index) { + for (int32_t index = 0; index < argv->GetArgsNumber(); ++index) { result += BuiltinsBase::GetCallArg(argv, index).GetTaggedValue().GetInt(); } JSHandle thisValue = BuiltinsBase::GetThis(argv); @@ -127,14 +127,15 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectApply) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(*thisArgument)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(*argumentsList)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectApply(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectApply(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(110).GetRawData()); JSObject::DeleteProperty(thread, (thisArgument), JSHandle(factory->NewFromASCII("test_reflect_apply_a"))); JSObject::DeleteProperty(thread, (thisArgument), JSHandle(factory->NewFromASCII("test_reflect_apply_b"))); + TestHelper::TearDownFrame(thread, prev); } // Reflect.construct (target, argumentsList [ , newTarget]) @@ -158,14 +159,15 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectConstruct) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(*argumentsList)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectConstruct(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectConstruct(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle taggedResult(thread, result); JSHandle refResult = JSHandle::Cast(taggedResult); JSHandle ruler = factory->NewFromASCII("ReflectConstruct"); ASSERT_EQ(EcmaString::Cast(refResult->GetValue().GetTaggedObject())->Compare(*ruler), 0); + TestHelper::TearDownFrame(thread, prev); } // Reflect.defineProperty (target, propertyKey, attributes) @@ -206,8 +208,8 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectDefineProperty) ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(*attributes)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectDefineProperty(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectDefineProperty(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); PropertyDescriptor descRuler(thread); @@ -216,6 +218,7 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectDefineProperty) ASSERT_EQ(descRuler.IsWritable(), true); ASSERT_EQ(descRuler.IsEnumerable(), false); ASSERT_EQ(descRuler.IsConfigurable(), true); + TestHelper::TearDownFrame(thread, prev); } // Reflect.deleteProperty (target, propertyKey) @@ -240,10 +243,11 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectDeleteProperty) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectDeleteProperty(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectDeleteProperty(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(JSObject::GetOwnProperty(thread, target, key, desc), false); + TestHelper::TearDownFrame(thread, prev); } // Reflect.get (target, propertyKey [ , receiver]) @@ -266,11 +270,12 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectGet) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectGet(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectGet(ecmaRuntimeCallInfo); JSHandle resultValue(thread, result); ASSERT_EQ(resultValue->GetDouble(), 101.5); + TestHelper::TearDownFrame(thread, prev); } // Reflect.getOwnPropertyDescriptor ( target, propertyKey ) @@ -292,8 +297,8 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectGetOwnPropertyDescriptor) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectGetOwnPropertyDescriptor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectGetOwnPropertyDescriptor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); @@ -315,6 +320,7 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectGetOwnPropertyDescriptor) JSHandle configurableKey = globalConst->GetHandledConfigurableString(); JSHandle resultConfigurable = JSObject::GetProperty(thread, resultObj, configurableKey).GetValue(); ASSERT_EQ(resultConfigurable->ToBoolean(), true); + TestHelper::TearDownFrame(thread, prev); } // Reflect.getPrototypeOf (target) @@ -334,11 +340,12 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectGetPrototypeOf) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectGetPrototypeOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectGetPrototypeOf(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultObj(thread, JSTaggedValue(reinterpret_cast(result.GetRawData()))); ASSERT_EQ(JSTaggedValue::SameValue(resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prev); } // Reflect.has (target, propertyKey) @@ -360,10 +367,11 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectHas) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectHas(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectHas(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Reflect.isExtensible (target) @@ -381,10 +389,11 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectIsExtensible) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectIsExtensible(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectIsExtensible(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); + TestHelper::TearDownFrame(thread, prev); } // Reflect.ownKeys (target) @@ -407,8 +416,8 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectOwnKeys) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectOwnKeys(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectOwnKeys(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultTaggedValue(thread, reinterpret_cast(result.GetRawData())); @@ -432,6 +441,7 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectOwnKeys) ASSERT_EQ(reinterpret_cast(resultValue1.GetTaggedValue().GetTaggedObject()) ->Compare(reinterpret_cast(key1.GetTaggedValue().GetTaggedObject())), 0); + TestHelper::TearDownFrame(thread, prev); } // Reflect.preventExtensions (target) @@ -449,11 +459,12 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectPreventExtensions) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectPreventExtensions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectPreventExtensions(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); ASSERT_EQ(target->IsExtensible(), false); + TestHelper::TearDownFrame(thread, prev); } // Reflect.set (target, propertyKey, V [ , receiver]) @@ -476,13 +487,14 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectSet) ecmaRuntimeCallInfo->SetCallArg(1, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectSet(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectSet(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle ruler = JSObject::GetProperty(thread, JSHandle(target), key).GetValue(); ASSERT_EQ(JSTaggedValue::ToInt32(thread, ruler), 106); + TestHelper::TearDownFrame(thread, prev); } // Reflect.setPrototypeOf (target, proto) @@ -501,11 +513,12 @@ HWTEST_F_L0(BuiltinsReflectTest, ReflectSetPrototypeOf) ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, proto.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsReflect::ReflectSetPrototypeOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsReflect::ReflectSetPrototypeOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); JSHandle resultObj(thread, target->GetJSHClass()->GetPrototype()); ASSERT_EQ(JSTaggedValue::SameValue(resultObj.GetTaggedValue(), proto.GetTaggedValue()), true); + TestHelper::TearDownFrame(thread, prev); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_regexp_test.cpp b/ecmascript/builtins/tests/builtins_regexp_test.cpp index d16dc20c7418d7af64f97a1ebf189552e59998a6..340314cd64ba6e4b8657001cae7d55f8c0b1b876 100644 --- a/ecmascript/builtins/tests/builtins_regexp_test.cpp +++ b/ecmascript/builtins/tests/builtins_regexp_test.cpp @@ -76,9 +76,10 @@ JSTaggedValue CreateBuiltinsRegExpObjByPatternAndFlags(JSThread *thread, const J ecmaRuntimeCallInfo->SetCallArg(0, pattern.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, flags.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke RegExpConstructor method - JSTaggedValue result = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue result = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -119,9 +120,10 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpConstructor2) ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke RegExpConstructor method - JSTaggedValue result2 = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); // ASSERT IsRegExp() JSHandle regexpObject(thread, result2); @@ -154,9 +156,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpConstructor3) ecmaRuntimeCallInfo->SetCallArg(0, value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, flags2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke RegExpConstructor method - JSTaggedValue result2 = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo); // ASSERT IsRegExp() JSHandle regexpObject(thread, result2); @@ -265,9 +267,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, toString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke ToString method - JSTaggedValue toStringResult = BuiltinsRegExp::ToString(ecmaRuntimeCallInfo.get()); + JSTaggedValue toStringResult = BuiltinsRegExp::ToString(ecmaRuntimeCallInfo); ASSERT_TRUE(toStringResult.IsString()); JSHandle toStringResultHandle(thread, toStringResult); JSHandle expectResult = thread->GetEcmaVM()->GetFactory()->NewFromASCII("/\\w+/gimuy"); @@ -290,9 +292,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Exec1) ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Exec method - JSTaggedValue results = BuiltinsRegExp::Exec(ecmaRuntimeCallInfo.get()); + JSTaggedValue results = BuiltinsRegExp::Exec(ecmaRuntimeCallInfo); JSHandle execResult(thread, results); JSHandle resultZero = @@ -348,9 +350,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Exec2) ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Exec method - JSTaggedValue results = BuiltinsRegExp::Exec(ecmaRuntimeCallInfo.get()); + JSTaggedValue results = BuiltinsRegExp::Exec(ecmaRuntimeCallInfo); JSHandle execResult(thread, results); JSHandle resultZero = thread->GetEcmaVM()->GetFactory()->NewFromASCII("123"); @@ -425,9 +427,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Match1) ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Match method - JSTaggedValue matchResults = BuiltinsRegExp::Match(ecmaRuntimeCallInfo.get()); + JSTaggedValue matchResults = BuiltinsRegExp::Match(ecmaRuntimeCallInfo); JSHandle matchResult(thread, matchResults); JSHandle zero(thread->GetEcmaVM()->GetFactory()->NewFromASCII("0")); @@ -454,9 +456,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Test1) ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Test method - JSTaggedValue testResult = BuiltinsRegExp::Test(ecmaRuntimeCallInfo.get()); + JSTaggedValue testResult = BuiltinsRegExp::Test(ecmaRuntimeCallInfo); ASSERT_EQ(testResult.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -476,9 +478,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Search1) ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Search method - JSTaggedValue searchResult = BuiltinsRegExp::Search(ecmaRuntimeCallInfo.get()); + JSTaggedValue searchResult = BuiltinsRegExp::Search(ecmaRuntimeCallInfo); ASSERT_EQ(searchResult.GetRawData(), JSTaggedValue(4).GetRawData()); } @@ -498,9 +500,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Split1) ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Split method - JSTaggedValue splitResults = BuiltinsRegExp::Split(ecmaRuntimeCallInfo.get()); + JSTaggedValue splitResults = BuiltinsRegExp::Split(ecmaRuntimeCallInfo); JSHandle splitResult(thread, splitResults); JSHandle zero(thread->GetEcmaVM()->GetFactory()->NewFromASCII("0")); @@ -526,9 +528,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Split2) ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke Split method - JSTaggedValue splitResults = BuiltinsRegExp::Split(ecmaRuntimeCallInfo.get()); + JSTaggedValue splitResults = BuiltinsRegExp::Split(ecmaRuntimeCallInfo); JSHandle splitResult(thread, splitResults); JSHandle resultZero = thread->GetEcmaVM()->GetFactory()->NewFromASCII("a"); JSHandle resultOne = thread->GetEcmaVM()->GetFactory()->NewFromASCII("b"); @@ -583,9 +585,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Replace1) ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke replace method - JSTaggedValue results = BuiltinsRegExp::Replace(ecmaRuntimeCallInfo.get()); + JSTaggedValue results = BuiltinsRegExp::Replace(ecmaRuntimeCallInfo); JSHandle replaceResult(thread, results); JSHandle resultZero = thread->GetEcmaVM()->GetFactory()->NewFromASCII( "The Quick Brown Fox Jumpsa The Over The Lazy Dog Jumps Brown $1 Jumps1 $32 a Over The Lazy Dog"); @@ -609,9 +611,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Replace2) ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke replace method - JSTaggedValue results = BuiltinsRegExp::Replace(ecmaRuntimeCallInfo.get()); + JSTaggedValue results = BuiltinsRegExp::Replace(ecmaRuntimeCallInfo); JSHandle replaceResult(thread, results); JSHandle resultZero = factory->NewFromASCII("a[cd$04$00]e"); ASSERT_EQ(static_cast(replaceResult->GetTaggedObject())->Compare(*resultZero), 0); @@ -634,9 +636,9 @@ HWTEST_F_L0(BuiltinsRegExpTest, Replace3) ecmaRuntimeCallInfo->SetCallArg(0, inputString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceString.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // invoke replace method - JSTaggedValue results = BuiltinsRegExp::Replace(ecmaRuntimeCallInfo.get()); + JSTaggedValue results = BuiltinsRegExp::Replace(ecmaRuntimeCallInfo); JSHandle replaceResult(thread, results); JSHandle resultZero = factory->NewFromASCII("de"); ASSERT_EQ(static_cast(replaceResult->GetTaggedObject())->Compare(*resultZero), 0); @@ -648,10 +650,12 @@ HWTEST_F_L0(BuiltinsRegExpTest, RegExpParseCache) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle string1 = factory->NewFromASCII("abc"); JSHandle string2 = factory->NewFromASCII("abcd"); - regExpParserCache->SetCache(*string1, 0, JSTaggedValue::True(), 2); - ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0).first == JSTaggedValue::True()); - ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0).second == 2U); - ASSERT_TRUE(regExpParserCache->GetCache(*string1, RegExpParserCache::CACHE_SIZE).first == JSTaggedValue::Hole()); - ASSERT_TRUE(regExpParserCache->GetCache(*string2, 0).first == JSTaggedValue::Hole()); + CVector vec; + regExpParserCache->SetCache(*string1, 0, JSTaggedValue::True(), 2, vec); + ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0, vec).first == JSTaggedValue::True()); + ASSERT_TRUE(regExpParserCache->GetCache(*string1, 0, vec).second == 2U); + ASSERT_TRUE(regExpParserCache->GetCache(*string1, + RegExpParserCache::CACHE_SIZE, vec).first == JSTaggedValue::Hole()); + ASSERT_TRUE(regExpParserCache->GetCache(*string2, 0, vec).first == JSTaggedValue::Hole()); } } // namespace panda::test diff --git a/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp b/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp index 724a1f968befa0cbd90d527f2dbb8ad4e980887f..6dd286a20c8a6253f80cb8c047df523f8138181c 100644 --- a/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp +++ b/ecmascript/builtins/tests/builtins_relative_time_format_test.cpp @@ -59,7 +59,7 @@ public: JSThread *thread {nullptr}; }; -// new RelativeTimeFormat(newTarget is defined) +// new RelativeTimeFormat(newTarget is undefined) HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, RelativeTimeFormatConstructor) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -74,8 +74,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, RelativeTimeFormatConstructor) // option tag is default value ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSRelativeTimeFormat()); @@ -100,9 +100,10 @@ static JSTaggedValue JSRelativeTimeFormatCreateWithLocaleTest(JSThread *thread, ecmaRuntimeCallInfo->SetCallArg(0, localesString.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, optionsObj.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::RelativeTimeFormatConstructor(ecmaRuntimeCallInfo); EXPECT_TRUE(result.IsJSRelativeTimeFormat()); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -123,8 +124,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_001) ecmaRuntimeCallInfo->SetCallArg(0, numberValue.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, unitValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -148,8 +149,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_002) ecmaRuntimeCallInfo->SetCallArg(0, numberValue.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, unitValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -173,8 +174,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_003) ecmaRuntimeCallInfo->SetCallArg(0, numberValue.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, unitValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -198,8 +199,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_004) ecmaRuntimeCallInfo->SetCallArg(0, numberValue.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, unitValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -223,8 +224,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, Format_005) ecmaRuntimeCallInfo->SetCallArg(0, numberValue.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, unitValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::Format(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleEcmaStr(thread, result); @@ -249,8 +250,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, FormatToParts) ecmaRuntimeCallInfo->SetCallArg(0, numberValue.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, unitValue.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::FormatToParts(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::FormatToParts(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultArr(thread, result); @@ -271,8 +272,8 @@ HWTEST_F_L0(BuiltinsRelativeTimeFormatTest, ResolvedOptions) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsPluralRules.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRelativeTimeFormat::ResolvedOptions(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRelativeTimeFormat::ResolvedOptions(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj = diff --git a/ecmascript/builtins/tests/builtins_set_test.cpp b/ecmascript/builtins/tests/builtins_set_test.cpp index bf9b491d5451458d0218b5c00a784d0738a02bd2..295d975772f2923d9408aefe408bf8882c012ffc 100644 --- a/ecmascript/builtins/tests/builtins_set_test.cpp +++ b/ecmascript/builtins/tests/builtins_set_test.cpp @@ -88,8 +88,9 @@ JSSet *CreateBuiltinsSet(JSThread *thread) ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSet::SetConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSet::SetConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsECMAObject()); return JSSet::Cast(reinterpret_cast(result.GetRawData())); @@ -107,8 +108,9 @@ HWTEST_F_L0(BuiltinsSetTest, CreateAndGetSize) ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSet::GetSize(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSet::GetSize(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -125,8 +127,9 @@ HWTEST_F_L0(BuiltinsSetTest, CreateAndGetSize) ecmaRuntimeCallInfo1->SetCallArg(0, values.GetTaggedValue()); ecmaRuntimeCallInfo1->SetNewTarget(newTarget.GetTaggedValue()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsSet::SetConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsSet::SetConstructor(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(JSSet::Cast(reinterpret_cast(result1.GetRawData()))->GetSize(), 5); } @@ -144,13 +147,14 @@ HWTEST_F_L0(BuiltinsSetTest, AddAndHas) ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsSet::Has(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsSet::Has(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Add() - JSTaggedValue result2 = BuiltinsSet::Add(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsSet::Add(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); JSSet *jsSet = JSSet::Cast(reinterpret_cast(result2.GetRawData())); EXPECT_EQ(jsSet->GetSize(), 1); @@ -161,8 +165,9 @@ HWTEST_F_L0(BuiltinsSetTest, AddAndHas) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsSet)); ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); { - [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result3 = BuiltinsSet::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result3 = BuiltinsSet::Has(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prevLocal); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -175,8 +180,9 @@ HWTEST_F_L0(BuiltinsSetTest, AddAndHas) ecmaRuntimeCallInfo2->SetThis(JSTaggedValue(jsSet)); ecmaRuntimeCallInfo2->SetCallArg(0, negativeZero.GetTaggedValue()); { - [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - BuiltinsSet::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + BuiltinsSet::Add(ecmaRuntimeCallInfo2); + TestHelper::TearDownFrame(thread, prevLocal); } auto ecmaRuntimeCallInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -184,10 +190,11 @@ HWTEST_F_L0(BuiltinsSetTest, AddAndHas) ecmaRuntimeCallInfo3->SetThis(JSTaggedValue(jsSet)); ecmaRuntimeCallInfo3->SetCallArg(0, positiveZero.GetTaggedValue()); { - [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result4 = BuiltinsSet::Has(ecmaRuntimeCallInfo3.get()); + [[maybe_unused]] auto prevLocal = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + [[maybe_unused]] JSTaggedValue result4 = BuiltinsSet::Has(ecmaRuntimeCallInfo3); + TestHelper::TearDownFrame(thread, prevLocal); - EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); + EXPECT_EQ(result4.GetRawData(), JSTaggedValue::True().GetRawData()); } } @@ -205,8 +212,9 @@ HWTEST_F_L0(BuiltinsSetTest, ForEach) ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsSet::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsSet::Add(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsECMAObject()); JSSet *jsSet = JSSet::Cast(reinterpret_cast(result1.GetRawData())); @@ -223,8 +231,9 @@ HWTEST_F_L0(BuiltinsSetTest, ForEach) ecmaRuntimeCallInfo1->SetCallArg(0, func.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, jsArray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsSet::ForEach(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsSet::ForEach(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(jsArray->GetArrayLength(), 5U); @@ -247,8 +256,9 @@ HWTEST_F_L0(BuiltinsSetTest, DeleteAndRemove) ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsSet::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsSet::Add(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsECMAObject()); JSSet *jsSet = JSSet::Cast(reinterpret_cast(result1.GetRawData())); @@ -263,27 +273,27 @@ HWTEST_F_L0(BuiltinsSetTest, DeleteAndRemove) ecmaRuntimeCallInfo1->SetThis(set.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, deleteKey.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsSet::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsSet::Has(ecmaRuntimeCallInfo1); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsSet::Delete(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = BuiltinsSet::Delete(ecmaRuntimeCallInfo1); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsSet::Has(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result4 = BuiltinsSet::Has(ecmaRuntimeCallInfo1); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); - JSTaggedValue result5 = BuiltinsSet::GetSize(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result5 = BuiltinsSet::GetSize(ecmaRuntimeCallInfo1); EXPECT_EQ(result5.GetRawData(), JSTaggedValue(39).GetRawData()); // clear - JSTaggedValue result6 = BuiltinsSet::Clear(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result6 = BuiltinsSet::Clear(ecmaRuntimeCallInfo1); EXPECT_EQ(result6.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); EXPECT_EQ(set->GetSize(), 0); } @@ -345,17 +355,17 @@ HWTEST_F_L0(BuiltinsSetTest, GetIterator) auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(set.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); // test Values() - JSTaggedValue result = BuiltinsSet::Values(ecmaRuntimeCallInfo.get()); + JSTaggedValue result = BuiltinsSet::Values(ecmaRuntimeCallInfo); JSHandle iter(thread, result); EXPECT_TRUE(iter->IsJSSetIterator()); EXPECT_EQ(IterationKind::VALUE, IterationKind(iter->GetIterationKind())); EXPECT_EQ(JSSet::Cast(set.GetTaggedValue().GetTaggedObject())->GetLinkedSet(), iter->GetIteratedSet()); // test entries() - JSTaggedValue result2 = BuiltinsSet::Entries(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsSet::Entries(ecmaRuntimeCallInfo); JSHandle iter2(thread, result2); EXPECT_TRUE(iter2->IsJSSetIterator()); EXPECT_EQ(IterationKind::KEY_AND_VALUE, iter2->GetIterationKind()); diff --git a/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp b/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp index 409028bb8329aefff767a9283a372c158eb49915..4b0ec1b83e3fba86ccd8567c73f0344f2797eafe 100644 --- a/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp +++ b/ecmascript/builtins/tests/builtins_sharedarraybuffer_test.cpp @@ -65,8 +65,9 @@ JSTaggedValue CreateBuiltinsSharedArrayBuffer(JSThread *thread, int32_t length) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(length)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSharedArrayBuffer::SharedArrayBufferConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSharedArrayBuffer::SharedArrayBufferConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -81,8 +82,8 @@ HWTEST_F_L0(BuiltinsSharedArrayBufferTest, Constructor1) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(20))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSharedArrayBuffer::SharedArrayBufferConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSharedArrayBuffer::SharedArrayBufferConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); } @@ -95,8 +96,8 @@ HWTEST_F_L0(BuiltinsSharedArrayBufferTest, byteLength1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(arrBuf.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSharedArrayBuffer::GetByteLength(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSharedArrayBuffer::GetByteLength(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(18).GetRawData()); } @@ -111,16 +112,16 @@ HWTEST_F_L0(BuiltinsSharedArrayBufferTest, slice1) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsSharedArrayBuffer::Slice(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsSharedArrayBuffer::Slice(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle arrBuf1(thread, JSArrayBuffer::Cast(reinterpret_cast(result1.GetRawData()))); auto ecmaRuntimeCallInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(arrBuf1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsSharedArrayBuffer::GetByteLength(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsSharedArrayBuffer::GetByteLength(ecmaRuntimeCallInfo1); ASSERT_EQ(result2.GetRawData(), JSTaggedValue(4).GetRawData()); } diff --git a/ecmascript/builtins/tests/builtins_string_iterator_test.cpp b/ecmascript/builtins/tests/builtins_string_iterator_test.cpp index 739777844e2563ba82e9d45ca7a9817f76ae4240..ba0791908f2e750c26c530f59b4afd11de3e1c6a 100644 --- a/ecmascript/builtins/tests/builtins_string_iterator_test.cpp +++ b/ecmascript/builtins/tests/builtins_string_iterator_test.cpp @@ -74,8 +74,8 @@ HWTEST_F_L0(BuiltinsStringIteratorTest, Next_001) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(stringIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsStringIterator::Next(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsStringIterator::Next(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(stringIterator->GetStringIteratorNextIndex(), 1U); @@ -83,8 +83,8 @@ HWTEST_F_L0(BuiltinsStringIteratorTest, Next_001) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(stringIterator.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - BuiltinsStringIterator::Next(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + BuiltinsStringIterator::Next(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(stringIterator->GetStringIteratorNextIndex(), 2U); @@ -92,8 +92,8 @@ HWTEST_F_L0(BuiltinsStringIteratorTest, Next_001) ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo3->SetThis(stringIterator.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result = BuiltinsStringIterator::Next(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result = BuiltinsStringIterator::Next(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); @@ -113,8 +113,8 @@ HWTEST_F_L0(BuiltinsStringIteratorTest, Next_002) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(stringIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsStringIterator::Next(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsStringIterator::Next(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(stringIterator->GetStringIteratorNextIndex(), 1U); @@ -122,8 +122,8 @@ HWTEST_F_L0(BuiltinsStringIteratorTest, Next_002) ecmaRuntimeCallInfo2->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetThis(stringIterator.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - BuiltinsStringIterator::Next(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + BuiltinsStringIterator::Next(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(stringIterator->GetStringIteratorNextIndex(), 3U); @@ -131,8 +131,8 @@ HWTEST_F_L0(BuiltinsStringIteratorTest, Next_002) ecmaRuntimeCallInfo3->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo3->SetThis(stringIterator.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result = BuiltinsStringIterator::Next(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result = BuiltinsStringIterator::Next(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/builtins/tests/builtins_string_test.cpp b/ecmascript/builtins/tests/builtins_string_test.cpp index 0c04daf30957d4dd72f1dbfd73fcdc98119b657e..3b51c19d6ebd32a4880678a404842dfe8d1b660f 100644 --- a/ecmascript/builtins/tests/builtins_string_test.cpp +++ b/ecmascript/builtins/tests/builtins_string_test.cpp @@ -73,8 +73,9 @@ JSTaggedValue CreateBuiltinsStringRegExpObjByPatternAndFlags(JSThread *thread, c ecmaRuntimeCallInfo->SetCallArg(0, pattern.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, flags.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsRegExp::RegExpConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); return result; } @@ -92,8 +93,8 @@ HWTEST_F_L0(BuiltinsStringTest, StringConstructor1) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, string2.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::StringConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::StringConstructor(ecmaRuntimeCallInfo); JSTaggedValue value(static_cast(result.GetRawData())); ASSERT_TRUE(value.IsECMAObject()); JSHandle ref(thread, JSPrimitiveRef::Cast(value.GetTaggedObject())); @@ -118,8 +119,8 @@ HWTEST_F_L0(BuiltinsStringTest, fromCharCode1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(arg2)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(arg3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::FromCharCode(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::FromCharCode(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSTaggedValue value(static_cast(result.GetRawData())); JSHandle valueHandle(thread, JSTaggedValue(value.GetTaggedObject())); @@ -144,8 +145,8 @@ HWTEST_F_L0(BuiltinsStringTest, fromCodePoint1) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(arg2)); ecmaRuntimeCallInfo->SetCallArg(2, JSTaggedValue(arg3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::FromCodePoint(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::FromCodePoint(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("ABC").GetTaggedValue(); @@ -163,8 +164,8 @@ HWTEST_F_L0(BuiltinsStringTest, charAt1) ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::CharAt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::CharAt(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("c").GetTaggedValue(); @@ -182,8 +183,8 @@ HWTEST_F_L0(BuiltinsStringTest, charAt2) ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::CharAt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::CharAt(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromUtf8("三").GetTaggedValue(); @@ -201,8 +202,8 @@ HWTEST_F_L0(BuiltinsStringTest, charAt3) ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::CharAt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::CharAt(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->GetEmptyString().GetTaggedValue(); @@ -220,8 +221,8 @@ HWTEST_F_L0(BuiltinsStringTest, charCodeAt1) ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::CharCodeAt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::CharCodeAt(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(65).GetRawData()); } @@ -237,8 +238,8 @@ HWTEST_F_L0(BuiltinsStringTest, charCodeAt2) ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(-1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::CharCodeAt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::CharCodeAt(ecmaRuntimeCallInfo); JSTaggedValue test = BuiltinsString::GetTaggedDouble(base::NAN_VALUE); ASSERT_EQ(result.GetRawData(), test.GetRawData()); @@ -255,8 +256,8 @@ HWTEST_F_L0(BuiltinsStringTest, codePointAt1) ecmaRuntimeCallInfo->SetThis(thisVal.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::CodePointAt(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::CodePointAt(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(66).GetRawData()); } @@ -277,8 +278,8 @@ HWTEST_F_L0(BuiltinsStringTest, concat1) ecmaRuntimeCallInfo->SetCallArg(1, val2.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(2, val3.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Concat(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Concat(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("abcd").GetTaggedValue(); @@ -297,8 +298,8 @@ HWTEST_F_L0(BuiltinsStringTest, indexof1) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::IndexOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::IndexOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -316,8 +317,8 @@ HWTEST_F_L0(BuiltinsStringTest, indexof2) ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::IndexOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::IndexOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(4).GetRawData()); } @@ -334,8 +335,8 @@ HWTEST_F_L0(BuiltinsStringTest, indexof3) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::IndexOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::IndexOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -352,8 +353,8 @@ HWTEST_F_L0(BuiltinsStringTest, lastIndexOf1) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::LastIndexOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::LastIndexOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(7).GetRawData()); } @@ -370,8 +371,8 @@ HWTEST_F_L0(BuiltinsStringTest, lastIndexOf2) ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::LastIndexOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::LastIndexOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -388,8 +389,8 @@ HWTEST_F_L0(BuiltinsStringTest, lastIndexOf3) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::LastIndexOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::LastIndexOf(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -406,8 +407,8 @@ HWTEST_F_L0(BuiltinsStringTest, Includes2) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Includes(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Includes(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -425,8 +426,8 @@ HWTEST_F_L0(BuiltinsStringTest, Includes3) ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Includes(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Includes(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -443,8 +444,8 @@ HWTEST_F_L0(BuiltinsStringTest, Includes4) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Includes(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Includes(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -461,8 +462,8 @@ HWTEST_F_L0(BuiltinsStringTest, startsWith1) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::StartsWith(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::StartsWith(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -479,8 +480,8 @@ HWTEST_F_L0(BuiltinsStringTest, startsWith2) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::StartsWith(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::StartsWith(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -498,8 +499,8 @@ HWTEST_F_L0(BuiltinsStringTest, startsWith3) ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(10))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::StartsWith(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::StartsWith(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -516,8 +517,8 @@ HWTEST_F_L0(BuiltinsStringTest, endsWith1) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::EndsWith(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::EndsWith(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -534,8 +535,8 @@ HWTEST_F_L0(BuiltinsStringTest, endsWith2) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::EndsWith(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::EndsWith(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::False().GetRawData()); } @@ -553,8 +554,8 @@ HWTEST_F_L0(BuiltinsStringTest, endsWith3) ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(19))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::EndsWith(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::EndsWith(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -570,8 +571,8 @@ HWTEST_F_L0(BuiltinsStringTest, toLocaleLowerCase2) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(this_str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::ToLocaleLowerCase(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::ToLocaleLowerCase(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromUtf8("有abc").GetTaggedValue(); @@ -588,8 +589,8 @@ HWTEST_F_L0(BuiltinsStringTest, toLowerCase1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::ToLowerCase(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::ToLowerCase(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSHandle test = factory->NewFromASCII("abc"); @@ -606,8 +607,8 @@ HWTEST_F_L0(BuiltinsStringTest, toUpperCase1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::ToUpperCase(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::ToUpperCase(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("ABC").GetTaggedValue(); @@ -626,8 +627,8 @@ HWTEST_F_L0(BuiltinsStringTest, localecompare1) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::LocaleCompare(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::LocaleCompare(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(-1).GetRawData()); } @@ -644,8 +645,8 @@ HWTEST_F_L0(BuiltinsStringTest, localecompare2) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::LocaleCompare(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::LocaleCompare(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(0).GetRawData()); } @@ -662,8 +663,8 @@ HWTEST_F_L0(BuiltinsStringTest, localecompare3) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::LocaleCompare(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::LocaleCompare(ecmaRuntimeCallInfo); ASSERT_EQ(result.GetRawData(), JSTaggedValue(1).GetRawData()); } @@ -681,8 +682,8 @@ HWTEST_F_L0(BuiltinsStringTest, normalize1) ecmaRuntimeCallInfo->SetThis(this_str.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, val.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Normalize(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Normalize(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle result_handle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("abc").GetTaggedValue(); @@ -700,8 +701,8 @@ HWTEST_F_L0(BuiltinsStringTest, repeat1) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(5))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Repeat(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Repeat(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("abcabcabcabcabc").GetTaggedValue(); @@ -720,8 +721,8 @@ HWTEST_F_L0(BuiltinsStringTest, slice1) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(4))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Slice(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Slice(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("morning is upon u").GetTaggedValue(); @@ -739,8 +740,8 @@ HWTEST_F_L0(BuiltinsStringTest, slice2) ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(12))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Slice(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Slice(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("is upon us.").GetTaggedValue(); @@ -759,8 +760,8 @@ HWTEST_F_L0(BuiltinsStringTest, substring1) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(-3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Substring(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Substring(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("Moz").GetTaggedValue(); @@ -779,8 +780,8 @@ HWTEST_F_L0(BuiltinsStringTest, substring2) ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(7))); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(4))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Substring(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Substring(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("lla").GetTaggedValue(); @@ -797,8 +798,8 @@ HWTEST_F_L0(BuiltinsStringTest, trim1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(thisStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Trim(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Trim(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("Hello world!").GetTaggedValue(); @@ -820,8 +821,8 @@ HWTEST_F_L0(BuiltinsStringTest, trim2) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Trim(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Trim(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = factory->NewFromASCII("Hello world!").GetTaggedValue(); @@ -843,8 +844,8 @@ HWTEST_F_L0(BuiltinsStringTest, ToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::ToString(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = JSTaggedValue(*thisStr); @@ -866,8 +867,8 @@ HWTEST_F_L0(BuiltinsStringTest, ValueOf) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(str.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::ValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::ValueOf(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); JSTaggedValue test = JSTaggedValue(*thisStr); @@ -915,8 +916,8 @@ HWTEST_F_L0(BuiltinsStringTest, Raw) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(5))); ecmaRuntimeCallInfo->SetCallArg(2, javascript.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Raw(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Raw(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *test)); } @@ -935,8 +936,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -951,8 +952,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) ecmaRuntimeCallInfo1->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(1, replaceStr1.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result1 = BuiltinsString::Replace(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result1 = BuiltinsString::Replace(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle resultString1(thread, result1); @@ -968,8 +969,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) ecmaRuntimeCallInfo2->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, replaceStr2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsString::Replace(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsString::Replace(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); JSHandle resultString2(thread, result2); @@ -985,8 +986,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) ecmaRuntimeCallInfo3->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo3->SetCallArg(1, replaceStr3.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result3 = BuiltinsString::Replace(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result3 = BuiltinsString::Replace(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); JSHandle resultString3(thread, result3); @@ -1003,8 +1004,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace) ecmaRuntimeCallInfo4->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(1, replaceStr4.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - JSTaggedValue result4 = BuiltinsString::Replace(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + JSTaggedValue result4 = BuiltinsString::Replace(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); JSHandle resultString4(thread, result4); @@ -1026,8 +1027,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); @@ -1043,8 +1044,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) ecmaRuntimeCallInfo2->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(1, replaceStr2.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue result2 = BuiltinsString::Replace(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue result2 = BuiltinsString::Replace(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); JSHandle resultString2(thread, result2); @@ -1061,8 +1062,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) ecmaRuntimeCallInfo3->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo3->SetCallArg(1, replaceStr3.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - JSTaggedValue result3 = BuiltinsString::Replace(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + JSTaggedValue result3 = BuiltinsString::Replace(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); JSHandle resultString3(thread, result3); @@ -1079,8 +1080,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace2) ecmaRuntimeCallInfo4->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo4->SetCallArg(1, replaceStr4.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - JSTaggedValue result4 = BuiltinsString::Replace(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + JSTaggedValue result4 = BuiltinsString::Replace(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result4.IsString()); @@ -1103,8 +1104,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace3) ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1133,8 +1134,8 @@ HWTEST_F_L0(BuiltinsStringTest, Replace4) ecmaRuntimeCallInfo->SetCallArg(0, searchStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, replaceStr.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Replace(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsString()); ASSERT_TRUE(EcmaString::StringsAreEqual(reinterpret_cast(result.GetRawData()), *expected)); @@ -1157,8 +1158,8 @@ HWTEST_F_L0(BuiltinsStringTest, Split) ecmaRuntimeCallInfo->SetCallArg(0, separatorStr.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Split(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Split(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultArray(thread, reinterpret_cast(result.GetRawData())); @@ -1196,8 +1197,8 @@ HWTEST_F_L0(BuiltinsStringTest, Split2) ecmaRuntimeCallInfo->SetCallArg(0, separatorObj.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(3))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsString::Split(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsString::Split(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); JSHandle resultArray(thread, result); diff --git a/ecmascript/builtins/tests/builtins_symbol_test.cpp b/ecmascript/builtins/tests/builtins_symbol_test.cpp index 273a711115d13e24e2156880b423df7427681961..aaa63a7aba31982345cd6d530e11310fc1b716b5 100644 --- a/ecmascript/builtins/tests/builtins_symbol_test.cpp +++ b/ecmascript/builtins/tests/builtins_symbol_test.cpp @@ -75,8 +75,9 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolNoParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = Symbol::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = Symbol::ToString(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); ASSERT_TRUE(result.IsString()); @@ -95,8 +96,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolWithParameterToString) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = Symbol::ToString(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = Symbol::ToString(ecmaRuntimeCallInfo); JSHandle resultHandle(thread, reinterpret_cast(result.GetRawData())); ASSERT_TRUE(result.IsString()); @@ -116,8 +117,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolNoParameterValueOf) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::ValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::ValueOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -130,8 +131,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolNoParameterValueOf) otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); otherEcmaRuntimeCallInfo->SetThis(symbolRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo.get()); - JSTaggedValue otherResult = BuiltinsSymbol::ValueOf(otherEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo); + JSTaggedValue otherResult = BuiltinsSymbol::ValueOf(otherEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(otherResult.IsSymbol()); ASSERT_EQ(otherResult.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -149,8 +150,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolWithParameterValueOf) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::ValueOf(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::ValueOf(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -163,8 +164,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolWithParameterValueOf) otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); otherEcmaRuntimeCallInfo->SetThis(symbolRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo.get()); - JSTaggedValue otherResult = BuiltinsSymbol::ValueOf(otherEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo); + JSTaggedValue otherResult = BuiltinsSymbol::ValueOf(otherEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(otherResult.IsSymbol()); ASSERT_EQ(otherResult.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -190,8 +191,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolWithParameterFor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, string.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::For(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::For(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(tableHandle->ContainsKey(string_handle.GetTaggedValue()), true); @@ -212,8 +213,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolKeyFor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::KeyFor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::KeyFor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_EQ(result.GetRawData(), JSTaggedValue::VALUE_UNDEFINED); @@ -225,8 +226,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolKeyFor) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetCallArg(0, string.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - BuiltinsSymbol::For(ecmaRuntimeCallInfo1.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + BuiltinsSymbol::For(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); JSHandle otherSymbol = ecmaVM->GetFactory()->NewPublicSymbolWithChar("ccc"); @@ -235,8 +236,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolKeyFor) ecmaRuntimeCallInfo2->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo2->SetCallArg(0, otherSymbol.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - JSTaggedValue otherResult = BuiltinsSymbol::KeyFor(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + JSTaggedValue otherResult = BuiltinsSymbol::KeyFor(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(otherResult.IsString()); JSHandle tableHandle(env->GetRegisterSymbols()); @@ -256,8 +257,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolToPrimitive) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::ToPrimitive(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::ToPrimitive(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); ASSERT_EQ(result.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -270,8 +271,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolToPrimitive) otherEcmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); otherEcmaRuntimeCallInfo->SetThis(symbolRef.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo.get()); - JSTaggedValue otherResult = BuiltinsSymbol::ToPrimitive(otherEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo); + JSTaggedValue otherResult = BuiltinsSymbol::ToPrimitive(otherEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(otherResult.IsSymbol()); ASSERT_EQ(otherResult.GetRawData() == (JSTaggedValue(*symbol)).GetRawData(), true); @@ -287,8 +288,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolConstructor) ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::SymbolConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::SymbolConstructor(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsSymbol()); JSSymbol *sym = reinterpret_cast(result.GetRawData()); @@ -301,8 +302,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolConstructor) otherEcmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); otherEcmaRuntimeCallInfo->SetCallArg(0, string.GetTaggedValue()); - prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsSymbol::SymbolConstructor(otherEcmaRuntimeCallInfo.get()); + prev = TestHelper::SetupFrame(thread, otherEcmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsSymbol::SymbolConstructor(otherEcmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultString = JSTaggedValue::ToString( thread, JSHandle(thread, reinterpret_cast(result1.GetRawData())->GetDescription())); @@ -320,8 +321,8 @@ HWTEST_F_L0(BuiltinsSymbolTest, SymbolGetter) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(symbol.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsSymbol::DescriptionGetter(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsSymbol::DescriptionGetter(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsString()); EcmaString *resString = reinterpret_cast(result.GetRawData()); diff --git a/ecmascript/builtins/tests/builtins_typedarray_test.cpp b/ecmascript/builtins/tests/builtins_typedarray_test.cpp index 600a97702088db12f4f3c8edb4c0bccee81bb019..d288d059957e7ad56e66abf6556459a3a21c0cb1 100644 --- a/ecmascript/builtins/tests/builtins_typedarray_test.cpp +++ b/ecmascript/builtins/tests/builtins_typedarray_test.cpp @@ -90,7 +90,7 @@ protected: static JSTaggedValue TestEveryFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { [[maybe_unused]] int aaa = GetCallArg(argv, 0)->GetInt(); // 10 : test case @@ -104,7 +104,7 @@ protected: static JSTaggedValue TestFilterFunc(EcmaRuntimeCallInfo *argv) { ASSERT(argv); - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -123,7 +123,7 @@ protected: static JSTaggedValue TestFindFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -135,7 +135,7 @@ protected: static JSTaggedValue TestFindIndexFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -161,7 +161,7 @@ protected: static JSTaggedValue TestSomeFunc(EcmaRuntimeCallInfo *argv) { - uint32_t argc = argv->GetArgsNumber(); + int32_t argc = argv->GetArgsNumber(); if (argc > 0) { // 10 : test case if (GetCallArg(argv, 0)->GetInt() > 10) { @@ -201,8 +201,9 @@ JSTypedArray *CreateTypedArrayFromList(JSThread *thread, const JSHandleSetThis(JSTaggedValue(*globalObject)); ecmaRuntimeCallInfo1->SetCallArg(0, jsarray.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = TypedArray::Int8ArrayConstructor(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = TypedArray::Int8ArrayConstructor(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsECMAObject()); JSTypedArray *int8arr = JSTypedArray::Cast(reinterpret_cast(result.GetRawData())); @@ -221,8 +222,8 @@ HWTEST_F_L0(BuiltinsTypedArrayTest, Species) ecmaRuntimeCallInfo1->SetFunction(array.GetTaggedValue()); ecmaRuntimeCallInfo1->SetThis(globalObject.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result = TypedArray::Species(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result = TypedArray::Species(ecmaRuntimeCallInfo1); ASSERT_TRUE(result.IsECMAObject()); } @@ -242,8 +243,8 @@ HWTEST_F_L0(BuiltinsTypedArrayTest, Includes) ecmaRuntimeCallInfo1->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, JSTaggedValue(static_cast(2))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - [[maybe_unused]] JSTaggedValue result = TypedArray::Includes(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + [[maybe_unused]] JSTaggedValue result = TypedArray::Includes(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(2) @@ -253,8 +254,8 @@ HWTEST_F_L0(BuiltinsTypedArrayTest, Includes) ecmaRuntimeCallInfo2->SetThis(obj.GetTaggedValue()); ecmaRuntimeCallInfo2->SetCallArg(0, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2.get()); - result = TypedArray::Includes(ecmaRuntimeCallInfo2.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo2); + result = TypedArray::Includes(ecmaRuntimeCallInfo2); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(!result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(1) @@ -265,8 +266,8 @@ HWTEST_F_L0(BuiltinsTypedArrayTest, Includes) ecmaRuntimeCallInfo3->SetCallArg(0, JSTaggedValue(static_cast(3))); ecmaRuntimeCallInfo3->SetCallArg(1, JSTaggedValue(static_cast(1))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3.get()); - result = TypedArray::Includes(ecmaRuntimeCallInfo3.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo3); + result = TypedArray::Includes(ecmaRuntimeCallInfo3); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(3, 1) @@ -277,8 +278,8 @@ HWTEST_F_L0(BuiltinsTypedArrayTest, Includes) ecmaRuntimeCallInfo4->SetCallArg(0, JSTaggedValue(static_cast(2))); ecmaRuntimeCallInfo4->SetCallArg(1, JSTaggedValue(static_cast(5))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4.get()); - result = Array::Includes(ecmaRuntimeCallInfo4.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo4); + result = Array::Includes(ecmaRuntimeCallInfo4); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(!result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(2, 5) @@ -289,8 +290,8 @@ HWTEST_F_L0(BuiltinsTypedArrayTest, Includes) ecmaRuntimeCallInfo5->SetCallArg(0, JSTaggedValue(static_cast(2))); ecmaRuntimeCallInfo5->SetCallArg(1, JSTaggedValue(static_cast(-2))); - prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5.get()); - result = Array::Includes(ecmaRuntimeCallInfo5.get()); + prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo5); + result = Array::Includes(ecmaRuntimeCallInfo5); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(!result.JSTaggedValue::ToBoolean()); // new Int8Array[2,3,4].includes(2, -2) diff --git a/ecmascript/builtins/tests/builtins_weak_map_test.cpp b/ecmascript/builtins/tests/builtins_weak_map_test.cpp index 90d1ce1dc15ef1fc29bf701f8943b291b6e6645c..6b62b9b54f4f57222dffc1d26c06fca8d2c8bb9a 100644 --- a/ecmascript/builtins/tests/builtins_weak_map_test.cpp +++ b/ecmascript/builtins/tests/builtins_weak_map_test.cpp @@ -85,8 +85,9 @@ JSWeakMap *CreateBuiltinsWeakMap(JSThread *thread) ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsWeakMap::WeakMapConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsWeakMap::WeakMapConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsECMAObject()); return JSWeakMap::Cast(reinterpret_cast(result.GetRawData())); @@ -116,9 +117,9 @@ HWTEST_F_L0(BuiltinsWeakMapTest, CreateAndGetSize) ecmaRuntimeCallInfo->SetCallArg(0, values.GetTaggedValue()); ecmaRuntimeCallInfo->SetNewTarget(newTarget.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); - JSTaggedValue result1 = BuiltinsWeakMap::WeakMapConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsWeakMap::WeakMapConstructor(ecmaRuntimeCallInfo); JSHandle weakMap(thread, JSWeakMap::Cast(reinterpret_cast(result1.GetRawData()))); EXPECT_EQ(weakMap->GetSize(), 1); } @@ -136,14 +137,15 @@ HWTEST_F_L0(BuiltinsWeakMapTest, SetAndHas) ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(1))); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); } // test Set() - JSTaggedValue result2 = BuiltinsWeakMap::Set(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsWeakMap::Set(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); JSWeakMap *jsWeakMap = JSWeakMap::Cast(reinterpret_cast(result2.GetRawData())); EXPECT_EQ(jsWeakMap->GetSize(), 1); @@ -155,8 +157,9 @@ HWTEST_F_L0(BuiltinsWeakMapTest, SetAndHas) ecmaRuntimeCallInfo1->SetCallArg(1, JSTaggedValue(static_cast(1))); ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsWeakMap)); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result3 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result3 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -177,8 +180,9 @@ HWTEST_F_L0(BuiltinsWeakMapTest, DeleteAndRemove) ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(1, JSTaggedValue(static_cast(i))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsWeakMap::Set(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsWeakMap::Set(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsECMAObject()); JSWeakMap *jsWeakMap = JSWeakMap::Cast(reinterpret_cast(result1.GetRawData())); @@ -193,18 +197,19 @@ HWTEST_F_L0(BuiltinsWeakMapTest, DeleteAndRemove) ecmaRuntimeCallInfo1->SetThis(weakMap.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, lastKey); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsWeakMap::Delete(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = BuiltinsWeakMap::Delete(ecmaRuntimeCallInfo1); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result4 = BuiltinsWeakMap::Has(ecmaRuntimeCallInfo1); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } diff --git a/ecmascript/builtins/tests/builtins_weak_ref_test.cpp b/ecmascript/builtins/tests/builtins_weak_ref_test.cpp index c25e0697f79a581da6d6e14a537ca69772f5bf8e..6fbab214bc985a2e80c2c25fa73e1c9818def42c 100644 --- a/ecmascript/builtins/tests/builtins_weak_ref_test.cpp +++ b/ecmascript/builtins/tests/builtins_weak_ref_test.cpp @@ -77,8 +77,10 @@ JSTaggedValue CreateWeakRefConstructor(JSThread *thread, JSTaggedValue target) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, target); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - return JSTaggedValue(BuiltinsWeakRef::WeakRefConstructor(ecmaRuntimeCallInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsWeakRef::WeakRefConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); + return result; } // new WeakRef(target) @@ -98,8 +100,8 @@ HWTEST_F_L0(BuiltinsWeakRefTest, WeakRefConstructor) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, target.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsWeakRef::WeakRefConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsWeakRef::WeakRefConstructor(ecmaRuntimeCallInfo); ASSERT_TRUE(result.IsECMAObject()); } @@ -118,9 +120,9 @@ HWTEST_F_L0(BuiltinsWeakRefTest, Deref1) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsWeakRef.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); - JSTaggedValue result1 = BuiltinsWeakRef::Deref(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsWeakRef::Deref(ecmaRuntimeCallInfo); ASSERT_EQ(result1, target.GetTaggedValue()); } @@ -143,9 +145,9 @@ HWTEST_F_L0(BuiltinsWeakRefTest, Deref2) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(jsWeakRef.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); - JSTaggedValue result1 = BuiltinsWeakRef::Deref(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsWeakRef::Deref(ecmaRuntimeCallInfo); ASSERT_EQ(result1, target.GetTaggedValue()); JSObject::SetProperty(thread, target, styleKey, styleValue); @@ -175,8 +177,8 @@ HWTEST_F_L0(BuiltinsWeakRefTest, Deref3) ecmaRuntimeCallInfo1->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo1->SetThis(jsWeakRef.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - result2 = BuiltinsWeakRef::Deref(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + result2 = BuiltinsWeakRef::Deref(ecmaRuntimeCallInfo1); TestHelper::TearDownFrame(thread, prev1); } vm->CollectGarbage(TriggerGCType::FULL_GC); diff --git a/ecmascript/builtins/tests/builtins_weak_set_test.cpp b/ecmascript/builtins/tests/builtins_weak_set_test.cpp index 445921fbf2ab3e526f626de8ec43e615a0b2f508..1be69bd434738e01091b6b096262126f0f5d7a4e 100644 --- a/ecmascript/builtins/tests/builtins_weak_set_test.cpp +++ b/ecmascript/builtins/tests/builtins_weak_set_test.cpp @@ -84,8 +84,9 @@ JSWeakSet *CreateBuiltinsWeakSet(JSThread *thread) auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*newTarget), 4); ecmaRuntimeCallInfo->SetFunction(newTarget.GetTaggedValue()); ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = BuiltinsWeakSet::WeakSetConstructor(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = BuiltinsWeakSet::WeakSetConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsECMAObject()); JSWeakSet *jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result.GetRawData())); @@ -112,9 +113,10 @@ HWTEST_F_L0(BuiltinsWeakSetTest, CreateAndGetSize) ecmaRuntimeCallInfo->SetCallArg(0, values.GetTaggedValue()); ecmaRuntimeCallInfo->SetNewTarget(newTarget.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); - JSTaggedValue result1 = BuiltinsWeakSet::WeakSetConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue result1 = BuiltinsWeakSet::WeakSetConstructor(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); JSHandle weakSetResult(thread, JSWeakSet::Cast(reinterpret_cast(result1.GetRawData()))); EXPECT_EQ(weakSetResult->GetSize(), 5); @@ -132,13 +134,14 @@ HWTEST_F_L0(BuiltinsWeakSetTest, AddAndHas) JSWeakSet *jsWeakSet; { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result1.GetRawData(), JSTaggedValue::False().GetRawData()); // test Add() - JSTaggedValue result2 = BuiltinsWeakSet::Add(ecmaRuntimeCallInfo.get()); + JSTaggedValue result2 = BuiltinsWeakSet::Add(ecmaRuntimeCallInfo); EXPECT_TRUE(result2.IsECMAObject()); jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result2.GetRawData())); EXPECT_EQ(jsWeakSet->GetSize(), 1); @@ -150,8 +153,9 @@ HWTEST_F_L0(BuiltinsWeakSetTest, AddAndHas) ecmaRuntimeCallInfo1->SetThis(JSTaggedValue(jsWeakSet)); ecmaRuntimeCallInfo1->SetCallArg(0, key.GetTaggedValue()); { - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result3 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result3 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); } @@ -172,8 +176,9 @@ HWTEST_F_L0(BuiltinsWeakSetTest, DeleteAndRemove) ecmaRuntimeCallInfo->SetThis(weakSet.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result1 = BuiltinsWeakSet::Add(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result1 = BuiltinsWeakSet::Add(ecmaRuntimeCallInfo); + TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsECMAObject()); JSWeakSet *jsWeakSet = JSWeakSet::Cast(reinterpret_cast(result1.GetRawData())); @@ -187,18 +192,19 @@ HWTEST_F_L0(BuiltinsWeakSetTest, DeleteAndRemove) ecmaRuntimeCallInfo1->SetThis(weakSet.GetTaggedValue()); ecmaRuntimeCallInfo1->SetCallArg(0, lastKey); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1.get()); - JSTaggedValue result2 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo1.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo1); + JSTaggedValue result2 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo1); + TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result2.GetRawData(), JSTaggedValue::True().GetRawData()); // delete - JSTaggedValue result3 = BuiltinsWeakSet::Delete(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result3 = BuiltinsWeakSet::Delete(ecmaRuntimeCallInfo1); EXPECT_EQ(result3.GetRawData(), JSTaggedValue::True().GetRawData()); // check deleteKey is deleted - JSTaggedValue result4 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo1.get()); + JSTaggedValue result4 = BuiltinsWeakSet::Has(ecmaRuntimeCallInfo1); EXPECT_EQ(result4.GetRawData(), JSTaggedValue::False().GetRawData()); } diff --git a/ecmascript/common.h b/ecmascript/common.h index 8766dfd1055fc590476f70ca90df905aedbf87f1..10e0f5ea2eaca339eb93266fab57bd913b199eb9 100644 --- a/ecmascript/common.h +++ b/ecmascript/common.h @@ -37,7 +37,7 @@ enum TriggerGCType { GC_TYPE_LAST }; -constexpr size_t NUM_MANDATORY_JSFUNC_ARGS = 3; +constexpr int32_t NUM_MANDATORY_JSFUNC_ARGS = 3; using Address = uintptr_t; diff --git a/ecmascript/compiler/BUILD.gn b/ecmascript/compiler/BUILD.gn index b2fc7ce53b80ef984e2f03d72e7a20fe360f13ce..26964c06c3ca111a1f9bf77c08b92070f701397b 100644 --- a/ecmascript/compiler/BUILD.gn +++ b/ecmascript/compiler/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (defined(ark_independent_build)) { +if (defined(ark_standalone_build)) { import("//js_runtime/js_runtime_config.gni") import("$build_root/ark.gni") } else { @@ -41,11 +41,13 @@ config("include_llvm") { source_set("libark_jsoptimizer_set") { sources = [ + "argument_accessor.cpp", "assembler/aarch64/assembler_aarch64.cpp", "assembler/aarch64/extend_assembler.cpp", "assembler/x64/assembler_x64.cpp", "assembler/x64/extended_assembler_x64.cpp", "assembler_module.cpp", + "async_function_lowering.cpp", "bc_call_signature.cpp", "bytecode_circuit_builder.cpp", "call_signature.cpp", @@ -167,9 +169,11 @@ source_set("ark_stub_compiler_set") { ] deps = [ + ":libark_jsoptimizer_set", + ":libark_mock_stub_set", "$ark_root/libpandabase:libarkbase", - "$js_root:libark_jsruntime", - "$js_root/ecmascript/compiler:libark_jsoptimizer", + "$js_root:libark_js_intl_set", + "$js_root:libark_jsruntime_set", ] } @@ -178,6 +182,7 @@ source_set("ark_aot_compiler_set") { "aot_compiler.cpp", "pass_manager.cpp", "slowpath_lowering.cpp", + "type_lowering.cpp", ] public_configs = [ @@ -193,20 +198,40 @@ source_set("ark_aot_compiler_set") { ] } -if (!defined(ark_independent_build)) { - ohos_shared_library("libark_jsoptimizer") { - deps = [ - ":libark_jsoptimizer_set", - "$js_root:libark_jsruntime", - ] +source_set("libark_stub_set") { + deps = [ ":build_stub_to_cpp" ] - install_enable = false + sources = [ "$root_gen_dir/ark/js_runtime/stub_m.cpp" ] - output_extension = "so" - part_name = "ark_js_runtime" - subsystem_name = "ark" - } + public_configs = [ + "$js_root:ark_jsruntime_common_config", + "$js_root:ark_jsruntime_public_config", + ] +} + +source_set("libark_mock_stub_set") { + sources = [ "mock/mock_stub_m.cpp" ] + + public_configs = [ + "$js_root:ark_jsruntime_common_config", + "$js_root:ark_jsruntime_public_config", + ] +} +ohos_shared_library("libark_jsoptimizer") { + deps = [ + ":libark_jsoptimizer_set", + "$js_root:libark_jsruntime", + ] + + install_enable = false + + output_extension = "so" + part_name = "ark_js_runtime" + subsystem_name = "ark" +} + +if (!defined(ark_standalone_build)) { ohos_shared_library("libark_jsoptimizer_test") { deps = [ ":libark_jsoptimizer_set", @@ -236,43 +261,59 @@ if (!defined(ark_independent_build)) { part_name = "ark_js_runtime" subsystem_name = "ark" } + action("gen_stub_file") { script = "$js_root/script/run_ark_executable.py" deps = [ "$js_root/ecmascript/compiler:ark_stub_compiler(${host_toolchain})" ] - stub_file_gen_dir = "$root_out_dir/../.." + stub_file_gen_dir = "$root_gen_dir/ark/js_runtime" + root_out_dir_with_host_toolchain = + get_label_info(":ark_stub_compiler(${host_toolchain})", "root_out_dir") - stub_option = " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.m" + if (current_toolchain == host_toolchain) { + stub_option = " --stub-file=" + rebase_path(stub_file_gen_dir) + "/stub.m" + } else { + stub_option = " --stub-file=" + rebase_path(stub_file_gen_dir) + + "/stub.m" + " --target-triple=aarch64-unknown-linux-gnu" + } args = [ "--script-file", - rebase_path(root_out_dir) + "/ark/ark_js_runtime/ark_stub_compiler", + rebase_path(root_out_dir_with_host_toolchain) + + "/ark/ark_js_runtime/ark_stub_compiler", "--script-options", stub_option, "--expect-output", "0", + "--timeout-limit", + "300", "--env-path", - rebase_path(root_out_dir) + "/ark/ark:" + rebase_path(root_out_dir) + - "/ark/ark_js_runtime:" + rebase_path(root_out_dir) + - "/thirdparty/icu:" + + rebase_path(root_out_dir_with_host_toolchain) + "/ark/ark:" + + rebase_path(root_out_dir_with_host_toolchain) + + "/ark/ark_js_runtime:" + + rebase_path(root_out_dir_with_host_toolchain) + "/thirdparty/icu:" + rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"), ] outputs = [ "$stub_file_gen_dir/stub.m" ] } -} else { - ark_shared_library("libark_jsoptimizer") { - deps = [ - ":libark_jsoptimizer_set", - "$js_root:libark_jsruntime", + + action("build_stub_to_cpp") { + sources = [ "$root_gen_dir/ark/js_runtime/stub.m" ] + + script = "$js_root/script/build_resource_to_cpp.py" + + deps = [ ":gen_stub_file" ] + + args = [ + "--input", + rebase_path("$root_gen_dir/ark/js_runtime/stub.m"), + "--output", + rebase_path("$root_gen_dir/ark/js_runtime/stub_m.cpp"), ] - output_extension = "so" - } -} -config("gen_stub_file_dir_config") { - stub_file_gen_dir = rebase_path("//out") - defines = [ "STUB_FILE_GEN_DIR=\"${stub_file_gen_dir}/\"" ] + outputs = [ "$root_gen_dir/ark/js_runtime/stub_m.cpp" ] + } } diff --git a/ecmascript/compiler/aot_compiler.cpp b/ecmascript/compiler/aot_compiler.cpp index 10a6ba6387c743ab7234dd1467bccca7b6e270a0..157deeed9be12040dac5400c37488d611ca825b7 100644 --- a/ecmascript/compiler/aot_compiler.cpp +++ b/ecmascript/compiler/aot_compiler.cpp @@ -18,7 +18,6 @@ #include // NOLINTNEXTLINE(modernize-deprecated-headers) #include -#include "ecmascript/compiler/bytecode_circuit_builder.h" #include "ecmascript/compiler/file_generators.h" #include "ecmascript/ecma_string.h" #include "ecmascript/ecma_vm.h" @@ -37,18 +36,18 @@ void BlockSignals() #if defined(PANDA_TARGET_UNIX) sigset_t set; if (sigemptyset(&set) == -1) { - COMPILER_LOG(ERROR) << "sigemptyset failed"; + LOG_COMPILER(ERROR) << "sigemptyset failed"; return; } int rc = 0; if (rc < 0) { - COMPILER_LOG(ERROR) << "sigaddset failed"; + LOG_COMPILER(ERROR) << "sigaddset failed"; return; } if (panda::os::native_stack::g_PandaThreadSigmask(SIG_BLOCK, &set, nullptr) != 0) { - COMPILER_LOG(ERROR) << "g_PandaThreadSigmask failed"; + LOG_COMPILER(ERROR) << "g_PandaThreadSigmask failed"; } #endif // PANDA_TARGET_UNIX } @@ -100,39 +99,42 @@ int Main(const int argc, const char **argv) arg_list_t arguments = paParser.GetRemainder(); if (runtimeOptions.IsStartupTime()) { - COMPILER_LOG(DEBUG) << "Startup start time: " << startTime; + LOG_COMPILER(DEBUG) << "Startup start time: " << startTime; } bool ret = true; EcmaVM *vm = JSNApi::CreateEcmaVM(runtimeOptions); if (vm == nullptr) { - COMPILER_LOG(ERROR) << "Cannot Create vm"; + LOG_COMPILER(ERROR) << "Cannot Create vm"; return -1; } - LocalScope scope(vm); - std::string entry = entrypoint.GetValue(); - arg_list_t pandaFileNames = files.GetValue(); - std::string triple = runtimeOptions.GetTargetTriple(); - std::string outputFileName = runtimeOptions.GetAOTOutputFile(); - size_t optLevel = runtimeOptions.GetOptLevel(); - BytecodeStubCSigns::Initialize(); - CommonStubCSigns::Initialize(); - RuntimeStubCSigns::Initialize(); - - std::string logMethods = vm->GetJSOptions().GetlogCompiledMethods(); - AotLog log(logMethods); - AOTFileGenerator generator(&log, vm); - PassManager passManager(vm, entry, triple, optLevel, &log); - for (const auto &fileName : pandaFileNames) { - COMPILER_LOG(INFO) << "AOT start to execute ark file: " << fileName; - if (passManager.Compile(fileName, generator) == false) { - ret = false; - break; + { + LocalScope scope(vm); + std::string entry = entrypoint.GetValue(); + arg_list_t pandaFileNames = files.GetValue(); + std::string triple = runtimeOptions.GetTargetTriple(); + std::string outputFileName = runtimeOptions.GetAOTOutputFile(); + size_t optLevel = runtimeOptions.GetOptLevel(); + BytecodeStubCSigns::Initialize(); + CommonStubCSigns::Initialize(); + RuntimeStubCSigns::Initialize(); + + std::string logMethods = vm->GetJSOptions().GetlogCompiledMethods(); + AotLog log(logMethods); + AOTFileGenerator generator(&log, vm); + PassManager passManager(vm, entry, triple, optLevel, &log); + for (const auto &fileName : pandaFileNames) { + LOG_COMPILER(INFO) << "AOT start to execute ark file: " << fileName; + if (passManager.Compile(fileName, generator) == false) { + ret = false; + break; + } } + generator.SaveAOTFile(outputFileName); + generator.GenerateSnapshotFile(); } - generator.SaveAOTFile(outputFileName); - generator.GenerateSnapshotFile(); + JSNApi::DestroyJSVM(vm); paParser.DisableTail(); return ret ? 0 : -1; @@ -142,6 +144,6 @@ int Main(const int argc, const char **argv) int main(const int argc, const char **argv) { auto result = panda::ecmascript::kungfu::Main(argc, argv); - COMPILER_LOG(INFO) << (result == 0 ? "ts aot compile success" : "ts aot compile failed"); + LOG_COMPILER(INFO) << (result == 0 ? "ts aot compile success" : "ts aot compile failed"); return result; } diff --git a/ecmascript/compiler/argument_accessor.cpp b/ecmascript/compiler/argument_accessor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc35fbc5349e20fdf395fb6f5720bc2aa5ce5785 --- /dev/null +++ b/ecmascript/compiler/argument_accessor.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/compiler/argument_accessor.h" + +namespace panda::ecmascript::kungfu { +void ArgumentAccessor::NewCommonArg(const CommonArgIdx argIndex, MachineType machineType, GateType gateType) +{ + circuit_->NewGate(OpCode(OpCode::ARG), machineType, static_cast(argIndex), { argRoot_ }, gateType); +} + +void ArgumentAccessor::NewArg(const size_t argIndex) +{ + circuit_->NewGate(OpCode(OpCode::ARG), MachineType::I64, argIndex, { argRoot_ }, GateType::TaggedValue()); +} + +// jsmethod must be set +size_t ArgumentAccessor::GetActualNumArgs() const +{ + ASSERT(method_ != nullptr); + auto numArgs = method_->GetNumArgsWithCallField(); + return static_cast(CommonArgIdx::NUM_OF_ARGS) + numArgs; +} + +// jsmethod must be set +GateRef ArgumentAccessor::GetArgGate(const size_t currentVreg) const +{ + ASSERT(method_ != nullptr); + const size_t offsetArgs = method_->GetNumVregs(); + ASSERT(currentVreg >= offsetArgs && currentVreg < offsetArgs + method_->GetNumArgs()); + auto reg = currentVreg - offsetArgs; + auto haveFunc = method_->HaveFuncWithCallField(); + auto haveNewTarget = method_->HaveNewTargetWithCallField(); + auto haveThis = method_->HaveThisWithCallField(); + auto index = GetFunctionArgIndex(reg, haveFunc, haveNewTarget, haveThis); + auto argsArray = GetFunctionArgs(); + return argsArray.at(index); +} + +GateRef ArgumentAccessor::GetCommonArgGate(const CommonArgIdx arg) const +{ + auto argsArray = GetFunctionArgs(); + return argsArray.at(static_cast(arg)); +} + +std::vector ArgumentAccessor::GetFunctionArgs() const +{ + auto argsArray = circuit_->GetOutVector(argRoot_); + std::reverse(argsArray.begin(), argsArray.end()); + return argsArray; +} + +size_t ArgumentAccessor::GetFunctionArgIndex(const size_t currentVreg, const bool haveFunc, + const bool haveNewTarget, const bool haveThis) const +{ + size_t numCommonArgs = haveFunc + haveNewTarget + haveThis; + // 2: number of common args + if (numCommonArgs == 2) { + if (!haveFunc && currentVreg == 0) { + return static_cast(CommonArgIdx::NEW_TARGET); + } + if (!haveFunc && currentVreg == 1) { + return static_cast(CommonArgIdx::THIS); + } + if (!haveNewTarget && currentVreg == 0) { + return static_cast(CommonArgIdx::FUNC); + } + if (!haveNewTarget && currentVreg == 1) { + return static_cast(CommonArgIdx::THIS); + } + if (!haveThis && currentVreg == 0) { + return static_cast(CommonArgIdx::FUNC); + } + if (!haveThis && currentVreg == 1) { + return static_cast(CommonArgIdx::NEW_TARGET); + } + } + // 1: number of common args, 0: the index of currentVreg + if (numCommonArgs == 1 && currentVreg == 0) { + if (haveFunc) { + return static_cast(CommonArgIdx::FUNC); + } + if (haveNewTarget) { + return static_cast(CommonArgIdx::NEW_TARGET); + } + if (haveThis) { + return static_cast(CommonArgIdx::THIS); + } + } + return currentVreg - numCommonArgs + static_cast(CommonArgIdx::NUM_OF_ARGS); +} +} // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/argument_accessor.h b/ecmascript/compiler/argument_accessor.h new file mode 100644 index 0000000000000000000000000000000000000000..e20d18d5c3404c8c9d64a6b7741c8ec77babe4fd --- /dev/null +++ b/ecmascript/compiler/argument_accessor.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_COMPILER_ARGUMENT_ACCESSOR_H +#define ECMASCRIPT_COMPILER_ARGUMENT_ACCESSOR_H + +#include "ecmascript/compiler/circuit.h" +#include "ecmascript/compiler/gate.h" +#include "ecmascript/js_method.h" + +namespace panda::ecmascript::kungfu { +enum class CommonArgIdx : uint8_t { + GLUE = 0, + LEXENV, + ACTUAL_ARGC, + FUNC, + NEW_TARGET, + THIS, + NUM_OF_ARGS, +}; + +class ArgumentAccessor { +public: + explicit ArgumentAccessor(Circuit *circuit, const JSMethod *method = nullptr) + : circuit_(circuit), method_(method), + argRoot_(Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST))) {} + ~ArgumentAccessor() = default; + + void NewCommonArg(const CommonArgIdx argIndex, MachineType machineType, GateType gateType); + void NewArg(const size_t argIndex); + // jsmethod must be set + size_t GetActualNumArgs() const; + // jsmethod must be set + GateRef GetArgGate(const size_t currentVreg) const; + GateRef GetCommonArgGate(const CommonArgIdx arg) const; + +private: + std::vector GetFunctionArgs() const; + size_t GetFunctionArgIndex(const size_t currentVreg, const bool haveFunc, + const bool haveNewTarget, const bool haveThis) const; + + Circuit *circuit_ {nullptr}; + const JSMethod *method_ {nullptr}; + GateRef argRoot_; +}; +} +#endif // ECMASCRIPT_COMPILER_ARGUMENT_ACCESSOR_H diff --git a/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h b/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h index 016f787da0e68b2b7f1e38eb95f4eca4ef12cfe2..750f58ccad4a8eb0889e86ef66ffea5ef97b098c 100644 --- a/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h +++ b/ecmascript/compiler/assembler/aarch64/assembler_aarch64.h @@ -57,6 +57,17 @@ public: { return reg_ != RegisterId::INVALID_REG; } + + inline bool operator !=(const Register &other) + { + return reg_ != other.GetId() || type_ != other.GetType(); + } + + inline bool operator ==(const Register &other) + { + return reg_ == other.GetId() && type_ == other.GetType(); + } + private: RegisterId reg_; RegisterType type_; diff --git a/ecmascript/compiler/assembler/aarch64/assembler_aarch64_constants.h b/ecmascript/compiler/assembler/aarch64/assembler_aarch64_constants.h index 37ed6565b28f391f34bd4f9c16a46fa812fbdbbe..039c05fb700f55810c29c7a3c96d750b0cd87fe9 100644 --- a/ecmascript/compiler/assembler/aarch64/assembler_aarch64_constants.h +++ b/ecmascript/compiler/assembler/aarch64/assembler_aarch64_constants.h @@ -44,14 +44,14 @@ enum VectorRegisterId : uint8_t { enum Extend : uint8_t { NO_EXTEND = 0xFF, - UXTB = 0, - UXTH = 1, - UXTW = 2, - UXTX = 3, - SXTB = 4, - SXTH = 5, - SXTW = 6, - SXTX = 7, + UXTB = 0, /* zero extend to byte */ + UXTH = 1, /* zero extend to half word */ + UXTW = 2, /* zero extend to word */ + UXTX = 3, /* zero extend to 64bit */ + SXTB = 4, /* sign extend to byte */ + SXTH = 5, /* sign extend to half word */ + SXTW = 6, /* sign extend to word */ + SXTX = 7, /* sign extend to 64bit */ }; enum Shift : uint8_t { diff --git a/ecmascript/compiler/assembler/aarch64/extend_assembler.cpp b/ecmascript/compiler/assembler/aarch64/extend_assembler.cpp index 7c8bdcedafbf257b6a775a2e7dc5cda2a04c332f..f44f8eefd2faae1a42911e8dbdf54e5e19d25377 100644 --- a/ecmascript/compiler/assembler/aarch64/extend_assembler.cpp +++ b/ecmascript/compiler/assembler/aarch64/extend_assembler.cpp @@ -84,6 +84,12 @@ void ExtendedAssembler::RestoreFpAndLr() Ldp(Register(X29), Register(X30), MemoryOperand(sp, 16, POSTINDEX)); } +void ExtendedAssembler::PushLrAndFp() +{ + Register sp(SP); + Stp(Register(X30), Register(X29), MemoryOperand(sp, -16, PREINDEX)); // 16: 2 registers +} + void ExtendedAssembler::SaveLrAndFp() { Register sp(SP); @@ -97,10 +103,10 @@ void ExtendedAssembler::RestoreLrAndFp() Ldp(Register(X30), Register(X29), MemoryOperand(sp, 16, POSTINDEX)); // 16: 2 registers } -void ExtendedAssembler::PushArgsWithArgv(Register argc, Register argv, Register op, panda::ecmascript::Label *next) +void ExtendedAssembler::PushArgsWithArgv(Register argc, Register argv, Register op, + Register fp, panda::ecmascript::Label *next) { Label loopBeginning; - Register sp(SP); if (next != nullptr) { Cmp(argc.W(), Immediate(0)); B(Condition::LS, next); @@ -108,20 +114,30 @@ void ExtendedAssembler::PushArgsWithArgv(Register argc, Register argv, Register Add(argv, argv, Operand(argc.W(), UXTW, 3)); // 3: argc * 8 Bind(&loopBeginning); Ldr(op, MemoryOperand(argv, -8, PREINDEX)); // -8: 8 bytes - Str(op, MemoryOperand(sp, -8, PREINDEX)); // -8: 8 bytes + Str(op, MemoryOperand(fp, -8, PREINDEX)); // -8: 8 bytes Sub(argc.W(), argc.W(), Immediate(1)); Cbnz(argc.W(), &loopBeginning); } -void ExtendedAssembler::PushArgc(int32_t argc, Register op) +void ExtendedAssembler::PushArgc(int32_t argc, Register op, Register fp) { Mov(op, Immediate(JSTaggedValue(argc).GetRawData())); - Str(op, MemoryOperand(Register(SP), -8, PREINDEX)); // -8: 8 bytes + Str(op, MemoryOperand(fp, -8, PREINDEX)); // -8: 8 bytes } -void ExtendedAssembler::PushArgc(Register argc, Register op) +void ExtendedAssembler::PushArgc(Register argc, Register op, Register fp) { Orr(op, argc, LogicalImmediate::Create(JSTaggedValue::TAG_INT, RegXSize)); - Str(op, MemoryOperand(Register(SP), -8, PREINDEX)); // -8: 8 bytes + Str(op, MemoryOperand(fp, -8, PREINDEX)); // -8: 8 bytes +} + +void ExtendedAssembler::Align16(Register fp) +{ + Label aligned; + Tst(fp, LogicalImmediate::Create(0xf, RegXSize)); // 0xf: 0x1111 + B(Condition::EQ, &aligned); + // 8: frame slot size + Sub(fp, fp, Immediate(8)); + Bind(&aligned); } } // namespace panda::ecmascript::aarch64 \ No newline at end of file diff --git a/ecmascript/compiler/assembler/aarch64/extend_assembler.h b/ecmascript/compiler/assembler/aarch64/extend_assembler.h index 39cd8c821e06108918f8ee563432709766dd4597..4bf1df6624fa189f49840b87600105b7c981b170 100644 --- a/ecmascript/compiler/assembler/aarch64/extend_assembler.h +++ b/ecmascript/compiler/assembler/aarch64/extend_assembler.h @@ -35,16 +35,19 @@ public: void PushFpAndLr(); void SaveFpAndLr(); void RestoreFpAndLr(); + void PushLrAndFp(); void SaveLrAndFp(); void RestoreLrAndFp(); - void PushArgsWithArgv(Register argc, Register argv, Register op, panda::ecmascript::Label *next); - void PushArgc(int32_t argc, Register op); - void PushArgc(Register argc, Register op); + void PushArgsWithArgv(Register argc, Register argv, Register op, + Register fp, panda::ecmascript::Label *next); + void PushArgc(int32_t argc, Register op, Register fp); + void PushArgc(Register argc, Register op, Register fp); + void Align16(Register fp); Register TempRegister1() { if (temp1InUse_) { - COMPILER_LOG(ERROR) << "temp register1 inuse."; + LOG_COMPILER(ERROR) << "temp register1 inuse."; UNREACHABLE(); } temp1InUse_ = true; @@ -53,7 +56,7 @@ public: Register TempRegister2() { if (temp2InUse_) { - COMPILER_LOG(ERROR) << "temp register2 inuse."; + LOG_COMPILER(ERROR) << "temp register2 inuse."; UNREACHABLE(); } temp2InUse_ = true; diff --git a/ecmascript/compiler/assembler/x64/extended_assembler_x64.h b/ecmascript/compiler/assembler/x64/extended_assembler_x64.h index 53cc3c12afbde31112c5b4f932271fac8aaa9335..5dc16e693c43fe444852f8136d1746a8d2bd040c 100644 --- a/ecmascript/compiler/assembler/x64/extended_assembler_x64.h +++ b/ecmascript/compiler/assembler/x64/extended_assembler_x64.h @@ -42,7 +42,7 @@ public: Register TempRegister() { if (tempInUse_) { - COMPILER_LOG(ERROR) << "temp register inuse."; + LOG_COMPILER(ERROR) << "temp register inuse."; UNREACHABLE(); } tempInUse_ = true; diff --git a/ecmascript/compiler/assembler_module.cpp b/ecmascript/compiler/assembler_module.cpp index 5b356a46352d2675c7a286a827f4ada8b00b33c5..15b98e3600302e57f5c0c10e4b197e26c0acbdcf 100644 --- a/ecmascript/compiler/assembler_module.cpp +++ b/ecmascript/compiler/assembler_module.cpp @@ -39,11 +39,11 @@ void AssemblerModule::Run(const CompilationConfig *cfg, Chunk* chunk) void AssemblerModule::GenerateStubsX64(Chunk* chunk) { x64::ExtendedAssembler assembler(chunk, this); - COMPILER_LOG(INFO) << "compiling asm stubs"; + LOG_COMPILER(INFO) << "compiling asm stubs"; for (size_t i = 0; i < asmCallSigns_.size(); i++) { auto cs = asmCallSigns_[i]; ASSERT(cs->HasConstructor()); - COMPILER_LOG(INFO) << "Stub Name: " << cs->GetName(); + LOG_COMPILER(INFO) << "Stub Name: " << cs->GetName(); AssemblerStub *stub = static_cast( cs->GetConstructor()(nullptr)); stub->GenerateX64(&assembler); @@ -56,11 +56,11 @@ void AssemblerModule::GenerateStubsX64(Chunk* chunk) void AssemblerModule::GenerateStubsAarch64(Chunk* chunk) { aarch64::ExtendedAssembler assembler(chunk, this); - COMPILER_LOG(INFO) << "compiling asm stubs"; + LOG_COMPILER(INFO) << "compiling asm stubs"; for (size_t i = 0; i < asmCallSigns_.size(); i++) { auto cs = asmCallSigns_[i]; ASSERT(cs->HasConstructor()); - COMPILER_LOG(INFO) << "Stub Name: " << cs->GetName(); + LOG_COMPILER(INFO) << "Stub Name: " << cs->GetName(); AssemblerStub *stub = static_cast( cs->GetConstructor()(nullptr)); stub->GenerateAarch64(&assembler); diff --git a/ecmascript/compiler/async_function_lowering.cpp b/ecmascript/compiler/async_function_lowering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ef14ee9a044833b21dfb292ce65df650be1c2d72 --- /dev/null +++ b/ecmascript/compiler/async_function_lowering.cpp @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/compiler/async_function_lowering.h" + +namespace panda::ecmascript::kungfu { +void AsyncFunctionLowering::ProcessAll() +{ + ProcessJumpTable(); +} + +void AsyncFunctionLowering::ProcessJumpTable() +{ + GateRef newTarget = argAccessor_.GetCommonArgGate(CommonArgIdx::NEW_TARGET); + GateRef isEqual = builder_.Equal(newTarget, builder_.Undefined()); + GateRef stateEntryState = *accessor_.ConstUses(stateEntry_).begin(); + GateRef ifBranchCondition = builder_.Branch(stateEntry_, isEqual); + GateRef ifTrueCondition = builder_.IfTrue(ifBranchCondition); + GateRef ifFalseCondition = builder_.IfFalse(ifBranchCondition); + accessor_.ReplaceStateIn(stateEntryState, ifTrueCondition); + + GateRef contextOffset = builder_.IntPtr(JSGeneratorObject::GENERATOR_CONTEXT_OFFSET); + GateRef val = builder_.PtrAdd(newTarget, contextOffset); + GateRef contextGate = circuit_->NewGate(OpCode(OpCode::LOAD), MachineType::I64, 0, {dependEntry_, val}, + GateType::TaggedPointer()); + GateRef bcOffset = builder_.IntPtr(GeneratorContext::GENERATOR_BC_OFFSET_OFFSET); + val = builder_.PtrAdd(contextGate, bcOffset); + GateRef restoreOffsetGate = circuit_->NewGate(OpCode(OpCode::LOAD), MachineType::I32, 0, {contextGate, val}, + GateType::NJSValue()); + GateRef firstState = Circuit::NullGate(); + const auto &suspendAndResumeGates = bcBuilder_->GetAsyncRelatedGates(); + for (const auto &gate : suspendAndResumeGates) { + auto curInfo = bcBuilder_->GetByteCodeInfo(gate); + if (curInfo.IsBc(EcmaOpcode::RESUMEGENERATOR_PREF_V8)) { + RebuildGeneratorCfg(gate, restoreOffsetGate, ifFalseCondition, newTarget, firstState); + } + } +} + +void AsyncFunctionLowering::RebuildGeneratorCfg(GateRef resumeGate, GateRef restoreOffsetGate, GateRef ifFalseCondition, + GateRef newTarget, GateRef &firstState) +{ + GateRef ifSuccess = accessor_.GetState(resumeGate); + GateRef suspendGate = accessor_.GetState(ifSuccess); + GateRef firstRestoreRegGate = GetFirstRestoreRegister(resumeGate); + GateRef offsetConstantGate = accessor_.GetValueIn(suspendGate); + offsetConstantGate = builder_.TruncInt64ToInt32(offsetConstantGate); + auto stateInGate = accessor_.GetState(resumeGate); + bool flag = true; + GateRef prevLoopBeginGate = Circuit::NullGate(); + GateRef loopBeginStateIn = Circuit::NullGate(); + GateRef prevBcOffsetPhiGate = Circuit::NullGate(); + while (true) { + auto opcode = accessor_.GetOpCode(stateInGate); + if (opcode == OpCode::STATE_ENTRY) { + GateRef condition = circuit_->NewGate(OpCode(OpCode::EQ), 0, {offsetConstantGate, restoreOffsetGate}, + GateType::NJSValue()); + GateRef ifBranch = circuit_->NewGate(OpCode(OpCode::IF_BRANCH), 0, { ifFalseCondition, condition }, + GateType::Empty()); + GateRef ifTrue = circuit_->NewGate(OpCode(OpCode::IF_TRUE), 0, {ifBranch}, GateType::Empty()); + GateRef ifFalse = circuit_->NewGate(OpCode(OpCode::IF_FALSE), 0, {ifBranch}, GateType::Empty()); + if (flag) { + accessor_.ReplaceStateIn(resumeGate, ifTrue); + accessor_.ReplaceValueIn(resumeGate, newTarget); + accessor_.ReplaceDependIn(firstRestoreRegGate, restoreOffsetGate); + circuit_->NewGate(OpCode(OpCode::RETURN), 0, + {ifSuccess, suspendGate, suspendGate, + Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST))}, + GateType::AnyType()); + } else { + loopBeginStateIn = ifTrue; + } + accessor_.ReplaceStateIn(ifBranch, ifFalseCondition); + if (firstState != Circuit::NullGate()) { + accessor_.ReplaceStateIn(firstState, ifFalse); + } else { + auto constant = builder_.UndefineConstant(); + circuit_->NewGate(OpCode(OpCode::RETURN), 0, + {ifFalse, restoreOffsetGate, constant, + Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST))}, + GateType::AnyType()); + } + firstState = ifBranch; + } + + if (opcode == OpCode::LOOP_BEGIN) { + // This constant gate must be created by the NewGate method to distinguish whether the while + // loop needs to modify the phi node or not. + GateRef emptyOffsetGate = circuit_->NewGate(OpCode(OpCode::CONSTANT), MachineType::I32, + static_cast(-1), + {Circuit::GetCircuitRoot(OpCode(OpCode::CIRCUIT_ROOT))}, + GateType::NJSValue()); + GateRef bcOffsetPhiGate = circuit_->NewGate(OpCode(OpCode::VALUE_SELECTOR), MachineType::I32, 2, + {stateInGate, restoreOffsetGate, emptyOffsetGate}, + GateType::NJSValue()); + + GateRef condition = circuit_->NewGate(OpCode(OpCode::EQ), 0, {offsetConstantGate, bcOffsetPhiGate}, + GateType::NJSValue()); + GateRef ifBranch = circuit_->NewGate(OpCode(OpCode::IF_BRANCH), 0, {stateInGate, condition}, + GateType::Empty()); + GateRef ifTrue = circuit_->NewGate(OpCode(OpCode::IF_TRUE), 0, {ifBranch}, GateType::Empty()); + GateRef ifFalse = circuit_->NewGate(OpCode(OpCode::IF_FALSE), 0, {ifBranch}, GateType::Empty()); + + GateRef resumeStateGate = accessor_.GetState(resumeGate); + if (accessor_.GetOpCode(resumeStateGate) != OpCode::IF_TRUE) { + accessor_.ReplaceStateIn(resumeGate, ifTrue); + accessor_.ReplaceValueIn(resumeGate, newTarget); + accessor_.ReplaceDependIn(firstRestoreRegGate, bcOffsetPhiGate); + circuit_->NewGate(OpCode(OpCode::RETURN), 0, + {ifSuccess, suspendGate, suspendGate, + Circuit::GetCircuitRoot(OpCode(OpCode::RETURN_LIST))}, + GateType::AnyType()); + } else { + // Handling multi-layer for loops + UpdateValueSelector(prevLoopBeginGate, ifTrue, prevBcOffsetPhiGate); + accessor_.ReplaceValueIn(prevBcOffsetPhiGate, bcOffsetPhiGate); + } + accessor_.ReplaceStateIn(ifBranch, stateInGate); + + // Find the node with LOOP_BEGIN as State input and modify its + // state input to the newly created IF_FALSE node. + auto uses = accessor_.Uses(stateInGate); + for (auto useIt = uses.begin(); useIt != uses.end(); useIt++) { + if (accessor_.GetOpCode(*useIt).IsState() && *useIt != ifBranch) { + accessor_.ReplaceIn(useIt, ifFalse); + } + } + + prevLoopBeginGate = stateInGate; + prevBcOffsetPhiGate = bcOffsetPhiGate; + stateInGate = accessor_.GetState(stateInGate); + flag = false; + continue; + } + if (loopBeginStateIn != Circuit::NullGate()) { + UpdateValueSelector(prevLoopBeginGate, loopBeginStateIn, prevBcOffsetPhiGate); + break; + } + if (accessor_.GetOpCode(stateInGate) == OpCode::STATE_ENTRY) { + break; + } + stateInGate = accessor_.GetState(stateInGate); + } +} + +void AsyncFunctionLowering::UpdateValueSelector(GateRef prevLoopBeginGate, + GateRef controlStateGate, + GateRef prevBcOffsetPhiGate) +{ + GateRef loopBeginFirstState = accessor_.GetState(prevLoopBeginGate); + GateRef newGate = circuit_->NewGate(OpCode(OpCode::MERGE), 2, + {controlStateGate, loopBeginFirstState}, GateType::Empty()); + accessor_.ReplaceStateIn(prevLoopBeginGate, newGate); + auto loopBeginUses = accessor_.Uses(prevLoopBeginGate); + for (auto use : loopBeginUses) { + if (accessor_.GetOpCode(use) == OpCode::VALUE_SELECTOR && use != prevBcOffsetPhiGate) { + auto machineType = accessor_.GetMachineType(use); + auto gateType = accessor_.GetGateType(use); + auto undefinedGate = + accessor_.GetConstantGate(machineType, JSTaggedValue::VALUE_UNDEFINED, gateType); + auto firstValueGate = accessor_.GetValueIn(use, 0); + auto newValueSelector = circuit_->NewGate(OpCode(OpCode::VALUE_SELECTOR), machineType, + 2, {newGate, undefinedGate, firstValueGate}, + gateType); + accessor_.ReplaceValueIn(use, newValueSelector); + } + } +} + +bool AsyncFunctionLowering::IsAsyncRelated() const +{ + return bcBuilder_->GetAsyncRelatedGates().size() > 0; +} + +GateRef AsyncFunctionLowering::GetFirstRestoreRegister(GateRef gate) const +{ + GateRef firstRestoreGate = 0; + GateRef curRestoreGate = accessor_.GetDep(gate); + while (accessor_.GetOpCode(curRestoreGate) == OpCode::RESTORE_REGISTER) { + firstRestoreGate = curRestoreGate; + curRestoreGate = accessor_.GetDep(curRestoreGate); + } + return firstRestoreGate; +} +} // panda::ecmascript::kungfu + diff --git a/ecmascript/compiler/async_function_lowering.h b/ecmascript/compiler/async_function_lowering.h new file mode 100644 index 0000000000000000000000000000000000000000..124bce0c3978d3c5ae817ceefe63b5991c622d01 --- /dev/null +++ b/ecmascript/compiler/async_function_lowering.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_ +#define ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_ + +#include "ecmascript/compiler/bytecode_circuit_builder.h" +#include "ecmascript/compiler/circuit.h" +#include "ecmascript/compiler/circuit_builder-inl.h" +#include "ecmascript/compiler/circuit_builder.h" + +namespace panda::ecmascript::kungfu { +class AsyncFunctionLowering { +public: + AsyncFunctionLowering(BytecodeCircuitBuilder *bcBuilder, Circuit *circuit, CompilationConfig *cmpCfg, + bool enableLog) + : bcBuilder_(bcBuilder), circuit_(circuit), builder_(circuit, cmpCfg), enableLog_(enableLog), + stateEntry_(Circuit::GetCircuitRoot(OpCode(OpCode::STATE_ENTRY))), + dependEntry_(Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY))), + accessor_(circuit), argAccessor_(circuit) + { + } + ~AsyncFunctionLowering() = default; + + void ProcessAll(); + + bool IsAsyncRelated() const; + +private: + void ProcessJumpTable(); + + void RebuildGeneratorCfg(GateRef resumeGate, GateRef restoreOffsetGate, GateRef ifFalseCondition, GateRef newTarget, + GateRef &firstState); + + void UpdateValueSelector(GateRef prevLoopBeginGate, GateRef controlStateGate, GateRef prevBcOffsetPhiGate); + + GateRef GetFirstRestoreRegister(GateRef gate) const; + + BytecodeCircuitBuilder *bcBuilder_; + Circuit *circuit_; + CircuitBuilder builder_; + [[maybe_unused]] bool enableLog_ {false}; + GateRef stateEntry_ {Circuit::NullGate()}; + GateRef dependEntry_ {Circuit::NullGate()}; + GateAccessor accessor_; + ArgumentAccessor argAccessor_; +}; +} // panda::ecmascript::kungfu + +#endif // ECMASCRIPT_COMPILER_ASYNC_FUNCTION_LOWRING_H_ diff --git a/ecmascript/compiler/bc_call_signature.h b/ecmascript/compiler/bc_call_signature.h index 4a4245e64573035dd641701b54d64dc26d18196d..69baeba14e4c058b4c423dd32d66546517651a41 100644 --- a/ecmascript/compiler/bc_call_signature.h +++ b/ecmascript/compiler/bc_call_signature.h @@ -181,7 +181,7 @@ namespace panda::ecmascript::kungfu { V(HandleOverflow) \ V(BCDebuggerEntry) \ V(BCDebuggerExceptionEntry) \ - V(NewObjectDynRangeReturn) \ + V(NewObjectDynRangeThrowException) \ V(InterpreterGetPropertyByName) \ #define INTERPRETER_IGNORED_BC_STUB_LIST(V) \ diff --git a/ecmascript/compiler/bytecode_circuit_builder.cpp b/ecmascript/compiler/bytecode_circuit_builder.cpp index 1401bae123a9ab10deaacd2e681dbbb64ccce1bc..a0eeb2106b76915f57cfbef33ffc29f747fbbca2 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.cpp +++ b/ecmascript/compiler/bytecode_circuit_builder.cpp @@ -13,10 +13,11 @@ * limitations under the License. */ -#include "bytecode_circuit_builder.h" +#include "ecmascript/compiler/bytecode_circuit_builder.h" + #include "ecmascript/base/number_helper.h" -#include "ecmascript/ts_types/ts_loader.h" #include "ecmascript/compiler/gate_accessor.h" +#include "ecmascript/ts_types/ts_loader.h" namespace panda::ecmascript::kungfu { void BytecodeCircuitBuilder::BytecodeToCircuit() @@ -128,7 +129,7 @@ void BytecodeCircuitBuilder::CollectBytecodeBlockInfo(uint8_t *pc, std::vector temp; temp.emplace_back(pc + BytecodeOffset::THREE); // first successor - int8_t offset = static_cast(READ_INST_16_0()); + int16_t offset = static_cast(READ_INST_16_0()); temp.emplace_back(pc + offset); // second successor bytecodeBlockInfos.emplace_back(pc, SplitKind::END, temp); bytecodeBlockInfos.emplace_back(pc + BytecodeOffset::THREE, SplitKind::START, @@ -401,7 +402,7 @@ void BytecodeCircuitBuilder::ComputeDominatorTree() if (IsLogEnabled()) { // print cfg order for (auto iter : bbIdToDfsTimestamp) { - COMPILER_LOG(INFO) << "BB_" << iter.first << " dfs timestamp is : " << iter.second; + LOG_COMPILER(INFO) << "BB_" << iter.first << " dfs timestamp is : " << iter.second; } } @@ -451,7 +452,7 @@ void BytecodeCircuitBuilder::ComputeDominatorTree() for (auto j: doms[i]) { log += std::to_string(j) + " , "; } - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; } } @@ -476,7 +477,7 @@ void BytecodeCircuitBuilder::ComputeDominatorTree() if (IsLogEnabled()) { // print immediate dominator for (size_t i = 0; i < immDom.size(); i++) { - COMPILER_LOG(INFO) << i << " immediate dominator: " << immDom[i]; + LOG_COMPILER(INFO) << i << " immediate dominator: " << immDom[i]; } PrintGraph(); } @@ -501,7 +502,7 @@ void BytecodeCircuitBuilder::BuildImmediateDominator(const std::vector & if (block.isDead) { continue; } - COMPILER_LOG(INFO) << "current block " << block.id + LOG_COMPILER(INFO) << "current block " << block.id << " immediate dominator block id: " << block.iDominator->id; } } @@ -524,7 +525,7 @@ void BytecodeCircuitBuilder::BuildImmediateDominator(const std::vector & for (size_t i = 0; i < block.immDomBlocks.size(); i++) { log += std::to_string(block.immDomBlocks[i]->id) + ","; } - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; } } @@ -565,7 +566,7 @@ void BytecodeCircuitBuilder::ComputeDomFrontiers(const std::vector &immD for (auto iter = domFrontiers[i].cbegin(); iter != domFrontiers[i].cend(); iter++) { log += std::to_string((*iter)->id) + ", "; } - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; } } } @@ -1254,8 +1255,11 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc) case EcmaOpcode::SUSPENDGENERATOR_PREF_V8_V8: { uint16_t v0 = READ_INST_8_1(); uint16_t v1 = READ_INST_8_2(); + info.accIn = true; info.accOut = true; info.offset = BytecodeOffset::FOUR; + uint32_t offset = pc - method_->GetBytecodeArray(); + info.inputs.emplace_back(Immediate(offset)); // Save the pc offset when suspend info.inputs.emplace_back(VirtualRegister(v0)); info.inputs.emplace_back(VirtualRegister(v1)); break; @@ -1464,6 +1468,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc) } case EcmaOpcode::COPYRESTARGS_PREF_IMM16: { uint16_t restIdx = READ_INST_16_1(); + info.accOut = true; info.offset = BytecodeOffset::FOUR; info.inputs.emplace_back(Immediate(restIdx)); break; @@ -1746,7 +1751,7 @@ BytecodeInfo BytecodeCircuitBuilder::GetBytecodeInfo(const uint8_t *pc) break; } default: { - COMPILER_LOG(ERROR) << "Error bytecode: " << opcode << ", pls check bytecode offset."; + LOG_COMPILER(ERROR) << "Error bytecode: " << opcode << ", pls check bytecode offset."; UNREACHABLE(); break; } @@ -1764,6 +1769,12 @@ void BytecodeCircuitBuilder::InsertPhi() auto pc = bb.start; while (pc <= bb.end) { auto bytecodeInfo = GetBytecodeInfo(pc); + if (bytecodeInfo.IsBc(EcmaOpcode::RESUMEGENERATOR_PREF_V8)) { + auto numVRegs = method_->GetNumVregs(); + for (size_t i = 0; i < numVRegs; i++) { + bytecodeInfo.vregOut.emplace_back(i); + } + } pc = pc + bytecodeInfo.offset; // next inst start pc for (const auto &vreg: bytecodeInfo.vregOut) { defsitesInfo[vreg].insert(bb.id); @@ -1777,7 +1788,7 @@ void BytecodeCircuitBuilder::InsertPhi() for (auto id : defsites) { log += std::to_string(id) + " , "; } - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; } } @@ -1839,31 +1850,14 @@ void BytecodeCircuitBuilder::UpdateCFG() // build circuit void BytecodeCircuitBuilder::BuildCircuitArgs() { - const size_t numArgs = method_->GetNumArgs(); - const size_t actualNumArgs = GetActualNumArgs(numArgs); - actualArgs_.resize(actualNumArgs); - - auto glueGate = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I64, 0, - {Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST))}, - GateType::NJSValue()); - actualArgs_.at(0) = glueGate; - commonArgs_.at(0) = glueGate; - auto argRoot = Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST)); - auto actualArgc = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I32, CommonArgIdx::ACTUAL_ARGC, - {argRoot}, GateType::NJSValue()); - actualArgs_.at(CommonArgIdx::ACTUAL_ARGC) = actualArgc; - commonArgs_.at(CommonArgIdx::ACTUAL_ARGC) = actualArgc; - for (size_t argIdx = CommonArgIdx::FUNC; argIdx < CommonArgIdx::NUM_OF_ARGS; argIdx++) { - auto argGate = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I64, argIdx, {argRoot}, - GateType::TaggedValue()); - actualArgs_.at(argIdx) = argGate; - commonArgs_.at(argIdx) = argGate; - } - - for (size_t argIdx = CommonArgIdx::NUM_OF_ARGS; argIdx < actualNumArgs; argIdx++) { - actualArgs_.at(argIdx) = circuit_.NewGate(OpCode(OpCode::ARG), MachineType::I64, argIdx, - {Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST))}, - GateType::TaggedValue()); + argAcc_.NewCommonArg(CommonArgIdx::GLUE, MachineType::I64, GateType::NJSValue()); + argAcc_.NewCommonArg(CommonArgIdx::LEXENV, MachineType::I64, GateType::TaggedValue()); + argAcc_.NewCommonArg(CommonArgIdx::ACTUAL_ARGC, MachineType::I32, GateType::NJSValue()); + auto funcIdx = static_cast(CommonArgIdx::FUNC); + const size_t actualNumArgs = argAcc_.GetActualNumArgs(); + // new actual argument gates + for (size_t argIdx = funcIdx; argIdx < actualNumArgs; argIdx++) { + argAcc_.NewArg(argIdx); } } @@ -2079,7 +2073,7 @@ GateRef BytecodeCircuitBuilder::NewConst(const BytecodeInfo &info) GateType::TaggedValue()); break; case EcmaOpcode::LDFUNCTION_PREF: - gate = GetCommonArgByIndex(CommonArgIdx::FUNC); + gate = argAcc_.GetCommonArgGate(CommonArgIdx::FUNC); break; default: UNREACHABLE(); @@ -2124,6 +2118,9 @@ void BytecodeCircuitBuilder::NewJSGate(BytecodeRegion &bb, const uint8_t *pc, Ga GateType::AnyType()); } jsgateToBytecode_[gate] = {bb.id, pc}; + if (bytecodeInfo.IsGeneratorRelative()) { + suspendAndResumeGates_.emplace_back(gate); + } if (bytecodeInfo.IsThrow()) { auto constant = circuit_.NewGate(OpCode(OpCode::CONSTANT), MachineType::I64, JSTaggedValue::VALUE_HOLE, @@ -2336,7 +2333,6 @@ GateRef BytecodeCircuitBuilder::RenameVariable(const size_t bbId, const uint8_t *end, const uint16_t reg, const bool acc, const GateType gateType) { ASSERT(end != nullptr); - const size_t offsetArgs = method_->GetNumVregs(); auto tmpReg = reg; auto tsType = GetRealGateType(tmpReg, gateType); // find def-site in bytecodes of basic block @@ -2353,8 +2349,8 @@ GateRef BytecodeCircuitBuilder::RenameVariable(const size_t bbId, } std::reverse(instList.begin(), instList.end()); auto tmpAcc = acc; - for (auto pcIter: instList) { // upper bound - auto curInfo = GetBytecodeInfo(pcIter); + for (auto pcIter = instList.begin(); pcIter != instList.end(); pcIter++) { // upper bound + auto curInfo = GetBytecodeInfo(*pcIter); // original bc use acc as input && current bc use acc as output bool isTransByAcc = tmpAcc && curInfo.accOut; // 0 : the index in vreg-out list @@ -2369,10 +2365,31 @@ GateRef BytecodeCircuitBuilder::RenameVariable(const size_t bbId, tsType = GetRealGateType(tmpReg, tsType); } } else { - ans = byteCodeToJSGate_.at(pcIter); + ans = byteCodeToJSGate_.at(*pcIter); break; } } + if (static_cast(curInfo.opcode) != EcmaOpcode::RESUMEGENERATOR_PREF_V8) { + continue; + } + // New RESTORE_REGISTER HIR, used to restore the register content when processing resume instruction. + // New SAVE_REGISTER HIR, used to save register content when processing suspend instruction. + GateAccessor accessor(&circuit_); + auto resumeGate = byteCodeToJSGate_.at(*pcIter); + GateRef resumeDependGate = accessor.GetDep(resumeGate); + ans = circuit_.NewGate(OpCode(OpCode::RESTORE_REGISTER), MachineType::I64, tmpReg, + {resumeDependGate}, GateType::NJSValue()); + accessor.SetDep(resumeGate, ans); + auto saveRegGate = RenameVariable(bbId, *pcIter - 1, tmpReg, tmpAcc, tsType); + auto nextPcIter = pcIter; + nextPcIter++; + ASSERT(GetBytecodeInfo(*nextPcIter).opcode == EcmaOpcode::SUSPENDGENERATOR_PREF_V8_V8); + GateRef suspendGate = byteCodeToJSGate_.at(*nextPcIter); + auto dependGate = accessor.GetDep(suspendGate); + auto newDependGate = circuit_.NewGate(OpCode(OpCode::SAVE_REGISTER), tmpReg, {dependGate, saveRegGate}, + GateType::Empty()); + accessor.SetDep(suspendGate, newDependGate); + break; } // find GET_EXCEPTION gate if this is a catch block if (ans == Circuit::NullGate() && tmpAcc) { @@ -2398,12 +2415,11 @@ GateRef BytecodeCircuitBuilder::RenameVariable(const size_t bbId, } ans = bb.valueSelectorAccGate; } - if (ans == Circuit::NullGate() && bbId == 0) { // entry block + if (ans == Circuit::NullGate() && IsEntryBlock(bbId)) { // entry block // find def-site in function args - ASSERT(!tmpAcc && tmpReg >= offsetArgs && tmpReg < offsetArgs + actualArgs_.size()); - auto index = GetFunctionArgIndex(tmpReg, offsetArgs); - ans = actualArgs_.at(index); - circuit_.LoadGatePtr(ans)->SetGateType(static_cast(tsType)); + ASSERT(!tmpAcc); + ans = argAcc_.GetArgGate(tmpReg); + circuit_.SetGateType(ans, tsType); return ans; } if (ans == Circuit::NullGate()) { @@ -2411,7 +2427,7 @@ GateRef BytecodeCircuitBuilder::RenameVariable(const size_t bbId, return RenameVariable(bb.iDominator->id, bb.iDominator->end, tmpReg, tmpAcc, tsType); } else { // def-site already found - circuit_.LoadGatePtr(ans)->SetGateType(static_cast(tsType)); + circuit_.SetGateType(ans, tsType); return ans; } } @@ -2447,9 +2463,10 @@ void BytecodeCircuitBuilder::BuildCircuit() for (const auto &[key, value]: jsgateToBytecode_) { byteCodeToJSGate_[value.second] = key; } + GateAccessor accessor = GateAccessor(&circuit_); // resolve def-site of virtual regs and set all value inputs for (auto gate: circuit_.GetAllGates()) { - auto valueCount = circuit_.GetOpCode(gate).GetInValueCount(circuit_.GetBitField(gate)); + auto valueCount = accessor.GetInValueCount(gate); auto it = jsgateToBytecode_.find(gate); if (it == jsgateToBytecode_.cend()) { continue; @@ -2463,8 +2480,8 @@ void BytecodeCircuitBuilder::BuildCircuit() [[maybe_unused]] size_t numValueOutputs = bytecodeInfo.ComputeOutCount() + bytecodeInfo.vregOut.size(); ASSERT(numValueInputs == valueCount); ASSERT(numValueOutputs <= 1); - auto stateCount = circuit_.GetOpCode(gate).GetStateCount(circuit_.GetBitField(gate)); - auto dependCount = circuit_.GetOpCode(gate).GetDependCount(circuit_.GetBitField(gate)); + auto stateCount = accessor.GetStateCount(gate); + auto dependCount = accessor.GetDependCount(gate); for (size_t valueIdx = 0; valueIdx < valueCount; valueIdx++) { auto inIdx = valueIdx + stateCount + dependCount; if (!circuit_.IsInGateNull(gate, inIdx)) { @@ -2486,11 +2503,6 @@ void BytecodeCircuitBuilder::BuildCircuit() } } -size_t BytecodeCircuitBuilder::GetFunctionArgIndex(size_t currentVreg, size_t numVregs) const -{ - return (currentVreg - numVregs + CommonArgIdx::NUM_OF_ARGS); -} - void BytecodeCircuitBuilder::AddBytecodeOffsetInfo(GateRef &gate, const BytecodeInfo &info, size_t bcOffsetIndex, uint8_t *pc) { @@ -2513,17 +2525,17 @@ void BytecodeCircuitBuilder::PrintCollectBlockInfo(std::vector &bytecod for (size_t i = 0; i < vec.size(); i++) { log += std::to_string(reinterpret_cast(vec[i])) + " , "; } - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; } - COMPILER_LOG(INFO) << "-----------------------------------------------------------------------"; + LOG_COMPILER(INFO) << "-----------------------------------------------------------------------"; } void BytecodeCircuitBuilder::PrintGraph() { for (size_t i = 0; i < graph_.size(); i++) { if (graph_[i].isDead) { - COMPILER_LOG(INFO) << "BB_" << graph_[i].id << ": ;predsId= invalid BB"; - COMPILER_LOG(INFO) << "curStartPc: " << reinterpret_cast(graph_[i].start) << + LOG_COMPILER(INFO) << "BB_" << graph_[i].id << ": ;predsId= invalid BB"; + LOG_COMPILER(INFO) << "curStartPc: " << reinterpret_cast(graph_[i].start) << " curEndPc: " << reinterpret_cast(graph_[i].end); continue; } @@ -2531,17 +2543,17 @@ void BytecodeCircuitBuilder::PrintGraph() for (size_t k = 0; k < graph_[i].preds.size(); ++k) { log += std::to_string(graph_[i].preds[k]->id) + ", "; } - COMPILER_LOG(INFO) << log; - COMPILER_LOG(INFO) << "curStartPc: " << reinterpret_cast(graph_[i].start) << + LOG_COMPILER(INFO) << log; + LOG_COMPILER(INFO) << "curStartPc: " << reinterpret_cast(graph_[i].start) << " curEndPc: " << reinterpret_cast(graph_[i].end); for (size_t j = 0; j < graph_[i].preds.size(); j++) { - COMPILER_LOG(INFO) << "predsStartPc: " << reinterpret_cast(graph_[i].preds[j]->start) << + LOG_COMPILER(INFO) << "predsStartPc: " << reinterpret_cast(graph_[i].preds[j]->start) << " predsEndPc: " << reinterpret_cast(graph_[i].preds[j]->end); } for (size_t j = 0; j < graph_[i].succs.size(); j++) { - COMPILER_LOG(INFO) << "succesStartPc: " << reinterpret_cast(graph_[i].succs[j]->start) << + LOG_COMPILER(INFO) << "succesStartPc: " << reinterpret_cast(graph_[i].succs[j]->start) << " succesEndPc: " << reinterpret_cast(graph_[i].succs[j]->end); } @@ -2549,21 +2561,21 @@ void BytecodeCircuitBuilder::PrintGraph() for (size_t j = 0; j < graph_[i].succs.size(); j++) { log1 += std::to_string(graph_[i].succs[j]->id) + ", "; } - COMPILER_LOG(INFO) << log1; + LOG_COMPILER(INFO) << log1; for (size_t j = 0; j < graph_[i].catchs.size(); j++) { - COMPILER_LOG(INFO) << "catchStartPc: " << reinterpret_cast(graph_[i].catchs[j]->start) << + LOG_COMPILER(INFO) << "catchStartPc: " << reinterpret_cast(graph_[i].catchs[j]->start) << " catchEndPc: " << reinterpret_cast(graph_[i].catchs[j]->end); } for (size_t j = 0; j < graph_[i].immDomBlocks.size(); j++) { - COMPILER_LOG(INFO) << "dominate block id: " << graph_[i].immDomBlocks[j]->id << " startPc: " << + LOG_COMPILER(INFO) << "dominate block id: " << graph_[i].immDomBlocks[j]->id << " startPc: " << reinterpret_cast(graph_[i].immDomBlocks[j]->start) << " endPc: " << reinterpret_cast(graph_[i].immDomBlocks[j]->end); } if (graph_[i].iDominator) { - COMPILER_LOG(INFO) << "current block " << graph_[i].id << + LOG_COMPILER(INFO) << "current block " << graph_[i].id << " immediate dominator is " << graph_[i].iDominator->id; } @@ -2571,14 +2583,14 @@ void BytecodeCircuitBuilder::PrintGraph() for (const auto &frontier: graph_[i].domFrontiers) { log2 += std::to_string(frontier->id) + " , "; } - COMPILER_LOG(INFO) << log2; + LOG_COMPILER(INFO) << log2; std::string log3("current block " + std::to_string(graph_[i].id) + " phi variable: "); for (auto variable: graph_[i].phi) { log3 += std::to_string(variable) + " , "; } - COMPILER_LOG(INFO) << log3; - COMPILER_LOG(INFO) << "-------------------------------------------------------"; + LOG_COMPILER(INFO) << log3; + LOG_COMPILER(INFO) << "-------------------------------------------------------"; } } @@ -2589,7 +2601,7 @@ void BytecodeCircuitBuilder::PrintBytecodeInfo() continue; } auto pc = bb.start; - COMPILER_LOG(INFO) << "BB_" << bb.id << ": "; + LOG_COMPILER(INFO) << "BB_" << bb.id << ": "; while (pc <= bb.end) { std::string log; auto curInfo = GetBytecodeInfo(pc); @@ -2610,7 +2622,7 @@ void BytecodeCircuitBuilder::PrintBytecodeInfo() log += std::to_string(out) + ","; } log += "]"; - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; pc += curInfo.offset; } } @@ -2622,28 +2634,28 @@ void BytecodeCircuitBuilder::PrintBBInfo() if (bb.isDead) { continue; } - COMPILER_LOG(INFO) << "------------------------"; - COMPILER_LOG(INFO) << "block: " << bb.id; + LOG_COMPILER(INFO) << "------------------------"; + LOG_COMPILER(INFO) << "block: " << bb.id; std::string log("preds: "); for (auto pred: bb.preds) { log += std::to_string(pred->id) + " , "; } - COMPILER_LOG(INFO) << log; + LOG_COMPILER(INFO) << log; std::string log1("succs: "); for (auto succ: bb.succs) { log1 += std::to_string(succ->id) + " , "; } - COMPILER_LOG(INFO) << log1; + LOG_COMPILER(INFO) << log1; std::string log2("catchs: "); for (auto catchBlock: bb.catchs) { log2 += std::to_string(catchBlock->id) + " , "; } - COMPILER_LOG(INFO) << log2; + LOG_COMPILER(INFO) << log2; std::string log3("trys: "); for (auto tryBlock: bb.trys) { log3 += std::to_string(tryBlock->id) + " , "; } - COMPILER_LOG(INFO) << log3; + LOG_COMPILER(INFO) << log3; } } } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/bytecode_circuit_builder.h b/ecmascript/compiler/bytecode_circuit_builder.h index 86adfc85000a561fa2aa7d65c0cacf32c4dd165d..896d8ba81515c1a1dd80361788aeb5d6799ee09a 100644 --- a/ecmascript/compiler/bytecode_circuit_builder.h +++ b/ecmascript/compiler/bytecode_circuit_builder.h @@ -22,7 +22,8 @@ #include #include -#include "circuit.h" +#include "ecmascript/compiler/argument_accessor.h" +#include "ecmascript/compiler/circuit.h" #include "ecmascript/interpreter/interpreter-inl.h" #include "ecmascript/js_method.h" #include "ecmascript/jspandafile/js_pandafile.h" @@ -359,6 +360,23 @@ struct BytecodeInfo { { return ComputeValueInputCount() + ComputeBCOffsetInputCount(); } + + bool IsGeneratorRelative() const + { + auto ecmaOpcode = static_cast(opcode); + switch (ecmaOpcode) { + case EcmaOpcode::SUSPENDGENERATOR_PREF_V8_V8: + case EcmaOpcode::RESUMEGENERATOR_PREF_V8: + return true; + default: + return false; + } + } + + bool IsBc(EcmaOpcode ecmaOpcode) const + { + return opcode == ecmaOpcode; + } }; enum BytecodeOffset { @@ -374,15 +392,6 @@ enum BytecodeOffset { TEN }; -enum CommonArgIdx : uint8_t { - GLUE = 0, - ACTUAL_ARGC, - FUNC, - NEW_TARGET, - THIS, - NUM_OF_ARGS, -}; - class BytecodeCircuitBuilder { public: explicit BytecodeCircuitBuilder(const BytecodeTranslationInfo &translationInfo, size_t index, @@ -391,6 +400,7 @@ public: method_(translationInfo.methodPcInfos[index].method), pcArray_(translationInfo.methodPcInfos[index].pcArray), constantPool_(translationInfo.constantPool), + argAcc_(&circuit_, method_), enableLog_(enableLog) { } @@ -431,11 +441,6 @@ public: return jsgateToBytecode_.at(gate).second; } - [[nodiscard]] GateRef GetCommonArgByIndex(CommonArgIdx idx) - { - return commonArgs_[idx]; - } - BytecodeInfo GetBytecodeInfo(const uint8_t *pc); // for external users, circuit must be built BytecodeInfo GetByteCodeInfo(const GateRef gate) @@ -449,6 +454,11 @@ public: return enableLog_; } + [[nodiscard]] const std::vector& GetAsyncRelatedGates() const + { + return suspendAndResumeGates_; + } + private: void PUBLIC_API CollectBytecodeBlockInfo(uint8_t* pc, std::vector &bytecodeBlockInfos); @@ -486,32 +496,31 @@ private: GateRef RenameVariable(const size_t bbId, const uint8_t *end, const uint16_t reg, const bool acc, GateType gateType = GateType::AnyType()); void BuildCircuit(); - void PrintCollectBlockInfo(std::vector &bytecodeBlockInfos); - size_t GetFunctionArgIndex(size_t currentVreg, size_t numVregs) const; void PrintGraph(); void PrintBytecodeInfo(); void PrintBBInfo(); GateType GetRealGateType(const uint16_t reg, const GateType gateType); - size_t GetActualNumArgs(size_t numArgs) + + inline bool IsEntryBlock(const size_t bbId) const { - return numArgs + CommonArgIdx::NUM_OF_ARGS; + return bbId == 0; } kungfu::Circuit circuit_; std::map> jsgateToBytecode_; std::map byteCodeToJSGate_; BytecodeGraph graph_; - std::array commonArgs_ {}; - std::vector actualArgs_ {}; TSLoader *tsLoader_ {nullptr}; const JSPandaFile *file_ {nullptr}; const panda_file::File *pf_ {nullptr}; const JSMethod *method_ {nullptr}; const std::vector pcArray_; JSHandle constantPool_; + ArgumentAccessor argAcc_; bool enableLog_ {false}; std::map pcToBCOffset_; + std::vector suspendAndResumeGates_ {}; }; } // namespace panda::ecmascript::kungfu #endif // ECMASCRIPT_CLASS_LINKER_BYTECODE_CIRCUIT_IR_BUILDER_H diff --git a/ecmascript/compiler/call_signature.cpp b/ecmascript/compiler/call_signature.cpp index 94541158323d27568a7e7846ef608824ec7348ba..442b0cbba0b55c6ad19364fd1bc41f66c596cfd1 100644 --- a/ecmascript/compiler/call_signature.cpp +++ b/ecmascript/compiler/call_signature.cpp @@ -520,7 +520,7 @@ DEF_CALL_SIGNATURE(CallRuntimeWithArgv) std::array params = { /* 4 : 4 input parameters */ VariableType::NATIVE_POINTER(), // glue VariableType::INT64(), // runtimeId - VariableType::INT32(), // argc + VariableType::INT64(), // argc VariableType::NATIVE_POINTER(), // argv }; callSign->SetVariadicArgs(false); @@ -537,8 +537,8 @@ DEF_CALL_SIGNATURE(OptimizedCallOptimized) *callSign = runtimeCallTrampoline; std::array params = { /* 4 : 4 input parameters */ VariableType::NATIVE_POINTER(), - VariableType::INT32(), - VariableType::INT32(), + VariableType::INT64(), + VariableType::INT64(), VariableType::NATIVE_POINTER(), }; callSign->SetVariadicArgs(true); @@ -550,12 +550,13 @@ DEF_CALL_SIGNATURE(OptimizedCallOptimized) DEF_CALL_SIGNATURE(JSCall) { // 5 : 5 input parameters - CallSignature jSCall("JSCall", 0, 5, + CallSignature jSCall("JSCall", 0, 6, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = jSCall; - std::array params = { // 5 : 5 input parameters + std::array params = { // 6 : 6 input parameters VariableType::NATIVE_POINTER(), // glue - VariableType::INT32(), // actual argC + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), // actual argC VariableType::JS_ANY(), // call target VariableType::JS_ANY(), // new target VariableType::JS_ANY(), // thisobj @@ -566,15 +567,15 @@ DEF_CALL_SIGNATURE(JSCall) callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC); } -DEF_CALL_SIGNATURE(JSCallWithArgV) +DEF_CALL_SIGNATURE(JSProxyCallInternalWithArgV) { // 4 : 4 input parameters - CallSignature jSCallWithArgV("JSCallWithArgV", 0, 4, + CallSignature jSProxyCallInternalWithArgV("JSProxyCallInternalWithArgV", 0, 4, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); - *callSign = jSCallWithArgV; + *callSign = jSProxyCallInternalWithArgV; std::array params = { // 4 : 4 input parameters VariableType::NATIVE_POINTER(), // glue - VariableType::INT32(), // actual argC + VariableType::INT64(), // actual argC VariableType::JS_ANY(), // call target VariableType::NATIVE_POINTER(), // argv }; @@ -593,8 +594,8 @@ DEF_CALL_SIGNATURE(JSFunctionEntry) std::array params = { // 6 : 6 input parameters VariableType::NATIVE_POINTER(), // glue VariableType::NATIVE_POINTER(), // prev fp - VariableType::INT32(), // expectedNumArgs - VariableType::INT32(), // actualNumArgs + VariableType::INT64(), // expectedNumArgs + VariableType::INT64(), // actualNumArgs VariableType::NATIVE_POINTER(), // argv VariableType::NATIVE_POINTER(), // codeAddr }; @@ -603,23 +604,6 @@ DEF_CALL_SIGNATURE(JSFunctionEntry) callSign->SetCallConv(CallSignature::CallConv::CCallConv); } -DEF_CALL_SIGNATURE(CallBuiltinTrampoline) -{ - /* 3 : 3 input parameters */ - CallSignature CallBuiltinTrampoline("CallBuiltinTrampoline", 0, 3, - ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); - *callSign = CallBuiltinTrampoline; - std::array params = { /* 3 : 3 input parameters */ - VariableType::NATIVE_POINTER(), // glue - VariableType::NATIVE_POINTER(), // codeAddress - VariableType::INT32(), // argc - }; - callSign->SetVariadicArgs(true); - callSign->SetParameters(params.data()); - callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC); - callSign->SetCallConv(CallSignature::CallConv::CCallConv); -} - DEF_CALL_SIGNATURE(ResumeRspAndDispatch) { // 8 : 8 input parameters @@ -643,12 +627,14 @@ DEF_CALL_SIGNATURE(ResumeRspAndDispatch) DEF_CALL_SIGNATURE(ResumeRspAndReturn) { - // 1 : 1 input parameters - CallSignature resumeRspAndReturn("ResumeRspAndReturn", 0, 1, + // 3 : 3 input parameters + CallSignature resumeRspAndReturn("ResumeRspAndReturn", 0, 3, ArgumentsOrder::DEFAULT_ORDER, VariableType::VOID()); *callSign = resumeRspAndReturn; - std::array params = { // 1 : 1 input parameters + std::array params = { // 3 : 3 input parameters VariableType::JS_ANY(), + VariableType::NATIVE_POINTER(), + VariableType::NATIVE_POINTER(), }; callSign->SetParameters(params.data()); callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC); @@ -677,12 +663,14 @@ DEF_CALL_SIGNATURE(ResumeCaughtFrameAndDispatch) DEF_CALL_SIGNATURE(ResumeUncaughtFrameAndReturn) { - // 1 : 1 input parameters - CallSignature resumeUncaughtFrameAndReturn("ResumeUncaughtFrameAndReturn", 0, 1, + // 3 : 3 input parameters + CallSignature resumeUncaughtFrameAndReturn("ResumeUncaughtFrameAndReturn", 0, 3, ArgumentsOrder::DEFAULT_ORDER, VariableType::VOID()); *callSign = resumeUncaughtFrameAndReturn; - std::array params = { // 1 : 1 input parameters + std::array params = { // 3 : 3 input parameters + VariableType::NATIVE_POINTER(), VariableType::NATIVE_POINTER(), + VariableType::JS_ANY(), }; callSign->SetParameters(params.data()); callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC); @@ -803,6 +791,26 @@ DEF_CALL_SIGNATURE(CallSetter) PUSH_CALL_ARGS_AND_DISPATCH_NATIVE_RANGE_SIGNATURE(CallSetter) } +DEF_CALL_SIGNATURE(JSCallWithArgV) +{ + // 6 : 6 input parameters + CallSignature jSCallWithArgV("JSCallWithArgV", 0, 6, + ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); + *callSign = jSCallWithArgV; + // 6 : 6 input parameters + std::array params = { + VariableType::NATIVE_POINTER(), // glue + VariableType::INT64(), // actualNumArgs + VariableType::JS_ANY(), // jsfunc + VariableType::JS_ANY(), // newTarget + VariableType::JS_ANY(), // this + VariableType::NATIVE_POINTER(), // argV + }; + callSign->SetParameters(params.data()); + callSign->SetTargetKind(CallSignature::TargetKind::RUNTIME_STUB_NO_GC); + callSign->SetCallConv(CallSignature::CallConv::CCallConv); +} + DEF_CALL_SIGNATURE(DebugPrint) { // 1 : 1 input parameters @@ -1016,7 +1024,7 @@ DEF_CALL_SIGNATURE(JsProxyCallInternal) *callSign = proxyCallInternal; std::array params = { // 4 : 4 input parameters VariableType::NATIVE_POINTER(), // glue - VariableType::INT32(), // actual argC + VariableType::INT64(), // actual argC VariableType::JS_POINTER(), // callTarget VariableType::NATIVE_POINTER(), // argv }; diff --git a/ecmascript/compiler/call_signature.h b/ecmascript/compiler/call_signature.h index caa98b185eca8dd453b5e949ce720433aad30512..7cab36b11ab25bb1a73db0de35114ae273a8b440 100644 --- a/ecmascript/compiler/call_signature.h +++ b/ecmascript/compiler/call_signature.h @@ -328,6 +328,7 @@ private: V(PushCallNewAndDispatch) \ V(CallGetter) \ V(CallSetter) \ + V(JSCallWithArgV) \ V(ResumeRspAndDispatch) \ V(ResumeRspAndReturn) \ V(ResumeCaughtFrameAndDispatch) \ @@ -349,8 +350,7 @@ private: V(CallIRangeDyn) \ V(JSCall) \ V(JSFunctionEntry) \ - V(CallBuiltinTrampoline) \ - V(JSCallWithArgV) \ + V(JSProxyCallInternalWithArgV) \ V(CreateArrayFromList) \ V(JSObjectGetMethod) \ V(JsProxyCallInternal) \ diff --git a/ecmascript/compiler/circuit.cpp b/ecmascript/compiler/circuit.cpp index a4147a4fa5c8623895685952b61cc44e20034822..2c84c167b05320958b23e38923c180e9471ce8ab 100644 --- a/ecmascript/compiler/circuit.cpp +++ b/ecmascript/compiler/circuit.cpp @@ -62,7 +62,7 @@ GateRef Circuit::NewGate(OpCode opcode, MachineType bitValue, BitField bitfield, { #ifndef NDEBUG if (numIns != opcode.GetOpCodeNumIns(bitfield)) { - COMPILER_LOG(ERROR) << "Invalid input list!" + LOG_COMPILER(ERROR) << "Invalid input list!" << " op=" << opcode.Str() << " bitfield=" << bitfield << " expected_num_in=" << opcode.GetOpCodeNumIns(bitfield) << " actual_num_in=" << numIns; UNREACHABLE(); @@ -92,7 +92,7 @@ GateRef Circuit::NewGate(OpCode opcode, BitField bitfield, size_t numIns, const { #ifndef NDEBUG if (numIns != opcode.GetOpCodeNumIns(bitfield)) { - COMPILER_LOG(ERROR) << "Invalid input list!" + LOG_COMPILER(ERROR) << "Invalid input list!" << " op=" << opcode.Str() << " bitfield=" << bitfield << " expected_num_in=" << opcode.GetOpCodeNumIns(bitfield) << " actual_num_in=" << numIns; UNREACHABLE(); diff --git a/ecmascript/compiler/circuit_builder-inl.h b/ecmascript/compiler/circuit_builder-inl.h index 01200c63d6236e7f3892e1aee911ca29eec6b8ac..a759352e1ccb05572e966ef68377b51729c1d1ce 100644 --- a/ecmascript/compiler/circuit_builder-inl.h +++ b/ecmascript/compiler/circuit_builder-inl.h @@ -53,7 +53,7 @@ GateRef CircuitBuilder::Load(VariableType type, GateRef base, GateRef offset) GateRef CircuitBuilder::TaggedCastToInt64(GateRef x) { GateRef tagged = ChangeTaggedPointerToInt64(x); - return Int64And(tagged, Int64(~JSTaggedValue::TAG_MASK)); + return Int64And(tagged, Int64(~JSTaggedValue::TAG_MARK)); } GateRef CircuitBuilder::TaggedCastToInt32(GateRef x) @@ -91,7 +91,7 @@ GateRef CircuitBuilder::IsSpecial(GateRef x, JSTaggedType type) } GateRef CircuitBuilder::TaggedIsInt(GateRef x) { - return Equal(Int64And(x, Int64(JSTaggedValue::TAG_MASK)), + return Equal(Int64And(x, Int64(JSTaggedValue::TAG_MARK)), Int64(JSTaggedValue::TAG_INT)); } @@ -102,7 +102,7 @@ GateRef CircuitBuilder::TaggedIsDouble(GateRef x) GateRef CircuitBuilder::TaggedIsObject(GateRef x) { - return Equal(Int64And(x, Int64(JSTaggedValue::TAG_MASK)), + return Equal(Int64And(x, Int64(JSTaggedValue::TAG_MARK)), Int64(JSTaggedValue::TAG_OBJECT)); } @@ -133,11 +133,9 @@ GateRef CircuitBuilder::TaggedIsException(GateRef x) GateRef CircuitBuilder::TaggedIsSpecial(GateRef x) { - return TruncInt32ToInt1(Int32And(SExtInt1ToInt32(Equal(Int64And(x, - Int64(~JSTaggedValue::TAG_SPECIAL_MASK)), - Int64(0))), Int32Or(SExtInt1ToInt32(NotEqual(Int64And(x, - Int64(JSTaggedValue::TAG_SPECIAL_VALUE)), - Int64(0))), SExtInt1ToInt32(IsSpecial(x, JSTaggedValue::VALUE_HOLE))))); + return BoolOr( + Equal(Int64And(x, Int64(JSTaggedValue::TAG_SPECIAL_MARK)), Int64(JSTaggedValue::TAG_SPECIAL)), + TaggedIsHole(x)); } GateRef CircuitBuilder::TaggedIsHeapObject(GateRef x) @@ -168,7 +166,7 @@ GateRef CircuitBuilder::TaggedIsWeak(GateRef x) { return TruncInt32ToInt1(Int32And(SExtInt1ToInt32(TaggedIsHeapObject(x)), SExtInt1ToInt32(Equal(Int64And(x, - Int64(JSTaggedValue::TAG_WEAK_MASK)), + Int64(JSTaggedValue::TAG_WEAK)), Int64(1))))); } @@ -212,7 +210,7 @@ GateRef CircuitBuilder::TaggedIsBoolean(GateRef x) GateRef CircuitBuilder::TaggedGetInt(GateRef x) { - return TruncInt64ToInt32(Int64And(x, Int64(~JSTaggedValue::TAG_MASK))); + return TruncInt64ToInt32(Int64And(x, Int64(~JSTaggedValue::TAG_MARK))); } GateRef CircuitBuilder::TaggedTypeNGC(GateRef x) @@ -504,6 +502,11 @@ GateRef CircuitBuilder::GetDepend() const return GetCurrentLabel()->GetDepend(); } +void CircuitBuilder::SetDepend(GateRef depend) +{ + GetCurrentLabel()->SetDepend(depend); +} + void Label::Seal() { return impl_->Seal(); diff --git a/ecmascript/compiler/circuit_builder.cpp b/ecmascript/compiler/circuit_builder.cpp index f0e476c98560b52fc7d8c20300d1f66bebef26c0..949965881658e2e70ae168ad99f6b2db9c7e43f3 100644 --- a/ecmascript/compiler/circuit_builder.cpp +++ b/ecmascript/compiler/circuit_builder.cpp @@ -469,6 +469,11 @@ void CircuitBuilder::SetLexicalEnvToFunction(GateRef glue, GateRef function, Gat Store(VariableType::JS_ANY(), glue, function, offset, value); } +GateRef CircuitBuilder::GetLexicalEnv(GateRef function) +{ + return Load(VariableType::JS_POINTER(), function, IntPtr(JSFunction::LEXICAL_ENV_OFFSET)); +} + void CircuitBuilder::SetModuleToFunction(GateRef glue, GateRef function, GateRef value) { GateRef offset = IntPtr(JSFunction::ECMA_MODULE_OFFSET); diff --git a/ecmascript/compiler/circuit_builder.h b/ecmascript/compiler/circuit_builder.h index f33911def039ad89f885bfb93071beef7f8d24d7..4d5a4f8d206bbb8b237aa0ec09b5172fdae28f39 100644 --- a/ecmascript/compiler/circuit_builder.h +++ b/ecmascript/compiler/circuit_builder.h @@ -16,6 +16,8 @@ #ifndef ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_H #define ECMASCRIPT_COMPILER_CIRCUIT_BUILDER_H +#include + #include "ecmascript/compiler/circuit.h" #include "ecmascript/compiler/gate.h" #include "ecmascript/compiler/gate_accessor.h" @@ -353,6 +355,7 @@ public: void SetResolvedToFunction(GateRef glue, GateRef function, GateRef value); void SetConstPoolToFunction(GateRef glue, GateRef function, GateRef value); void SetLexicalEnvToFunction(GateRef glue, GateRef function, GateRef value); + GateRef GetLexicalEnv(GateRef function); void SetModuleToFunction(GateRef glue, GateRef function, GateRef value); void SetPropertyInlinedProps(GateRef glue, GateRef obj, GateRef hClass, GateRef value, GateRef attrOffset, VariableType type); @@ -393,6 +396,7 @@ public: inline Label *GetCurrentLabel() const; inline GateRef GetState() const; inline GateRef GetDepend() const; + inline void SetDepend(GateRef depend); private: Circuit *circuit_ {nullptr}; diff --git a/ecmascript/compiler/common_stubs.cpp b/ecmascript/compiler/common_stubs.cpp index a60d577bfe574b204a85bea9970b333eb92dcefc..80aa5521b1145ceb48e401968f3ba8c3bdebbc7d 100644 --- a/ecmascript/compiler/common_stubs.cpp +++ b/ecmascript/compiler/common_stubs.cpp @@ -229,72 +229,10 @@ void SetPropertyByNameWithOwnStub::GenerateCircuit(const CompilationConfig *cfg) void GetPropertyByValueStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); - auto env = GetEnvironment(); GateRef glue = PtrArgument(0); GateRef receiver = TaggedArgument(1); - DEFVARIABLE(key, VariableType::JS_ANY(), TaggedArgument(2)); /* 2 : 3rd parameter is key */ - - Label isNumberOrStringSymbol(env); - Label notNumber(env); - Label isStringOrSymbol(env); - Label notStringOrSymbol(env); - Label exit(env); - - Branch(TaggedIsNumber(*key), &isNumberOrStringSymbol, ¬Number); - Bind(¬Number); - { - Branch(TaggedIsStringOrSymbol(*key), &isNumberOrStringSymbol, ¬StringOrSymbol); - Bind(¬StringOrSymbol); - { - Return(Hole()); - } - } - Bind(&isNumberOrStringSymbol); - { - GateRef index = TryToElementsIndex(*key); - Label validIndex(env); - Label notValidIndex(env); - Branch(Int32GreaterThanOrEqual(index, Int32(0)), &validIndex, ¬ValidIndex); - Bind(&validIndex); - { - Return(GetPropertyByIndex(glue, receiver, index)); - } - Bind(¬ValidIndex); - { - Label notNumber1(env); - Label getByName(env); - Branch(TaggedIsNumber(*key), &exit, ¬Number1); - Bind(¬Number1); - { - Label isString(env); - Label notString(env); - Label isInternalString(env); - Label notIntenalString(env); - Branch(TaggedIsString(*key), &isString, ¬String); - Bind(&isString); - { - Branch(IsInternalString(*key), &isInternalString, ¬IntenalString); - Bind(&isInternalString); - Jump(&getByName); - Bind(¬IntenalString); - { - key = CallRuntime(glue, RTSTUB_ID(NewInternalString), { *key }); - Jump(&getByName); - } - } - Bind(¬String); - { - Jump(&getByName); - } - } - Bind(&getByName); - { - Return(GetPropertyByName(glue, receiver, *key)); - } - } - } - Bind(&exit); - Return(Hole()); + GateRef key = TaggedArgument(2); // 2 : 3rd para + Return(GetPropertyByValue(glue, receiver, key)); } void SetPropertyByValueStub::GenerateCircuit(const CompilationConfig *cfg) @@ -516,7 +454,7 @@ void JsProxyCallInternalStub::GenerateCircuit(const CompilationConfig *cfg) Label isNotUndefined(env); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); + GateRef argc = Int64Argument(1); GateRef proxy = TaggedPointerArgument(2); // callTarget GateRef argv = PtrArgument(3); @@ -542,16 +480,17 @@ void JsProxyCallInternalStub::GenerateCircuit(const CompilationConfig *cfg) Branch(TaggedIsUndefined(method), &isUndefined, &isNotUndefined); Bind(&isUndefined); { - result = CallNGCRuntime(glue, RTSTUB_ID(JSCallWithArgV), {glue, argc, target, argv}); + result = CallNGCRuntime(glue, RTSTUB_ID(JSProxyCallInternalWithArgV), {glue, argc, target, argv}); Return(*result); } Bind(&isNotUndefined); { GateRef arrHandle = CallRuntime(glue, RTSTUB_ID(CreateArrayFromList), argc, argv); GateRef thisArg = Load(VariableType::JS_POINTER(), argv, IntPtr(2*sizeof(JSTaggedValue))); - GateRef numArgs = Int32(6); + GateRef numArgs = Int64(JSPROXY_NUM_ARGS + NUM_MANDATORY_JSFUNC_ARGS); + GateRef lexEnv = Load(VariableType::JS_POINTER(), method, IntPtr(JSFunction::LEXICAL_ENV_OFFSET)); result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), - {glue, numArgs, method, Undefined(), handler, target, thisArg, arrHandle}); + {glue, lexEnv, numArgs, method, Undefined(), handler, target, thisArg, arrHandle}); Jump(&exit); } } diff --git a/ecmascript/compiler/common_stubs.h b/ecmascript/compiler/common_stubs.h index 84b2c66a37b4c04250c8aeb20e4517286e3b8536..52398ba17eeb837d98915d6b14313dcdf1be70a4 100644 --- a/ecmascript/compiler/common_stubs.h +++ b/ecmascript/compiler/common_stubs.h @@ -341,6 +341,8 @@ public: NO_MOVE_SEMANTIC(JsProxyCallInternalStub); NO_COPY_SEMANTIC(JsProxyCallInternalStub); void GenerateCircuit(const CompilationConfig *cfg) override; +private: + static constexpr int JSPROXY_NUM_ARGS = 3; }; class CommonStubCSigns { diff --git a/ecmascript/compiler/compiler_log.h b/ecmascript/compiler/compiler_log.h index 982d27be8ec118037fb634401315fbddeae060e0..e48b2de023eabcdc38ca5b78a23ff2b4724aa346 100644 --- a/ecmascript/compiler/compiler_log.h +++ b/ecmascript/compiler/compiler_log.h @@ -34,6 +34,11 @@ public: return methods_.compare("all") == 0; } + bool IsDisassembleEnabled() const + { + return methods_.compare("asm") == 0; + } + bool IsAlwaysDisabled() const { return methods_.compare("none") == 0; diff --git a/ecmascript/compiler/file_generators.cpp b/ecmascript/compiler/file_generators.cpp index f26e2129ec39baa562e6c5b7355ef694e04a2756..0539a145b5e557dc8b4c11adbe307e2fc290ce8b 100644 --- a/ecmascript/compiler/file_generators.cpp +++ b/ecmascript/compiler/file_generators.cpp @@ -38,7 +38,6 @@ void StubFileGenerator::CollectAsmStubCodeInfo(std::map auto codeBuffer = modulePackage_[0].GetCodeBuffer(); uintptr_t entry = codeBuffer + entryOffset + codeBegin; addr2name[entry] = cs->GetName(); - DisassembleEachFunc(addr2name); } } @@ -83,11 +82,11 @@ void StubFileGenerator::RunAsmAssembler() auto currentOffset = modulePackage_[0].GetCodeSize(); auto codeBuffer = modulePackage_[0].AllocaCodeSection(bufferSize, "asm code"); if (codeBuffer == nullptr) { - LOG_ECMA(FATAL) << "AllocaCodeSection failed"; + LOG_FULL(FATAL) << "AllocaCodeSection failed"; return; } if (memcpy_s(codeBuffer, bufferSize, buffer, bufferSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; return; } asmModule_.SetCodeBufferOffset(currentOffset); @@ -114,7 +113,11 @@ void AOTFileGenerator::GenerateSnapshotFile() TSLoader *tsLoader = vm_->GetTSLoader(); Snapshot snapshot(vm_); CVector constStringTable = tsLoader->GetConstStringTable(); + CVector staticHClassTable = tsLoader->GetStaticHClassTable(); + CVector tsLoaderSerializeTable(constStringTable); + tsLoaderSerializeTable.insert(tsLoaderSerializeTable.end(), staticHClassTable.begin(), staticHClassTable.end()); const CString snapshotPath(vm_->GetJSOptions().GetSnapshotOutputFile().c_str()); - snapshot.Serialize(reinterpret_cast(constStringTable.data()), constStringTable.size(), snapshotPath); + snapshot.Serialize(reinterpret_cast(tsLoaderSerializeTable.data()), tsLoaderSerializeTable.size(), + snapshotPath); } } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/file_generators.h b/ecmascript/compiler/file_generators.h index 55c8ecadc3e0e5cabb3e8845644c482082d0d31c..dedf6687fd43560c519c2709103960c3ddeb7e37 100644 --- a/ecmascript/compiler/file_generators.h +++ b/ecmascript/compiler/file_generators.h @@ -77,7 +77,7 @@ public: uint64_t length = 0; std::string funcName(LLVMGetValueName2(func, &length)); assert(length != 0); - COMPILER_LOG(INFO) << "CollectCodeInfo for AOT func: " << funcName.c_str(); + LOG_COMPILER(INFO) << "CollectCodeInfo for AOT func: " << funcName.c_str(); addr2name[funcEntry] = funcName; int delta = assembler_->GetFpDeltaPrevFramSp(func, log); ASSERT(delta >= 0 && (delta % sizeof(uintptr_t) == 0)); @@ -201,7 +201,7 @@ public: void AddModule(LLVMModule *llvmModule, LLVMAssembler *assembler, const JSPandaFile *jsPandaFile) { modulePackage_.emplace_back(Module(llvmModule, assembler)); - auto hash = jsPandaFile->GetPandaFile()->GetFilenameHash(); + auto hash = jsPandaFile->GetFileUniqId(); aotfileHashs_.emplace_back(hash); } diff --git a/ecmascript/compiler/gate.cpp b/ecmascript/compiler/gate.cpp index 7b4001bfa644922b0c7373c114dffe5c00e23cc5..59fda343adab62c35dfe434243ddbac96db58444 100644 --- a/ecmascript/compiler/gate.cpp +++ b/ecmascript/compiler/gate.cpp @@ -14,7 +14,6 @@ */ #include "ecmascript/compiler/gate.h" -#include "ecmascript/compiler/bytecode_circuit_builder.h" namespace panda::ecmascript::kungfu { constexpr size_t ONE_DEPEND = 1; @@ -185,8 +184,13 @@ Properties OpCode::GetProperties() const return {FLEX, NO_STATE, NO_DEPEND, VALUE(ANYVALUE), NO_ROOT}; case BITCAST: return {FLEX, NO_STATE, NO_DEPEND, VALUE(ANYVALUE), NO_ROOT}; + // suspend relate HIR + case RESTORE_REGISTER: + return {FLEX, NO_STATE, ONE_DEPEND, NO_VALUE, NO_ROOT}; + case SAVE_REGISTER: + return {NOVALUE, NO_STATE, ONE_DEPEND, VALUE(ANYVALUE), NO_ROOT}; default: - COMPILER_LOG(ERROR) << "Please complete OpCode properties (OpCode=" << op_ << ")"; + LOG_COMPILER(ERROR) << "Please complete OpCode properties (OpCode=" << op_ << ")"; UNREACHABLE(); } #undef STATE @@ -294,6 +298,8 @@ std::string OpCode::Str() const {FLOAT_TO_SIGNED_INT, "FLOAT_TO_SIGNED_INT"}, {UNSIGNED_FLOAT_TO_INT, "UNSIGNED_FLOAT_TO_INT"}, {BITCAST, "BITCAST"}, + {RESTORE_REGISTER, "RESTORE_REGISTER"}, + {SAVE_REGISTER, "SAVE_REGISTER"}, }; if (strMap.count(op_) > 0) { return strMap.at(op_); @@ -310,10 +316,9 @@ size_t OpCode::GetStateCount(BitField bitfield) const size_t OpCode::GetDependCount(BitField bitfield) const { - const size_t manyDepend = 2; auto properties = GetProperties(); auto dependProp = properties.dependsIn; - return (dependProp == manyDepend) ? bitfield : dependProp; + return (dependProp == MANY_DEPEND) ? bitfield : dependProp; } size_t OpCode::GetInValueCount(BitField bitfield) const @@ -655,9 +660,9 @@ bool Gate::Verify() const } } if (failed) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Gate level input list schema verify failed"; + LOG_COMPILER(ERROR) << "[Verifier][Error] Gate level input list schema verify failed"; Print("", true, highlightIdx); - COMPILER_LOG(ERROR) << "Note: " << errorString; + LOG_COMPILER(ERROR) << "Note: " << errorString; } return !failed; } @@ -937,7 +942,7 @@ In *Gate::GetIn(size_t idx) { #ifndef NDEBUG if (idx >= GetNumIns()) { - COMPILER_LOG(INFO) << std::dec << "Gate In access out-of-bound! (idx=" << idx << ")"; + LOG_COMPILER(INFO) << std::dec << "Gate In access out-of-bound! (idx=" << idx << ")"; Print(); ASSERT(false); } @@ -950,7 +955,7 @@ const In *Gate::GetInConst(size_t idx) const { #ifndef NDEBUG if (idx >= GetNumIns()) { - COMPILER_LOG(INFO) << std::dec << "Gate In access out-of-bound! (idx=" << idx << ")"; + LOG_COMPILER(INFO) << std::dec << "Gate In access out-of-bound! (idx=" << idx << ")"; Print(); ASSERT(false); } @@ -1118,7 +1123,7 @@ void Gate::Print(std::string bytecode, bool inListPreview, size_t highlightIdx) } log += "])"; log += "\n"; - COMPILER_LOG(INFO) << std::dec << log; + LOG_COMPILER(INFO) << std::dec << log; } } diff --git a/ecmascript/compiler/gate.h b/ecmascript/compiler/gate.h index 0e5e411bf5d0a15fe5a6828ae65783a623fdfdf8..c7189b7cf1526bc6f9cb20ae281b4a3bc3c04eb6 100644 --- a/ecmascript/compiler/gate.h +++ b/ecmascript/compiler/gate.h @@ -157,6 +157,8 @@ public: FLOAT_TO_SIGNED_INT, UNSIGNED_FLOAT_TO_INT, BITCAST, + RESTORE_REGISTER, + SAVE_REGISTER, }; OpCode() = default; diff --git a/ecmascript/compiler/gate_accessor.cpp b/ecmascript/compiler/gate_accessor.cpp index 8f60500cc0ce51d713cd363e93c5cc5e68b036c6..bd7d9cadd4df2cd7903d169bc8faac852c082758 100644 --- a/ecmascript/compiler/gate_accessor.cpp +++ b/ecmascript/compiler/gate_accessor.cpp @@ -180,4 +180,70 @@ void GateAccessor::NewIn(GateRef gate, size_t idx, GateRef in) { circuit_->NewIn(gate, idx, in); } -} \ No newline at end of file + +size_t GateAccessor::GetStateCount(GateRef gate) const +{ + return circuit_->LoadGatePtr(gate)->GetStateCount(); +} + +size_t GateAccessor::GetDependCount(GateRef gate) const +{ + return circuit_->LoadGatePtr(gate)->GetDependCount(); +} + +size_t GateAccessor::GetInValueCount(GateRef gate) const +{ + return circuit_->LoadGatePtr(gate)->GetInValueCount(); +} + +void GateAccessor::ReplaceAllDepends(GateRef gate, GateRef replaceDependIn) +{ + auto uses = Uses(gate); + for (auto useIt = uses.begin(); useIt != uses.end(); useIt++) { + size_t dependStartIndex = circuit_->LoadGatePtr(*useIt)->GetStateCount(); + size_t dependEndIndex = circuit_->LoadGatePtr(*useIt)->GetDependCount() + dependStartIndex; + if (useIt.GetIndex() >= dependStartIndex && useIt.GetIndex() < dependEndIndex) { + circuit_->ModifyIn(*useIt, useIt.GetIndex(), replaceDependIn); + } + } +} + +void GateAccessor::ReplaceIn(GateRef gate, size_t index, GateRef in) +{ + circuit_->ModifyIn(gate, index, in); +} +void GateAccessor::ReplaceStateIn(GateRef gate, GateRef in, size_t index) +{ + ASSERT(index < GetStateCount(gate)); + circuit_->ModifyIn(gate, index, in); +} + +void GateAccessor::ReplaceDependIn(GateRef gate, GateRef in, size_t index) +{ + ASSERT(index < GetDependCount(gate)); + size_t stateCount = GetStateCount(gate); + circuit_->ModifyIn(gate, stateCount + index, in); +} + +void GateAccessor::ReplaceValueIn(GateRef gate, GateRef in, size_t index) +{ + ASSERT(index < GetInValueCount(gate)); + size_t valueStartIndex = GetStateCount(gate) + GetDependCount(gate); + circuit_->ModifyIn(gate, valueStartIndex + index, in); +} + +void GateAccessor::DeleteGate(GateRef gate) +{ + circuit_->DeleteGate(gate); +} + +MachineType GateAccessor::GetMachineType(GateRef gate) const +{ + return circuit_->GetMachineType(gate); +} + +GateRef GateAccessor::GetConstantGate(MachineType bitValue, BitField bitfield, GateType type) const +{ + return circuit_->GetConstantGate(bitValue, bitfield, type); +} +} // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/gate_accessor.h b/ecmascript/compiler/gate_accessor.h index 94da48dbe5db96b778a9910134918e8d9deb83d4..6a17ae7ec101c2a8862dedbcb167465cfb6dcc32 100644 --- a/ecmascript/compiler/gate_accessor.h +++ b/ecmascript/compiler/gate_accessor.h @@ -320,7 +320,7 @@ public: void SetBitField(GateRef gate, BitField bitField); void Print(GateRef gate) const; [[nodiscard]] GateId GetId(GateRef gate) const; - [[nodiscard]] GateRef GetValueIn(GateRef gate, size_t idx) const; + [[nodiscard]] GateRef GetValueIn(GateRef gate, size_t idx = 0) const; [[nodiscard]] size_t GetNumValueIn(GateRef gate) const; [[nodiscard]] GateRef GetIn(GateRef gate, size_t idx) const; [[nodiscard]] GateRef GetState(GateRef gate, size_t idx = 0) const; @@ -337,6 +337,17 @@ public: void DeleteGate(UsesIterator &useIt); void DecreaseIn(UsesIterator &useIt); void NewIn(GateRef gate, size_t idx, GateRef in); + [[nodiscard]] size_t GetStateCount(GateRef gate) const; + [[nodiscard]] size_t GetDependCount(GateRef gate) const; + [[nodiscard]] size_t GetInValueCount(GateRef gate) const; + void ReplaceAllDepends(GateRef gate, GateRef replaceDependIn); + void ReplaceIn(GateRef gate, size_t index, GateRef in); + void ReplaceStateIn(GateRef gate, GateRef in, size_t index = 0); + void ReplaceDependIn(GateRef gate, GateRef in, size_t index = 0); + void ReplaceValueIn(GateRef gate, GateRef in, size_t index = 0); + void DeleteGate(GateRef gate); + MachineType GetMachineType(GateRef gate) const; + GateRef GetConstantGate(MachineType bitValue, BitField bitfield, GateType type) const; private: [[nodiscard]] ConstUsesIterator ConstUseBegin(GateRef gate) const diff --git a/ecmascript/compiler/interpreter_stub.cpp b/ecmascript/compiler/interpreter_stub.cpp index db20829a01e71c1d46dd9c5a9aa3f95fd42341bc..ad79ccffceabcbdf965c7259b346e7366139b9e4 100644 --- a/ecmascript/compiler/interpreter_stub.cpp +++ b/ecmascript/compiler/interpreter_stub.cpp @@ -214,7 +214,7 @@ DECLARE_ASM_HANDLER(HandleCopyRestArgsPrefImm16) DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc); auto env = GetEnvironment(); GateRef restIdx = ZExtInt16ToInt32(ReadInst16_1(pc)); - GateRef res = CallRuntime(glue, RTSTUB_ID(CopyRestArgs), { IntBuildTaggedTypeWithNoGC(restIdx) }); + GateRef res = CallRuntime(glue, RTSTUB_ID(CopyRestArgs), { IntToTaggedTypeNGC(restIdx) }); Label isException(env); Label notException(env); Branch(TaggedIsException(res), &isException, ¬Exception); @@ -273,7 +273,7 @@ DECLARE_ASM_HANDLER(HandleCreateObjectWithExcludedKeysPrefImm16V8V8) GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(ReadInst8_3(pc))); GateRef firstArgRegIdx = ZExtInt8ToInt16(ReadInst8_4(pc)); GateRef res = CallRuntime(glue, RTSTUB_ID(CreateObjectWithExcludedKeys), - { Int16BuildTaggedTypeWithNoGC(numKeys), obj, Int16BuildTaggedTypeWithNoGC(firstArgRegIdx) }); + { Int16ToTaggedTypeNGC(numKeys), obj, Int16ToTaggedTypeNGC(firstArgRegIdx) }); Label isException(env); Label notException(env); Branch(TaggedIsException(res), &isException, ¬Exception); @@ -310,7 +310,7 @@ DECLARE_ASM_HANDLER(HandleThrowIfSuperNotCorrectCallPrefImm16) auto env = GetEnvironment(); GateRef imm = ReadInst16_1(pc); GateRef res = CallRuntime(glue, RTSTUB_ID(ThrowIfSuperNotCorrectCall), - { Int16BuildTaggedTypeWithNoGC(imm), acc }); // acc is thisValue + { Int16ToTaggedTypeNGC(imm), acc }); // acc is thisValue Label isException(env); Label notException(env); Branch(TaggedIsException(res), &isException, ¬Exception); @@ -353,7 +353,7 @@ DECLARE_ASM_HANDLER(HandleNewObjDynRangePrefImm16V8) GateRef firstArgRegIdx = ZExtInt8ToInt16(ReadInst8_3(pc)); GateRef firstArgOffset = Int16(2); GateRef ctor = GetVregValue(sp, ZExtInt16ToPtr(firstArgRegIdx)); - GateRef actualNumArgs = ZExtInt16ToPtr(Int16Sub(numArgs, firstArgOffset)); + GateRef actualNumArgs = ZExtInt16ToInt32(Int16Sub(numArgs, firstArgOffset)); Label ctorIsHeapObject(env); Label ctorIsJSFunction(env); @@ -380,12 +380,12 @@ DECLARE_ASM_HANDLER(HandleNewObjDynRangePrefImm16V8) Branch(isBase, &ctorIsBase, &ctorNotBase); Bind(&ctorIsBase); { - Label notHole(env); + Label isHeapObject(env); Label checkJSObject(env); auto protoOrHclass = Load(VariableType::JS_ANY(), ctor, IntPtr(JSFunction::PROTO_OR_DYNCLASS_OFFSET)); - Branch(TaggedIsHole(protoOrHclass), &callRuntime, ¬Hole); - Bind(¬Hole); + Branch(TaggedIsHeapObject(protoOrHclass), &isHeapObject, &callRuntime); + Bind(&isHeapObject); Branch(IsJSHClass(protoOrHclass), &checkJSObject, &callRuntime); Bind(&checkJSObject); auto objectType = GetObjectType(protoOrHclass); @@ -409,14 +409,14 @@ DECLARE_ASM_HANDLER(HandleNewObjDynRangePrefImm16V8) PtrAdd(firstArgRegIdx, firstArgOffset), IntPtr(8))); // 8: skip function&this res = JSCallDispatch(glue, ctor, actualNumArgs, JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV, - { actualNumArgs, argv, *thisObj }); + { ChangeInt32ToIntPtr(actualNumArgs), argv, *thisObj }); Jump(&threadCheck); } Bind(&slowPath); GateRef firstArgIdx = Int16Add(firstArgRegIdx, firstArgOffset); GateRef length = Int16Sub(numArgs, firstArgOffset); res = CallRuntime(glue, RTSTUB_ID(NewObjDynRange), - { ctor, ctor, Int16BuildTaggedTypeWithNoGC(firstArgIdx), Int16BuildTaggedTypeWithNoGC(length) }); + { ctor, ctor, Int16ToTaggedTypeNGC(firstArgIdx), Int16ToTaggedTypeNGC(length) }); Jump(&checkResult); Bind(&checkResult); { @@ -472,7 +472,7 @@ DECLARE_ASM_HANDLER(HandleDefineFuncDynPrefId16Imm16V8) Bind(&defaultLabel); { GateRef hClass = LoadHClass(*result); - SetPropertyInlinedProps(glue, *result, hClass, Int16BuildTaggedWithNoGC(length), + SetPropertyInlinedProps(glue, *result, hClass, Int16ToTaggedNGC(length), Int32(JSFunction::LENGTH_INLINE_PROPERTY_INDEX), VariableType::INT64()); GateRef envHandle = GetVregValue(sp, ZExtInt8ToPtr(v0)); SetLexicalEnvToFunction(glue, *result, envHandle); @@ -520,7 +520,7 @@ DECLARE_ASM_HANDLER(HandleDefineNCFuncDynPrefId16Imm16V8) Bind(&defaultLabel); { GateRef hClass = LoadHClass(*result); - SetPropertyInlinedProps(glue, *result, hClass, Int16BuildTaggedWithNoGC(length), + SetPropertyInlinedProps(glue, *result, hClass, Int16ToTaggedNGC(length), Int32(JSFunction::LENGTH_INLINE_PROPERTY_INDEX), VariableType::INT64()); GateRef lexEnv = GetVregValue(sp, ZExtInt8ToPtr(v0)); SetLexicalEnvToFunction(glue, *result, lexEnv); @@ -569,7 +569,7 @@ DECLARE_ASM_HANDLER(HandleDefineGeneratorFuncPrefId16Imm16V8) Bind(&defaultLabel); { GateRef hClass = LoadHClass(*result); - SetPropertyInlinedProps(glue, *result, hClass, Int16BuildTaggedWithNoGC(length), + SetPropertyInlinedProps(glue, *result, hClass, Int16ToTaggedNGC(length), Int32(JSFunction::LENGTH_INLINE_PROPERTY_INDEX), VariableType::INT64()); GateRef lexEnv = GetVregValue(sp, ZExtInt8ToPtr(v0)); SetLexicalEnvToFunction(glue, *result, lexEnv); @@ -617,7 +617,7 @@ DECLARE_ASM_HANDLER(HandleDefineAsyncFuncPrefId16Imm16V8) Bind(&defaultLabel); { GateRef hClass = LoadHClass(*result); - SetPropertyInlinedProps(glue, *result, hClass, Int16BuildTaggedWithNoGC(length), + SetPropertyInlinedProps(glue, *result, hClass, Int16ToTaggedNGC(length), Int32(JSFunction::LENGTH_INLINE_PROPERTY_INDEX), VariableType::INT64()); GateRef lexEnv = GetVregValue(sp, ZExtInt8ToPtr(v0)); SetLexicalEnvToFunction(glue, *result, lexEnv); @@ -666,7 +666,7 @@ DECLARE_ASM_HANDLER(HandleDefineMethodPrefId16Imm16V8) Bind(&defaultLabel); { GateRef hClass = LoadHClass(*result); - SetPropertyInlinedProps(glue, *result, hClass, Int16BuildTaggedWithNoGC(length), + SetPropertyInlinedProps(glue, *result, hClass, Int16ToTaggedNGC(length), Int32(JSFunction::LENGTH_INLINE_PROPERTY_INDEX), VariableType::INT64()); GateRef lexEnv = GetVregValue(sp, ZExtInt8ToPtr(v0)); SetLexicalEnvToFunction(glue, *result, lexEnv); @@ -775,7 +775,7 @@ DECLARE_ASM_HANDLER(HandleSuperCallPrefImm16V8) GateRef v0 = ZExtInt8ToInt16(ReadInst8_3(pc)); // acc is thisFunc GateRef res = CallRuntime(glue, RTSTUB_ID(SuperCall), - { acc, Int16BuildTaggedTypeWithNoGC(v0), Int16BuildTaggedTypeWithNoGC(range) }); + { acc, Int16ToTaggedTypeNGC(v0), Int16ToTaggedTypeNGC(range) }); Label isException(env); Label notException(env); Branch(TaggedIsException(res), &isException, ¬Exception); @@ -1545,10 +1545,11 @@ DECLARE_ASM_HANDLER(SingleStepDebugging) DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc); DEFVARIABLE(varHotnessCounter, VariableType::INT32(), hotnessCounter); + GateRef currentSp = *varSp; varSp = TaggedCastToIntPtr(CallRuntime(glue, RTSTUB_ID(JumpToCInterpreter), { constpool, profileTypeInfo, acc, - IntBuildTaggedTypeWithNoGC(hotnessCounter)})); + IntToTaggedTypeNGC(hotnessCounter)})); GateRef frame = GetFrame(*varSp); varPc = GetPcFromFrame(frame); Label shouldReturn(env); @@ -1557,7 +1558,7 @@ DECLARE_ASM_HANDLER(SingleStepDebugging) Branch(IntPtrEqual(*varPc, IntPtr(0)), &shouldReturn, &shouldContinue); Bind(&shouldReturn); { - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { Undefined() }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { Undefined(), *varSp, currentSp }); Return(); } Bind(&shouldContinue); @@ -1842,7 +1843,7 @@ DECLARE_ASM_HANDLER(HandleIncDynPrefV8) Branch(Int32Equal(valueInt, Int32(INT32_MAX)), &valueNotInt, &valueNoOverflow); Bind(&valueNoOverflow); { - varAcc = IntBuildTaggedWithNoGC(Int32Add(valueInt, Int32(1))); + varAcc = IntToTaggedNGC(Int32Add(valueInt, Int32(1))); Jump(&accDispatch); } } @@ -1898,7 +1899,7 @@ DECLARE_ASM_HANDLER(HandleDecDynPrefV8) Branch(Int32Equal(valueInt, Int32(INT32_MIN)), &valueNotInt, &valueNoOverflow); Bind(&valueNoOverflow); { - varAcc = IntBuildTaggedWithNoGC(Int32Sub(valueInt, Int32(1))); + varAcc = IntToTaggedNGC(Int32Sub(valueInt, Int32(1))); Jump(&accDispatch); } } @@ -2067,7 +2068,7 @@ DECLARE_ASM_HANDLER(HandleGetResumeModePrefV8) GateRef vs = ReadInst8_1(pc); GateRef obj = GetVregValue(sp, ZExtInt8ToPtr(vs)); - varAcc = IntBuildTaggedWithNoGC(GetResumeModeFromGeneratorObject(obj)); + varAcc = IntToTaggedNGC(GetResumeModeFromGeneratorObject(obj)); DISPATCH_WITH_ACC(PREF_V8); } @@ -2497,9 +2498,7 @@ DECLARE_ASM_HANDLER(HandleLdObjByValuePrefV8V8) } Bind(&tryFastPath); { - GateRef result = CallStub(glue, - CommonStubCSigns::GetPropertyByValue, - { glue, receiver, propKey }); + GateRef result = GetPropertyByValue(glue, receiver, propKey); Label notHole(env); Branch(TaggedIsHole(result), &slowPath, ¬Hole); Bind(¬Hole); @@ -2513,7 +2512,7 @@ DECLARE_ASM_HANDLER(HandleLdObjByValuePrefV8V8) Bind(&slowPath); { GateRef result = CallRuntime(glue, RTSTUB_ID(LoadICByValue), - { profileTypeInfo, receiver, propKey, IntBuildTaggedTypeWithNoGC(slotId) }); + { profileTypeInfo, receiver, propKey, IntToTaggedTypeNGC(slotId) }); Label notException(env); Branch(TaggedIsException(result), &isException, ¬Exception); Bind(¬Exception); @@ -2596,9 +2595,7 @@ DECLARE_ASM_HANDLER(HandleStObjByValuePrefV8V8) } Bind(&tryFastPath); { - GateRef result = CallStub(glue, - CommonStubCSigns::SetPropertyByValue, - { glue, receiver, propKey, acc }); // acc is value + GateRef result = SetPropertyByValue(glue, receiver, propKey, acc, false); Label notHole(env); Branch(TaggedIsHole(result), &slowPath, ¬Hole); Bind(¬Hole); @@ -2608,7 +2605,7 @@ DECLARE_ASM_HANDLER(HandleStObjByValuePrefV8V8) Bind(&slowPath); { GateRef result = CallRuntime(glue, RTSTUB_ID(StoreICByValue), - { profileTypeInfo, receiver, propKey, acc, IntBuildTaggedTypeWithNoGC(slotId) }); + { profileTypeInfo, receiver, propKey, acc, IntToTaggedTypeNGC(slotId) }); Branch(TaggedIsException(result), &isException, ¬Exception); } Bind(&isException); @@ -2641,8 +2638,7 @@ DECLARE_ASM_HANDLER(HandleStOwnByValuePrefV8V8) Bind(¬ClassPrototype); { // fast path - GateRef result = CallStub(glue, CommonStubCSigns::SetPropertyByValueWithOwn, - { glue, receiver, propKey, acc }); // acc is value + GateRef result = SetPropertyByValue(glue, receiver, propKey, acc, true); // acc is value Label notHole(env); Branch(TaggedIsHole(result), &slowPath, ¬Hole); Bind(¬Hole); @@ -2763,8 +2759,7 @@ DECLARE_ASM_HANDLER(HandleLdObjByIndexPrefV8Imm32) Branch(TaggedIsHeapObject(receiver), &fastPath, &slowPath); Bind(&fastPath); { - GateRef result = CallStub(glue, CommonStubCSigns::GetPropertyByIndex, - { glue, receiver, index }); + GateRef result = GetPropertyByIndex(glue, receiver, index); Label notHole(env); Branch(TaggedIsHole(result), &slowPath, ¬Hole); Bind(¬Hole); @@ -2777,7 +2772,7 @@ DECLARE_ASM_HANDLER(HandleLdObjByIndexPrefV8Imm32) Bind(&slowPath); { GateRef result = CallRuntime(glue, RTSTUB_ID(LdObjByIndex), - { receiver, IntBuildTaggedTypeWithNoGC(index), TaggedFalse(), Undefined() }); + { receiver, IntToTaggedTypeNGC(index), TaggedFalse(), Undefined() }); Label notException(env); Branch(TaggedIsException(result), &isException, ¬Exception); Bind(¬Exception); @@ -2806,8 +2801,7 @@ DECLARE_ASM_HANDLER(HandleStObjByIndexPrefV8Imm32) Branch(TaggedIsHeapObject(receiver), &fastPath, &slowPath); Bind(&fastPath); { - GateRef result = CallStub(glue, CommonStubCSigns::SetPropertyByIndex, - { glue, receiver, index, acc }); // acc is value + GateRef result = SetPropertyByIndex(glue, receiver, index, acc, false); Label notHole(env); Branch(TaggedIsHole(result), &slowPath, ¬Hole); Bind(¬Hole); @@ -2816,7 +2810,7 @@ DECLARE_ASM_HANDLER(HandleStObjByIndexPrefV8Imm32) Bind(&slowPath); { GateRef result = CallRuntime(glue, RTSTUB_ID(StObjByIndex), - { receiver, IntBuildTaggedTypeWithNoGC(index), acc }); + { receiver, IntToTaggedTypeNGC(index), acc }); Branch(TaggedIsException(result), &isException, ¬Exception); } Bind(&isException); @@ -2848,8 +2842,7 @@ DECLARE_ASM_HANDLER(HandleStOwnByIndexPrefV8Imm32) Bind(¬ClassPrototype); { // fast path - GateRef result = CallStub(glue, CommonStubCSigns::SetPropertyByIndexWithOwn, - { glue, receiver, index, acc }); // acc is value + GateRef result = SetPropertyByIndex(glue, receiver, index, acc, true); // acc is value Label notHole(env); Branch(TaggedIsHole(result), &slowPath, ¬Hole); Bind(¬Hole); @@ -2858,7 +2851,7 @@ DECLARE_ASM_HANDLER(HandleStOwnByIndexPrefV8Imm32) Bind(&slowPath); { GateRef result = CallRuntime(glue, RTSTUB_ID(StOwnByIndex), - { receiver, IntBuildTaggedTypeWithNoGC(index), acc }); + { receiver, IntToTaggedTypeNGC(index), acc }); Branch(TaggedIsException(result), &isException, ¬Exception); } Bind(&isException); @@ -2954,7 +2947,7 @@ DECLARE_ASM_HANDLER(HandleNegDynPrefV8) } Bind(&valueNotZero); { - varAcc = IntBuildTaggedWithNoGC(Int32Sub(Int32(0), valueInt)); + varAcc = IntToTaggedNGC(Int32Sub(Int32(0), valueInt)); Jump(&accDispatch); } } @@ -3005,7 +2998,7 @@ DECLARE_ASM_HANDLER(HandleNotDynPrefV8) Bind(&numberIsInt); { number = TaggedCastToInt32(value); - varAcc = IntBuildTaggedWithNoGC(Int32Not(*number)); + varAcc = IntToTaggedNGC(Int32Not(*number)); Jump(&accDispatch); } Bind(&numberNotInt); @@ -3017,7 +3010,7 @@ DECLARE_ASM_HANDLER(HandleNotDynPrefV8) { GateRef valueDouble = TaggedCastToDouble(value); number = DoubleToInt(glue, valueDouble); - varAcc = IntBuildTaggedWithNoGC(Int32Not(*number)); + varAcc = IntToTaggedNGC(Int32Not(*number)); Jump(&accDispatch); } Bind(&numberNotDouble); @@ -3127,7 +3120,7 @@ DECLARE_ASM_HANDLER(HandleAnd2DynPrefV8) Bind(&accDispatch); { GateRef ret = Int32And(*opNumber0, *opNumber1); - varAcc = IntBuildTaggedWithNoGC(ret); + varAcc = IntToTaggedNGC(ret); DISPATCH_WITH_ACC(PREF_V8); } } @@ -3218,7 +3211,7 @@ DECLARE_ASM_HANDLER(HandleOr2DynPrefV8) Bind(&accDispatch); { GateRef ret = Int32Or(*opNumber0, *opNumber1); - varAcc = IntBuildTaggedWithNoGC(ret); + varAcc = IntToTaggedNGC(ret); DISPATCH_WITH_ACC(PREF_V8); } } @@ -3309,7 +3302,7 @@ DECLARE_ASM_HANDLER(HandleXOr2DynPrefV8) Bind(&accDispatch); { GateRef ret = Int32Xor(*opNumber0, *opNumber1); - varAcc = IntBuildTaggedWithNoGC(ret); + varAcc = IntToTaggedNGC(ret); DISPATCH_WITH_ACC(PREF_V8); } } @@ -3401,7 +3394,7 @@ DECLARE_ASM_HANDLER(HandleAshr2DynPrefV8) { GateRef shift = Int32And(*opNumber1, Int32(0x1f)); GateRef ret = Int32ASR(*opNumber0, shift); - varAcc = IntBuildTaggedWithNoGC(ret); + varAcc = IntToTaggedNGC(ret); DISPATCH_WITH_ACC(PREF_V8); } } @@ -3505,7 +3498,7 @@ DECLARE_ASM_HANDLER(HandleShr2DynPrefV8) } Bind(¬Overflow); { - varAcc = IntBuildTaggedWithNoGC(ret); + varAcc = IntToTaggedNGC(ret); Jump(&accDispatch); } } @@ -3602,7 +3595,7 @@ DECLARE_ASM_HANDLER(HandleShl2DynPrefV8) { GateRef shift = Int32And(*opNumber1, Int32(0x1f)); GateRef ret = Int32LSL(*opNumber0, shift); - varAcc = IntBuildTaggedWithNoGC(ret); + varAcc = IntToTaggedNGC(ret); DISPATCH_WITH_ACC(PREF_V8); } } @@ -3651,7 +3644,7 @@ DECLARE_ASM_HANDLER(HandleDefineClassWithBufferPrefId16Imm16Imm16V8V8) Bind(&isNotException); GateRef newLexicalEnv = GetVregValue(sp, ZExtInt8ToPtr(v0)); // slow runtime may gc SetLexicalEnvToFunction(glue, *res, newLexicalEnv); - CallRuntime(glue, RTSTUB_ID(SetClassConstructorLength), { *res, Int16BuildTaggedTypeWithNoGC(length) }); + CallRuntime(glue, RTSTUB_ID(SetClassConstructorLength), { *res, Int16ToTaggedTypeNGC(length) }); varAcc = *res; DISPATCH_WITH_ACC(PREF_ID16_IMM16_IMM16_V8_V8); } @@ -3734,7 +3727,7 @@ DECLARE_ASM_HANDLER(HandleLdObjByNamePrefId32V8) GateRef stringId = ReadInst32_1(pc); GateRef propKey = GetValueFromTaggedArray(VariableType::JS_ANY(), constpool, stringId); result = CallRuntime(glue, RTSTUB_ID(LoadICByName), - { profileTypeInfo, receiver, propKey, IntBuildTaggedTypeWithNoGC(slotId) }); + { profileTypeInfo, receiver, propKey, IntToTaggedTypeNGC(slotId) }); Branch(TaggedIsException(*result), &isException, &noException); Bind(&isException); { @@ -3803,9 +3796,7 @@ DECLARE_ASM_HANDLER(HandleStObjByNamePrefId32V8) { GateRef stringId = ReadInst32_1(pc); GateRef propKey = GetValueFromTaggedArray(VariableType::JS_ANY(), constpool, stringId); - result = CallStub(glue, CommonStubCSigns::SetPropertyByName, { - glue, receiver, propKey, acc - }); + result = SetPropertyByName(glue, receiver, propKey, acc, false); Branch(TaggedIsHole(*result), &slowPath, &checkResult); } } @@ -3815,7 +3806,7 @@ DECLARE_ASM_HANDLER(HandleStObjByNamePrefId32V8) GateRef propKey = GetValueFromTaggedArray(VariableType::JS_ANY(), constpool, stringId); result = ChangeTaggedPointerToInt64(CallRuntime(glue, RTSTUB_ID(StoreICByName), { profileTypeInfo, receiver, propKey, acc, - IntBuildTaggedTypeWithNoGC(slotId) })); + IntToTaggedTypeNGC(slotId) })); Jump(&checkResult); } Bind(&checkResult); @@ -3855,9 +3846,7 @@ DECLARE_ASM_HANDLER(HandleStOwnByValueWithNameSetPrefV8V8) Branch(IsClassPrototype(receiver), &slowPath, ¬ClassPrototype); Bind(¬ClassPrototype); { - GateRef res = CallStub(glue, - CommonStubCSigns::SetPropertyByValueWithOwn, - { glue, receiver, propKey, acc }); + GateRef res = SetPropertyByValue(glue, receiver, propKey, acc, true); Branch(TaggedIsHole(res), &slowPath, ¬Hole); Bind(¬Hole); { @@ -3909,8 +3898,7 @@ DECLARE_ASM_HANDLER(HandleStOwnByNamePrefId32V8) Branch(IsClassPrototype(receiver), &slowPath, &fastPath); Bind(&fastPath); { - result = CallStub(glue, CommonStubCSigns::SetPropertyByNameWithOwn, - { glue, receiver, propKey, acc }); + result = SetPropertyByName(glue, receiver, propKey, acc, true); Branch(TaggedIsHole(*result), &slowPath, &checkResult); } } @@ -3957,8 +3945,7 @@ DECLARE_ASM_HANDLER(HandleStOwnByNameWithNameSetPrefId32V8) Branch(IsClassPrototype(receiver), ¬JSObject, ¬ClassPrototype); Bind(¬ClassPrototype); { - GateRef res = CallStub(glue, CommonStubCSigns::SetPropertyByNameWithOwn, - { glue, receiver, propKey, acc }); + GateRef res = SetPropertyByName(glue, receiver, propKey, acc, true); Branch(TaggedIsHole(res), ¬JSObject, ¬Hole); Bind(¬Hole); { @@ -4032,7 +4019,7 @@ DECLARE_ASM_HANDLER(HandleLdaiDynImm32) DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc); GateRef imm = ReadInst32_0(pc); - varAcc = IntBuildTaggedWithNoGC(imm); + varAcc = IntToTaggedNGC(imm); DISPATCH_WITH_ACC(IMM32); } @@ -4257,7 +4244,7 @@ DECLARE_ASM_HANDLER(HandleReturnDyn) Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr); Bind(&pcEqualNullptr); { - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc, *varSp, currentSp }); Return(); } Bind(&pcNotEqualNullptr); @@ -4318,7 +4305,7 @@ DECLARE_ASM_HANDLER(HandleReturnUndefinedPref) Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr); Bind(&pcEqualNullptr); { - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc, *varSp, currentSp }); Return(); } Bind(&pcNotEqualNullptr); @@ -4390,7 +4377,7 @@ DECLARE_ASM_HANDLER(HandleSuspendGeneratorPrefV8V8) Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcEqualNullptr, &pcNotEqualNullptr); Bind(&pcEqualNullptr); { - CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeRspAndReturn), { *varAcc, *varSp, currentSp }); Return(); } Bind(&pcNotEqualNullptr); @@ -4424,18 +4411,18 @@ DECLARE_ASM_HANDLER(ExceptionHandler) GateRef exceptionOffset = IntPtr(JSThread::GlueData::GetExceptionOffset(env->IsArch32Bit())); GateRef exception = Load(VariableType::JS_ANY(), glue, exceptionOffset); varPc = TaggedCastToIntPtr(CallRuntime(glue, RTSTUB_ID(UpFrame), {})); + varSp = GetCurrentFrame(glue); Branch(IntPtrEqual(*varPc, IntPtr(0)), &pcIsInvalid, &pcNotInvalid); Bind(&pcIsInvalid); { - CallNGCRuntime(glue, RTSTUB_ID(ResumeUncaughtFrameAndReturn), { glue }); + CallNGCRuntime(glue, RTSTUB_ID(ResumeUncaughtFrameAndReturn), { glue, *varSp, *varAcc }); Return(); } Bind(&pcNotInvalid); { - varSp = GetCurrentFrame(glue); varAcc = exception; // clear exception - Store(VariableType::INT64(), glue, glue, IntPtr(0), Hole()); + Store(VariableType::INT64(), glue, glue, exceptionOffset, Hole()); GateRef function = GetFunctionFromFrame(GetFrame(*varSp)); varConstpool = GetConstpoolFromFunction(function); varProfileTypeInfo = GetProfileTypeInfoFromFunction(function); @@ -4478,7 +4465,7 @@ DECLARE_ASM_HANDLER(HandleLdModuleVarPrefId32Imm8) GateRef flag = ReadInst8_5(pc); GateRef key = GetObjectFromConstPool(constpool, stringId); GateRef innerFlag = ZExtInt8ToInt32(flag); - GateRef moduleVar = CallRuntime(glue, RTSTUB_ID(LdModuleVar), { key, IntBuildTaggedTypeWithNoGC(innerFlag) }); + GateRef moduleVar = CallRuntime(glue, RTSTUB_ID(LdModuleVar), { key, IntToTaggedTypeNGC(innerFlag) }); varAcc = moduleVar; DISPATCH_WITH_ACC(PREF_ID32_IMM8); } @@ -4501,20 +4488,25 @@ DECLARE_ASM_HANDLER(HandleTryLdGlobalByNamePrefId32) GateRef slotId = ZExtInt8ToInt32(ReadInst8_0(pc)); GateRef handler = GetValueFromTaggedArray(VariableType::JS_ANY(), profileTypeInfo, slotId); Label isHeapObject(env); + Label notHeapObject(env); Label ldMiss(env); Label icResultCheck(env); - Branch(TaggedIsHeapObject(handler), &isHeapObject, &ldMiss); + Branch(TaggedIsHeapObject(handler), &isHeapObject, ¬HeapObject); Bind(&isHeapObject); { icResult = LoadGlobal(handler); Branch(TaggedIsHole(*icResult), &ldMiss, &icResultCheck); } + Bind(¬HeapObject); + { + Branch(TaggedIsHole(handler), &icNotAvailable, &ldMiss); + } Bind(&ldMiss); { GateRef globalObject = GetGlobalObject(glue); icResult = CallRuntime(glue, RTSTUB_ID(LoadMiss), - { profileTypeInfo, globalObject, prop, IntBuildTaggedTypeWithNoGC(slotId), - IntBuildTaggedTypeWithNoGC(Int32(static_cast(ICKind::NamedGlobalLoadIC))) }); + { profileTypeInfo, globalObject, prop, IntToTaggedTypeNGC(slotId), + IntToTaggedTypeNGC(Int32(static_cast(ICKind::NamedGlobalLoadIC))) }); Jump(&icResultCheck); } Bind(&icResultCheck); @@ -4604,8 +4596,8 @@ DECLARE_ASM_HANDLER(HandleTryStGlobalByNamePrefId32) { GateRef globalObject = GetGlobalObject(glue); result = CallRuntime(glue, RTSTUB_ID(StoreMiss), - { profileTypeInfo, globalObject, propKey, acc, IntBuildTaggedTypeWithNoGC(slotId), - IntBuildTaggedTypeWithNoGC(Int32(static_cast(ICKind::NamedGlobalStoreIC))) }); + { profileTypeInfo, globalObject, propKey, acc, IntToTaggedTypeNGC(slotId), + IntToTaggedTypeNGC(Int32(static_cast(ICKind::NamedGlobalStoreIC))) }); Jump(&checkResult); } } @@ -4672,18 +4664,23 @@ DECLARE_ASM_HANDLER(HandleLdGlobalVarPrefId32) GateRef slotId = ZExtInt8ToInt32(ReadInst8_0(pc)); GateRef handler = GetValueFromTaggedArray(VariableType::JS_ANY(), profileTypeInfo, slotId); Label isHeapObject(env); + Label notHeapObject(env); Label ldMiss(env); - Branch(TaggedIsHeapObject(handler), &isHeapObject, &ldMiss); + Branch(TaggedIsHeapObject(handler), &isHeapObject, ¬HeapObject); Bind(&isHeapObject); { result = LoadGlobal(handler); Branch(TaggedIsHole(*result), &ldMiss, &checkResult); } + Bind(¬HeapObject); + { + Branch(TaggedIsHole(handler), &icNotAvailable, &ldMiss); + } Bind(&ldMiss); { result = CallRuntime(glue, RTSTUB_ID(LoadMiss), - { profileTypeInfo, globalObject, propKey, IntBuildTaggedTypeWithNoGC(slotId), - IntBuildTaggedTypeWithNoGC(Int32(static_cast(ICKind::NamedGlobalLoadIC))) }); + { profileTypeInfo, globalObject, propKey, IntToTaggedTypeNGC(slotId), + IntToTaggedTypeNGC(Int32(static_cast(ICKind::NamedGlobalLoadIC))) }); Jump(&checkResult); } } @@ -4741,8 +4738,8 @@ DECLARE_ASM_HANDLER(HandleStGlobalVarPrefId32) { GateRef globalObject = GetGlobalObject(glue); result = CallRuntime(glue, RTSTUB_ID(StoreMiss), - { profileTypeInfo, globalObject, propKey, acc, IntBuildTaggedTypeWithNoGC(slotId), - IntBuildTaggedTypeWithNoGC(Int32(static_cast(ICKind::NamedGlobalStoreIC))) }); + { profileTypeInfo, globalObject, propKey, acc, IntToTaggedTypeNGC(slotId), + IntToTaggedTypeNGC(Int32(static_cast(ICKind::NamedGlobalStoreIC))) }); Jump(&checkResult); } } @@ -4772,7 +4769,7 @@ DECLARE_ASM_HANDLER(HandleCreateRegExpWithLiteralPrefId32Imm8) GateRef pattern = GetObjectFromConstPool(constpool, stringId); GateRef flags = ReadInst8_5(pc); GateRef res = CallRuntime(glue, RTSTUB_ID(CreateRegExpWithLiteral), - { pattern, Int8BuildTaggedTypeWithNoGC(flags) }); + { pattern, Int8ToTaggedTypeNGC(flags) }); Label isException(env); Label notException(env); Branch(TaggedIsException(res), &isException, ¬Exception); @@ -5095,7 +5092,7 @@ DECLARE_ASM_HANDLER(HandleNewLexEnvWithNameDynPrefImm16Imm16) GateRef numVars = ReadInst16_1(pc); GateRef scopeId = ReadInst16_3(pc); GateRef res = CallRuntime(glue, RTSTUB_ID(NewLexicalEnvWithNameDyn), - { Int16BuildTaggedTypeWithNoGC(numVars), Int16BuildTaggedTypeWithNoGC(scopeId) }); + { Int16ToTaggedTypeNGC(numVars), Int16ToTaggedTypeNGC(scopeId) }); Label isException(env); Label notException(env); Branch(TaggedIsException(res), &isException, ¬Exception); @@ -5110,48 +5107,6 @@ DECLARE_ASM_HANDLER(HandleNewLexEnvWithNameDynPrefImm16Imm16) DISPATCH_WITH_ACC(PREF_IMM16_IMM16); } -DECLARE_ASM_HANDLER(NewObjectDynRangeReturn) -{ - auto env = GetEnvironment(); - DEFVARIABLE(varAcc, VariableType::JS_ANY(), acc); - - Label isHeapObject(env); - Label isEcmaObject(env); - Label notEcmaObject(env); - Label throwError(env); - Label returnObject(env); - Label dispatch(env); - - auto frame = GetFrame(sp); - auto newSp = Load(VariableType::NATIVE_POINTER(), frame, IntPtr(AsmInterpretedFrame::GetBaseOffset(env->IsArch32Bit()))); - - Branch(TaggedIsHeapObject(*varAcc), &isHeapObject, ¬EcmaObject); - Bind(&isHeapObject); - Branch(TaggedObjectIsEcmaObject(*varAcc), &dispatch, ¬EcmaObject); - Bind(¬EcmaObject); - { - // default acc is not undefined - auto constructor = GetFunctionFromFrame(frame); - Branch(IsBase(constructor), &returnObject, &throwError); - Bind(&throwError); - { - CallRuntime(glue, RTSTUB_ID(ThrowDerivedMustReturnException), {}); - DispatchLast(glue, newSp, pc, constpool, profileTypeInfo, acc, hotnessCounter); - } - Bind(&returnObject); - { - auto fp = Load(VariableType::JS_POINTER(), frame, - IntPtr(AsmInterpretedFrame::GetFpOffset(GetEnvironment()->IsArch32Bit()))); - auto thisObj = GetThisObjectFromFastNewFrame(fp); - varAcc = thisObj; - Jump(&dispatch); - } - } - Bind(&dispatch); - Dispatch(glue, newSp, pc, constpool, profileTypeInfo, *varAcc, hotnessCounter, - IntPtr(BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_IMM16_V8))); -} - DECLARE_ASM_HANDLER(InterpreterGetPropertyByName) { auto env = GetEnvironment(); @@ -5173,7 +5128,7 @@ DECLARE_ASM_HANDLER(InterpreterGetPropertyByName) { GateRef slotId = ZExtInt8ToInt32(ReadInst8_0(pc)); result = CallRuntime(glue, RTSTUB_ID(LoadICByName), - { profileTypeInfo, receiver, propKey, IntBuildTaggedTypeWithNoGC(slotId) }); + { profileTypeInfo, receiver, propKey, IntToTaggedTypeNGC(slotId) }); Jump(&checkResult); } Bind(&checkResult); @@ -5188,6 +5143,12 @@ DECLARE_ASM_HANDLER(InterpreterGetPropertyByName) varAcc = *result; DISPATCH_WITH_ACC(PREF_ID32_V8); } + +DECLARE_ASM_HANDLER(NewObjectDynRangeThrowException) +{ + CallRuntime(glue, RTSTUB_ID(ThrowDerivedMustReturnException), {}); + DISPATCH_LAST(); +} #undef DECLARE_ASM_HANDLER #undef DISPATCH #undef DISPATCH_WITH_ACC diff --git a/ecmascript/compiler/llvm_codegen.cpp b/ecmascript/compiler/llvm_codegen.cpp index 8d33f378a21ead9e2bb750e75267ef767f86c4b0..4898c19e08745a2dce9df1bb95e3ca798c996ac1 100644 --- a/ecmascript/compiler/llvm_codegen.cpp +++ b/ecmascript/compiler/llvm_codegen.cpp @@ -35,6 +35,7 @@ #endif #include "ecmascript/compiler/call_signature.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "llvm-c/Analysis.h" #include "llvm-c/Core.h" #include "llvm-c/Disassembler.h" @@ -64,7 +65,6 @@ #include "llvm/Support/Host.h" #include "llvm/Support/TargetSelect.h" #include "llvm/Transforms/Scalar.h" -#include "llvm/llvm_stackmap_parser.h" #if defined(__clang__) #pragma clang diagnostic pop @@ -131,7 +131,7 @@ bool LLVMAssembler::BuildMCJITEngine() { LLVMBool ret = LLVMCreateMCJITCompilerForModule(&engine_, module_, &options_, sizeof(options_), &error_); if (ret) { - COMPILER_LOG(FATAL) << "error_ : " << error_; + LOG_COMPILER(FATAL) << "error_ : " << error_; return false; } return true; @@ -261,7 +261,7 @@ int LLVMAssembler::GetFpDeltaPrevFramSp(LLVMValueRef fn, const CompilerLog &log) fpToCallerSpDelta = atoi(value); if (log.IsAlwaysEnabled()) { size_t length; - COMPILER_LOG(INFO) << " funcName: " << LLVMGetValueName2(fn, &length) << " fpToCallerSpDelta:" + LOG_COMPILER(INFO) << " funcName: " << LLVMGetValueName2(fn, &length) << " fpToCallerSpDelta:" << fpToCallerSpDelta; } } @@ -272,6 +272,7 @@ void LLVMAssembler::Disassemble(const std::map &addr2nam { LLVMDisasmContextRef dcr = LLVMCreateDisasm(LLVMGetTarget(module_), nullptr, 0, nullptr, SymbolLookupCallback); bool logFlag = false; + unsigned pc = 0; for (auto it : codeInfo_.GetCodeInfo()) { uint8_t *byteSp; @@ -279,7 +280,6 @@ void LLVMAssembler::Disassemble(const std::map &addr2nam byteSp = it.first; numBytes = it.second; - unsigned pc = 0; const char outStringSize = 100; char outString[outStringSize]; std::string methodName; @@ -288,16 +288,16 @@ void LLVMAssembler::Disassemble(const std::map &addr2nam if (addr2name.find(addr) != addr2name.end()) { methodName = addr2name.at(addr); if (logFlag) { - COMPILER_LOG(INFO) << "======================================================================="; - COMPILER_LOG(INFO) << methodName.c_str() << " disassemble:"; + LOG_COMPILER(INFO) << "======================================================================="; + LOG_COMPILER(INFO) << methodName.c_str() << " disassemble:"; } } - logFlag = log.IsAlwaysEnabled() ? true : log.IncludesMethod(methodName); + logFlag = log.IsDisassembleEnabled() ? true : log.IncludesMethod(methodName); size_t InstSize = LLVMDisasmInstruction(dcr, byteSp, numBytes, pc, outString, outStringSize); if (InstSize == 0) { if (logFlag) { - COMPILER_LOG(INFO) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) + LOG_COMPILER(INFO) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) << *reinterpret_cast(byteSp) << "maybe constant"; } pc += 4; // 4 pc length @@ -305,7 +305,7 @@ void LLVMAssembler::Disassemble(const std::map &addr2nam numBytes -= 4; // 4 num bytes } if (logFlag) { - COMPILER_LOG(INFO) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) + LOG_COMPILER(INFO) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) << *reinterpret_cast(byteSp) << " " << outString; } pc += InstSize; @@ -330,7 +330,7 @@ void LLVMAssembler::Disassemble(uint8_t *buf, size_t size) LLVMInitializeX86Target(); LLVMDisasmContextRef dcr = LLVMCreateDisasm(LLVMGetTarget(module), nullptr, 0, nullptr, SymbolLookupCallback); if (!dcr) { - COMPILER_LOG(ERROR) << "ERROR: Couldn't create disassembler for triple!"; + LOG_COMPILER(ERROR) << "ERROR: Couldn't create disassembler for triple!"; return; } uint8_t *byteSp; @@ -343,13 +343,13 @@ void LLVMAssembler::Disassemble(uint8_t *buf, size_t size) while (numBytes > 0) { size_t InstSize = LLVMDisasmInstruction(dcr, byteSp, numBytes, pc, outString, outStringSize); if (InstSize == 0) { - COMPILER_LOG(ERROR) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) + LOG_COMPILER(ERROR) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) << *reinterpret_cast(byteSp) << "maybe constant"; pc += 4; // 4 pc length byteSp += 4; // 4 sp offset numBytes -= 4; // 4 num bytes } - COMPILER_LOG(ERROR) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) + LOG_COMPILER(ERROR) << std::setw(8) << std::setfill('0') << std::hex << pc << ":" << std::setw(8) << *reinterpret_cast(byteSp) << " " << outString; pc += InstSize; byteSp += InstSize; diff --git a/ecmascript/compiler/llvm_codegen.h b/ecmascript/compiler/llvm_codegen.h index 52fb8ae988a8d48457f28265204c52f5a4d60eca..6bf71d8b1774097a44fa632f321af2acbe0dcb20 100644 --- a/ecmascript/compiler/llvm_codegen.h +++ b/ecmascript/compiler/llvm_codegen.h @@ -40,6 +40,7 @@ #include "ecmascript/mem/machine_code.h" #include "ecmascript/mem/region.h" +#include "libpandabase/utils/asan_interface.h" #include "llvm-c/Analysis.h" #include "llvm-c/Core.h" #include "llvm-c/ExecutionEngine.h" @@ -93,7 +94,7 @@ struct CodeInfo { size = AlignUp(size, static_cast(MemAlignment::MEM_ALIGN_REGION)); uint8_t *addr = nullptr; if (codeBufferPos_ + size > MAX_MACHINE_CODE_SIZE) { - COMPILER_LOG(ERROR) << std::hex << "AllocaCodeSection failed alloc codeBufferPos_:" << codeBufferPos_ + LOG_COMPILER(ERROR) << std::hex << "AllocaCodeSection failed alloc codeBufferPos_:" << codeBufferPos_ << " size:" << size << " larger MAX_MACHINE_CODE_SIZE:" << MAX_MACHINE_CODE_SIZE; return nullptr; } diff --git a/ecmascript/compiler/llvm_ir_builder.cpp b/ecmascript/compiler/llvm_ir_builder.cpp index cdc5d96f425ffe6f12b853c62cb3f744bcff9f03..bca3111ac81e602967cab9f3d8a180f8a97f2cbc 100644 --- a/ecmascript/compiler/llvm_ir_builder.cpp +++ b/ecmascript/compiler/llvm_ir_builder.cpp @@ -19,8 +19,8 @@ #include #include +#include "ecmascript/compiler/argument_accessor.h" #include "ecmascript/compiler/bc_call_signature.h" -#include "ecmascript/compiler/bytecode_circuit_builder.h" #include "ecmascript/compiler/circuit.h" #include "ecmascript/compiler/call_signature.h" #include "ecmascript/compiler/common_stubs.h" @@ -50,7 +50,6 @@ #include "llvm/Support/Host.h" #include "securec.h" -#include "utils/logger.h" namespace panda::ecmascript::kungfu { LLVMIRBuilder::LLVMIRBuilder(const std::vector> *schedule, const Circuit *circuit, @@ -245,7 +244,7 @@ void LLVMIRBuilder::Build() continue; } if (illegalOpHandlers_.find(circuit_->GetOpCode(gate)) == illegalOpHandlers_.end()) { - COMPILER_OPTIONAL_LOG(ERROR) << "The gate below need to be translated "; + LOG_COMPILER(ERROR) << "The gate below need to be translated "; circuit_->Print(gate); UNREACHABLE(); } @@ -272,7 +271,7 @@ void LLVMIRBuilder::SetToCfg(BasicBlock *bb) const EnsureLBB(bb); BasicBlockImpl *impl = bb->GetImpl(); if ((impl == nullptr) || (impl->lBB_ == nullptr)) { - COMPILER_OPTIONAL_LOG(ERROR) << "SetToCfg failed "; + LOG_COMPILER(ERROR) << "SetToCfg failed "; return; } impl->started = true; @@ -287,12 +286,12 @@ void LLVMIRBuilder::ProcessPhiWorkList() for (auto &e : impl->unmergedPhis_) { BasicBlock *pred = e.pred; if (impl->started == 0) { - COMPILER_OPTIONAL_LOG(ERROR) << " ProcessPhiWorkList error hav't start "; + OPTIONAL_LOG_COMPILER(ERROR) << " ProcessPhiWorkList error hav't start "; return; } LLVMValueRef value = gate2LValue_[e.operand]; if (LLVMTypeOf(value) != LLVMTypeOf(e.phi)) { - COMPILER_OPTIONAL_LOG(ERROR) << " ProcessPhiWorkList LLVMTypeOf don't match error "; + OPTIONAL_LOG_COMPILER(ERROR) << " ProcessPhiWorkList LLVMTypeOf don't match error "; } LLVMBasicBlockRef llvmBB = EnsureLBB(pred); LLVMAddIncoming(e.phi, &value, &llvmBB, 1); @@ -380,7 +379,7 @@ void LLVMIRBuilder::GenPrologue([[maybe_unused]] LLVMModuleRef &module, LLVMBuil LLVMAddTargetDependentFunctionAttr(function_, "frame-reserved-slots", std::to_string(reservedSlotsSize).c_str()); } else { - COMPILER_OPTIONAL_LOG(FATAL) << "frameType interpret type error !"; + LOG_COMPILER(FATAL) << "frameType interpret type error !"; ASSERT_PRINT(static_cast(frameType), "is not support !"); } @@ -487,7 +486,7 @@ void LLVMIRBuilder::HandleCall(GateRef gate) if (callOp == OpCode::CALL || callOp == OpCode::NOGC_RUNTIME_CALL) { VisitCall(gate, ins, callOp); } else { - abort(); + UNREACHABLE(); } } @@ -857,12 +856,12 @@ void LLVMIRBuilder::VisitPhi(GateRef gate, const std::vector &srcGates) if (cnt > 0) { BasicBlock *bb = bbID2BB_[bbIdx].get(); if (bb == nullptr) { - COMPILER_OPTIONAL_LOG(ERROR) << "VisitPhi failed BasicBlock nullptr"; + OPTIONAL_LOG_COMPILER(ERROR) << "VisitPhi failed BasicBlock nullptr"; return; } BasicBlockImpl *impl = bb->GetImpl(); if (impl == nullptr) { - COMPILER_OPTIONAL_LOG(ERROR) << "VisitPhi failed impl nullptr"; + OPTIONAL_LOG_COMPILER(ERROR) << "VisitPhi failed impl nullptr"; return; } LLVMBasicBlockRef llvmBB = EnsureLBB(bb); // The llvm bb @@ -919,7 +918,7 @@ void LLVMIRBuilder::LinkToLLVMCfg(int bbId, const OperandsVector &predecessors) { BasicBlock *bb = EnsureBB(bbId); if (bb == nullptr) { - COMPILER_OPTIONAL_LOG(ERROR) << " block create failed "; + OPTIONAL_LOG_COMPILER(ERROR) << " block create failed "; return; } currentBb_ = bb; @@ -928,7 +927,7 @@ void LLVMIRBuilder::LinkToLLVMCfg(int bbId, const OperandsVector &predecessors) for (int predecessor : predecessors) { BasicBlock *pre = EnsureBB(predecessor); if (pre == nullptr) { - COMPILER_OPTIONAL_LOG(ERROR) << " block setup failed, predecessor:%d nullptr" << predecessor; + OPTIONAL_LOG_COMPILER(ERROR) << " block setup failed, predecessor:%d nullptr" << predecessor; return; } LLVMBasicBlockRef preLBB = EnsureLBB(pre); @@ -967,7 +966,7 @@ void LLVMIRBuilder::VisitGoto(int block, int bbOut) } BasicBlock *bb = EnsureBB(bbOut); if (bb == nullptr) { - COMPILER_OPTIONAL_LOG(ERROR) << " block is nullptr "; + OPTIONAL_LOG_COMPILER(ERROR) << " block is nullptr "; return; } llvm::BasicBlock *self = llvm::unwrap(EnsureLBB(bbID2BB_[block].get())); @@ -1013,7 +1012,7 @@ void LLVMIRBuilder::VisitConstant(GateRef gate, std::bitset<64> value) // 64: bi } else if (LLVMGetTypeKind(type) == LLVMIntegerTypeKind) { // do nothing } else { - abort(); + UNREACHABLE(); } } else if (machineType == MachineType::F64) { auto doubleValue = bit_cast(value.to_ullong()); // actual double value @@ -1025,7 +1024,7 @@ void LLVMIRBuilder::VisitConstant(GateRef gate, std::bitset<64> value) // 64: bi } else if (machineType == MachineType::I1) { llvmValue = LLVMConstInt(LLVMInt1Type(), value.to_ulong(), 0); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = llvmValue; } @@ -1072,12 +1071,29 @@ void LLVMIRBuilder::VisitParameter(GateRef gate) ASSERT(LLVMTypeOf(value) == ConvertLLVMTypeFromGate(gate)); gate2LValue_[gate] = value; // NOTE: caller put args, otherwise crash - if (value == nullptr) { - COMPILER_OPTIONAL_LOG(FATAL) << "generate LLVM IR for para: " << argth << "fail"; - return; + ASSERT(value != nullptr); + + // add env slot for optimized jsfunction frame + auto frameType = circuit_->GetFrameType(); + if (frameType == panda::ecmascript::FrameType::OPTIMIZED_JS_FUNCTION_FRAME) { + if (argth == static_cast(CommonArgIdx::LEXENV)) { + SaveLexicalEnvOnFrame(value); + } } } +void LLVMIRBuilder::SaveLexicalEnvOnFrame(LLVMValueRef value) +{ + LLVMValueRef llvmFpAddr = CallingFp(module_, builder_, false); + LLVMValueRef frameAddr = LLVMBuildPtrToInt(builder_, llvmFpAddr, slotType_, "cast_int_t"); + LLVMValueRef frameEnvSlotAddr = LLVMBuildSub(builder_, frameAddr, LLVMConstInt(slotType_, + static_cast(ReservedSlots::OPTIMIZED_JS_FUNCTION_RESERVED_SLOT) * slotSize_, false), ""); + LLVMValueRef envAddr = LLVMBuildIntToPtr(builder_, frameEnvSlotAddr, + LLVMPointerType(slotType_, 0), "env.Addr"); + LLVMValueRef envValue = LLVMBuildPtrToInt(builder_, value, slotType_, "cast_to_i64"); + LLVMBuildStore(builder_, envValue, envAddr); +} + void LLVMIRBuilder::HandleBranch(GateRef gate) { std::vector ins = circuit_->GetInVector(gate); @@ -1109,7 +1125,7 @@ void LLVMIRBuilder::VisitMod(GateRef gate, GateRef e1, GateRef e2) } else if (machineType == MachineType::F64) { result = LLVMBuildFRem(builder_, e1Value, e2Value, ""); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = result; } @@ -1117,7 +1133,7 @@ void LLVMIRBuilder::VisitMod(GateRef gate, GateRef e1, GateRef e2) void LLVMIRBuilder::VisitBranch(GateRef gate, GateRef cmp, int btrue, int bfalse) { if (gate2LValue_.count(cmp) == 0) { - COMPILER_OPTIONAL_LOG(ERROR) << "Branch condition gate is nullptr!"; + OPTIONAL_LOG_COMPILER(ERROR) << "Branch condition gate is nullptr!"; return; } LLVMValueRef cond = gate2LValue_[cmp]; @@ -1208,8 +1224,8 @@ LLVMValueRef LLVMIRBuilder::CanonicalizeToInt(LLVMValueRef value) } else if (LLVMGetTypeKind(LLVMTypeOf(value)) == LLVMIntegerTypeKind) { return value; } else { - COMPILER_OPTIONAL_LOG(ERROR) << "can't Canonicalize to Int64: "; - abort(); + LOG_COMPILER(ERROR) << "can't Canonicalize to Int64: "; + UNREACHABLE(); } } @@ -1225,8 +1241,8 @@ LLVMValueRef LLVMIRBuilder::CanonicalizeToPtr(LLVMValueRef value) LLVMValueRef tmp = LLVMBuildIntToPtr(builder_, value, LLVMPointerType(LLVMInt64Type(), 0), ""); return LLVMBuildPointerCast(builder_, tmp, LLVMPointerType(LLVMInt8Type(), 0), ""); } else { - COMPILER_OPTIONAL_LOG(ERROR) << "can't Canonicalize to Ptr: "; - abort(); + LOG_COMPILER(ERROR) << "can't Canonicalize to Ptr: "; + UNREACHABLE(); } } @@ -1245,7 +1261,7 @@ void LLVMIRBuilder::VisitIntRev(GateRef gate, GateRef e1) if (machineType <= MachineType::I64 && machineType >= MachineType::I1) { result = LLVMBuildNot(builder_, e1Value, ""); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = result; } @@ -1308,7 +1324,7 @@ LLVMTypeRef LLVMIRBuilder::ConvertLLVMTypeFromGate(GateRef gate) const } } default: - abort(); + UNREACHABLE(); } } @@ -1335,9 +1351,9 @@ int64_t LLVMIRBuilder::GetBitWidthFromMachineType(MachineType machineType) const return 64; // 64: bit width case FLEX: case ANYVALUE: - abort(); + UNREACHABLE(); default: - abort(); + UNREACHABLE(); } } @@ -1390,7 +1406,7 @@ void LLVMIRBuilder::VisitAdd(GateRef gate, GateRef e1, GateRef e2) } else if (machineType == MachineType::F64) { result = LLVMBuildFAdd(builder_, e1Value, e2Value, ""); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = result; } @@ -1414,7 +1430,7 @@ void LLVMIRBuilder::VisitSub(GateRef gate, GateRef e1, GateRef e2) } else if (machineType == MachineType::F64) { result = LLVMBuildFSub(builder_, e1Value, e2Value, ""); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = result; } @@ -1449,7 +1465,7 @@ void LLVMIRBuilder::VisitMul(GateRef gate, GateRef e1, GateRef e2) } else if (machineType == MachineType::F64) { result = LLVMBuildFMul(builder_, e1Value, e2Value, ""); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = result; } @@ -1576,7 +1592,7 @@ void LLVMIRBuilder::VisitCmp(GateRef gate, GateRef e1, GateRef e2) break; } default: { - abort(); + UNREACHABLE(); break; } } @@ -1587,7 +1603,7 @@ void LLVMIRBuilder::VisitCmp(GateRef gate, GateRef e1, GateRef e2) } else if (e1ValCode == MachineType::F64) { result = LLVMBuildFCmp(builder_, realOpcode, e1Value, e2Value, ""); } else { - abort(); + UNREACHABLE(); } gate2LValue_[gate] = result; } @@ -1936,22 +1952,16 @@ LLVMTypeRef LLVMModule::ConvertLLVMTypeFromVariableType(VariableType type) LLVMValueRef LLVMModule::AddFunc(const panda::ecmascript::JSMethod *method) { - VariableType retType(MachineType::I64, GateType::TaggedValue()); // possibly get it for circuit - LLVMTypeRef returnType = ConvertLLVMTypeFromVariableType(retType); - std::vector paramTys; - auto paramCount = method->GetNumArgs() + CommonArgIdx::NUM_OF_ARGS; - VariableType glueParamType(MachineType::I64, GateType::NJSValue()); - paramTys.push_back(ConvertLLVMTypeFromVariableType(glueParamType)); - VariableType actualArgc(MachineType::I32, GateType::NJSValue()); - paramTys.push_back(ConvertLLVMTypeFromVariableType(actualArgc)); - for (uint32_t i = CommonArgIdx::FUNC; i < CommonArgIdx::NUM_OF_ARGS; i++) { - VariableType paramsType(MachineType::I64, GateType::TaggedValue()); - paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType)); - } - for (uint32_t j = CommonArgIdx::NUM_OF_ARGS; j < paramCount; j++) { - VariableType paramsType(MachineType::I64, GateType::TaggedValue()); - paramTys.push_back(ConvertLLVMTypeFromVariableType(paramsType)); - } + LLVMTypeRef returnType = NewLType(MachineType::I64, GateType::TaggedValue()); // possibly get it for circuit + LLVMTypeRef glue = NewLType(MachineType::I64, GateType::NJSValue()); + LLVMTypeRef lexEnv = NewLType(MachineType::I64, GateType::TaggedValue()); + LLVMTypeRef actualArgc = NewLType(MachineType::I32, GateType::NJSValue()); + std::vector paramTys = { glue, lexEnv, actualArgc }; + auto funcIndex = static_cast(CommonArgIdx::FUNC); + auto numOfComArgs = static_cast(CommonArgIdx::NUM_OF_ARGS); + auto paramCount = method->GetNumArgs() + numOfComArgs; + auto numOfRestArgs = paramCount - funcIndex; + paramTys.insert(paramTys.end(), numOfRestArgs, NewLType(MachineType::I64, GateType::TaggedValue())); auto funcType = LLVMFunctionType(returnType, paramTys.data(), paramCount, false); // not variable args CString name = method->GetMethodName(); auto function = LLVMAddFunction(module_, name.c_str(), funcType); @@ -1959,4 +1969,10 @@ LLVMValueRef LLVMModule::AddFunc(const panda::ecmascript::JSMethod *method) SetFunction(offsetInPandaFile, function); return function; } + +LLVMTypeRef LLVMModule::NewLType(MachineType machineType, GateType gateType) +{ + VariableType vType(machineType, gateType); + return ConvertLLVMTypeFromVariableType(vType); +} } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/llvm_ir_builder.h b/ecmascript/compiler/llvm_ir_builder.h index 527e3841b210022cb524f6a06e7a3d0749360ea5..72b8790dd6a1d2b61fba301219f9d5bebc4031d4 100644 --- a/ecmascript/compiler/llvm_ir_builder.h +++ b/ecmascript/compiler/llvm_ir_builder.h @@ -169,6 +169,7 @@ private: LLVMValueRef AddAndGetFunc(const CallSignature *stubDescriptor); void InitialLLVMFuncTypeAndFuncByModuleCSigns(); LLVMTypeRef ConvertLLVMTypeFromVariableType(VariableType type); + LLVMTypeRef NewLType(MachineType machineType, GateType gateType); // index: // stub scenario - sequence of function adding to llvmModule // aot scenario - method Id of function generated by panda files @@ -305,6 +306,7 @@ private: bool NeedBCOffset(OpCode op); void ComputeArgCountAndBCOffset(size_t &actualNumArgs, LLVMValueRef &bcOffset, const std::vector &inList, OpCode op); + void SaveLexicalEnvOnFrame(LLVMValueRef value); const CompilationConfig *compCfg_ {nullptr}; const std::vector> *scheduledGates_ {nullptr}; const Circuit *circuit_ {nullptr}; diff --git a/ecmascript/compiler/mock/mock_stub_m.cpp b/ecmascript/compiler/mock/mock_stub_m.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0de567b53508a94c11e7ccf3e13acc034ae8269b --- /dev/null +++ b/ecmascript/compiler/mock/mock_stub_m.cpp @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include +extern const uint8_t _binary_stub_m_start[1] = {0x0}; +extern const uint32_t _binary_stub_m_length = 1; \ No newline at end of file diff --git a/ecmascript/compiler/pass.h b/ecmascript/compiler/pass.h index 8d8ed76de1f3ea5e7916a5a087f31db4cbae1c82..ceadd2e344a5d0afdb019f36b395b5b248526a7a 100644 --- a/ecmascript/compiler/pass.h +++ b/ecmascript/compiler/pass.h @@ -16,13 +16,15 @@ #ifndef ECMASCRIPT_COMPILER_PASS_H #define ECMASCRIPT_COMPILER_PASS_H -#include "bytecode_circuit_builder.h" -#include "common_stubs.h" -#include "llvm_codegen.h" -#include "scheduler.h" -#include "slowpath_lowering.h" -#include "type_inference/type_infer.h" -#include "verifier.h" +#include "ecmascript/compiler/async_function_lowering.h" +#include "ecmascript/compiler/bytecode_circuit_builder.h" +#include "ecmascript/compiler/common_stubs.h" +#include "ecmascript/compiler/llvm_codegen.h" +#include "ecmascript/compiler/scheduler.h" +#include "ecmascript/compiler/slowpath_lowering.h" +#include "ecmascript/compiler/type_inference/type_infer.h" +#include "ecmascript/compiler/type_lowering.h" +#include "ecmascript/compiler/verifier.h" namespace panda::ecmascript::kungfu { class PassData { @@ -77,6 +79,17 @@ public: } }; +class TypeLoweringPass { +public: + bool Run(PassData *data, bool enableLog, BytecodeCircuitBuilder *builder, CompilationConfig *cmpCfg, + TSLoader *tsLoader) + { + TypeLowering lowering(builder, data->GetCircuit(), cmpCfg, tsLoader, enableLog); + lowering.RunTypeLowering(); + return true; + } +}; + class SlowPathLoweringPass { public: bool Run(PassData* data, bool enableLog, BytecodeCircuitBuilder *builder, CompilationConfig *cmpCfg) @@ -121,5 +134,17 @@ public: private: std::unique_ptr llvmImpl_ {nullptr}; }; + +class AsyncFunctionLoweringPass { +public: + bool Run(PassData* data, bool enableLog, BytecodeCircuitBuilder *builder, CompilationConfig *cmpCfg) + { + AsyncFunctionLowering lowering(builder, data->GetCircuit(), cmpCfg, enableLog); + if (lowering.IsAsyncRelated()) { + lowering.ProcessAll(); + } + return true; + } +}; } // namespace panda::ecmascript::kungfu #endif diff --git a/ecmascript/compiler/pass_manager.cpp b/ecmascript/compiler/pass_manager.cpp index 8a8a3dc80967406649032a3ae8781467f0083d7f..fb100fc81c07a8802bba1dce38223309c4a66091 100644 --- a/ecmascript/compiler/pass_manager.cpp +++ b/ecmascript/compiler/pass_manager.cpp @@ -30,7 +30,7 @@ bool PassManager::Compile(const std::string &fileName, AOTFileGenerator &generat [[maybe_unused]] EcmaHandleScope handleScope(vm_->GetJSThread()); bool res = CollectInfoOfPandaFile(fileName, entry_, &translationInfo); if (!res) { - COMPILER_LOG(ERROR) << "Cannot execute panda file '" << fileName << "'"; + LOG_COMPILER(ERROR) << "Cannot execute panda file '" << fileName << "'"; return false; } auto aotModule = new LLVMModule("aot_" + fileName, triple_); @@ -48,7 +48,7 @@ bool PassManager::Compile(const std::string &fileName, AOTFileGenerator &generat } if (enableLog) { - COMPILER_LOG(INFO) << "\033[34m" << "aot method [" << fileName << ":" + LOG_COMPILER(INFO) << "\033[34m" << "aot method [" << fileName << ":" << methodName << "] log:" << "\033[0m"; } @@ -56,7 +56,9 @@ bool PassManager::Compile(const std::string &fileName, AOTFileGenerator &generat builder.BytecodeToCircuit(); PassData data(builder.GetCircuit()); PassRunner pipeline(&data, enableLog); + pipeline.RunPass(&builder, &cmpCfg); pipeline.RunPass(&builder, tsLoader); + pipeline.RunPass(&builder, &cmpCfg, tsLoader); pipeline.RunPass(&builder, &cmpCfg); pipeline.RunPass(); pipeline.RunPass(); @@ -85,7 +87,7 @@ bool PassManager::CollectInfoOfPandaFile(const std::string &fileName, std::strin TSLoader *tsLoader = vm_->GetTSLoader(); tsLoader->DecodeTSTypes(jsPandaFile); } else { - COMPILER_LOG(INFO) << fileName << " has no type info"; + LOG_COMPILER(INFO) << fileName << " has no type info"; } auto program = PandaFileTranslator::GenerateProgram(vm_, jsPandaFile); diff --git a/ecmascript/compiler/scheduler.cpp b/ecmascript/compiler/scheduler.cpp index 030cdda788d9bb772bb9c691b0722721508fcc9e..7a4fde7bbaab8f47837a46c7526bd48760666237 100644 --- a/ecmascript/compiler/scheduler.cpp +++ b/ecmascript/compiler/scheduler.cpp @@ -214,7 +214,7 @@ std::optional> Scheduler::CalculateSchedulin } auto predUpperBound = predResult.value(); if (!isAncestor(curUpperBound, predUpperBound) && !isAncestor(predUpperBound, curUpperBound)) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Scheduling upper bound of gate (id=" + LOG_COMPILER(ERROR) << "[Verifier][Error] Scheduling upper bound of gate (id=" << circuit->LoadGatePtrConst(curGate)->GetId() << ") does not exist"; return std::nullopt; } @@ -304,31 +304,31 @@ void Scheduler::Print(const std::vector> *cfg, const Circui std::unordered_map bbGatesAddrToIdx; std::vector immDom; std::tie(bbGatesList, bbGatesAddrToIdx, immDom) = Scheduler::CalculateDominatorTree(circuit); - COMPILER_LOG(INFO) << "=========================================================================="; + LOG_COMPILER(INFO) << "=========================================================================="; for (size_t bbIdx = 0; bbIdx < cfg->size(); bbIdx++) { - COMPILER_LOG(INFO) << "BB_" << bbIdx << "_" << circuit->GetOpCode((*cfg)[bbIdx].front()).Str() << ":" + LOG_COMPILER(INFO) << "BB_" << bbIdx << "_" << circuit->GetOpCode((*cfg)[bbIdx].front()).Str() << ":" << " immDom=" << immDom[bbIdx]; - COMPILER_LOG(INFO) << " pred=["; + LOG_COMPILER(INFO) << " pred=["; bool isFirst = true; for (const auto &predStates : circuit->GetInVector((*cfg)[bbIdx].front())) { if (circuit->GetOpCode(predStates).IsState() || circuit->GetOpCode(predStates) == OpCode::STATE_ENTRY) { - COMPILER_LOG(INFO) << (isFirst ? "" : " ") << bbGatesAddrToIdx.at(predStates); + LOG_COMPILER(INFO) << (isFirst ? "" : " ") << bbGatesAddrToIdx.at(predStates); isFirst = false; } } - COMPILER_LOG(INFO) << "] succ=["; + LOG_COMPILER(INFO) << "] succ=["; isFirst = true; for (const auto &succStates : circuit->GetOutVector((*cfg)[bbIdx].front())) { if (circuit->GetOpCode(succStates).IsState() || circuit->GetOpCode(succStates) == OpCode::STATE_ENTRY) { - COMPILER_LOG(INFO) << (isFirst ? "" : " ") << bbGatesAddrToIdx.at(succStates); + LOG_COMPILER(INFO) << (isFirst ? "" : " ") << bbGatesAddrToIdx.at(succStates); isFirst = false; } } - COMPILER_LOG(INFO) << "]"; + LOG_COMPILER(INFO) << "]"; for (size_t instIdx = (*cfg)[bbIdx].size(); instIdx > 0; instIdx--) { circuit->Print((*cfg)[bbIdx][instIdx - 1]); } } - COMPILER_LOG(INFO) << "=========================================================================="; + LOG_COMPILER(INFO) << "=========================================================================="; } } // namespace panda::ecmascript::kungfu \ No newline at end of file diff --git a/ecmascript/compiler/slowpath_lowering.cpp b/ecmascript/compiler/slowpath_lowering.cpp index 5072f21941ba7207ea5b1e588e15e81c1017a8ae..584f31687144b9b04f590b16241ba5730337fb81 100644 --- a/ecmascript/compiler/slowpath_lowering.cpp +++ b/ecmascript/compiler/slowpath_lowering.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "slowpath_lowering.h" +#include "ecmascript/compiler/slowpath_lowering.h" namespace panda::ecmascript::kungfu { #define CREATE_DOUBLE_EXIT(SuccessLabel, FailLabel) \ @@ -43,7 +43,7 @@ void SlowPathLowering::CallRuntimeLowering() } if (IsLogEnabled()) { - COMPILER_LOG(INFO) << "========================================================="; + LOG_COMPILER(INFO) << "========================================================="; circuit_->PrintAllGates(*bcBuilder_); } } @@ -100,6 +100,8 @@ void SlowPathLowering::ReplaceHirToSubCfg(GateRef hir, GateRef outir, // replace normal depend } else if ((acc.GetOpCode(*useIt) == OpCode::JS_BYTECODE) && useIt.GetIndex() == 1) { acc.ReplaceIn(useIt, successControl[1]); + } else if ((acc.GetOpCode(*useIt) == OpCode::RUNTIME_CALL) && useIt.GetIndex() == 0) { + acc.ReplaceIn(useIt, successControl[1]); // if no catch block, just throw exception(RETURN) } else if ((acc.GetOpCode(*useIt) == OpCode::RETURN) && acc.GetOpCode(acc.GetIn(*useIt, 0)) == OpCode::IF_EXCEPTION) { @@ -204,12 +206,6 @@ GateRef SlowPathLowering::GetConstPool(GateRef jsFunc) return builder_.Load(VariableType::JS_ANY(), jsFunc, builder_.IntPtr(JSFunction::CONSTANT_POOL_OFFSET)); } -// labelmanager must be initialized -GateRef SlowPathLowering::GetCurrentEnv(GateRef jsFunc) -{ - return builder_.Load(VariableType::JS_ANY(), jsFunc, builder_.IntPtr(JSFunction::LEXICAL_ENV_OFFSET)); -} - // labelmanager must be initialized GateRef SlowPathLowering::GetObjectFromConstPool(GateRef jsFunc, GateRef index) { @@ -235,9 +231,10 @@ GateRef SlowPathLowering::GetValueFromConstStringTable(GateRef glue, GateRef gat void SlowPathLowering::Lower(GateRef gate) { - GateRef glue = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::GLUE); - GateRef newTarget = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::NEW_TARGET); - GateRef jsFunc = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::FUNC); + GateRef glue = argAcc_.GetCommonArgGate(CommonArgIdx::GLUE); + GateRef newTarget = argAcc_.GetCommonArgGate(CommonArgIdx::NEW_TARGET); + GateRef jsFunc = argAcc_.GetCommonArgGate(CommonArgIdx::FUNC); + GateRef actualArgc = argAcc_.GetCommonArgGate(CommonArgIdx::ACTUAL_ARGC); auto pc = bcBuilder_->GetJSBytecode(gate); EcmaOpcode op = static_cast(*pc); @@ -269,10 +266,10 @@ void SlowPathLowering::Lower(GateRef gate) LowerCallIRangeDyn(gate, glue); break; case LDLEXENVDYN_PREF: - LowerLexicalEnv(gate, glue, jsFunc); + LowerLexicalEnv(gate, glue); break; case GETUNMAPPEDARGS_PREF: - LowerGetUnmappedArgs(gate, glue); + LowerGetUnmappedArgs(gate, glue, actualArgc); break; case ASYNCFUNCTIONENTER_PREF: LowerAsyncFunctionEnter(gate, glue); @@ -335,7 +332,7 @@ void SlowPathLowering::Lower(GateRef gate) LowerCreateIterResultObj(gate, glue); break; case SUSPENDGENERATOR_PREF_V8_V8: - LowerSuspendGenerator(gate, glue); + LowerSuspendGenerator(gate, glue, jsFunc); break; case ASYNCFUNCTIONAWAITUNCAUGHT_PREF_V8_V8: LowerAsyncFunctionAwaitUncaught(gate, glue); @@ -467,7 +464,7 @@ void SlowPathLowering::Lower(GateRef gate) LowerSetObjectWithProto(gate, glue); break; case LDBIGINT_PREF_ID32: - LowerLdBigInt(gate, glue, jsFunc); + LowerLdBigInt(gate, glue); break; case LDMODULEVAR_PREF_ID32_IMM8: LowerLdModuleVar(gate, glue); @@ -529,13 +526,13 @@ void SlowPathLowering::Lower(GateRef gate) LowerDefineAsyncFunc(gate, glue, jsFunc); break; case NEWLEXENVDYN_PREF_IMM16: - LowerNewLexicalEnvDyn(gate, glue, jsFunc); + LowerNewLexicalEnvDyn(gate, glue); break; case NEWLEXENVWITHNAMEDYN_PREF_IMM16_IMM16: LowerNewLexicalEnvWithNameDyn(gate, glue, jsFunc); break; case POPLEXENVDYN_PREF: - LowerPopLexicalEnv(gate, glue, jsFunc); + LowerPopLexicalEnv(gate, glue); break; case LDSUPERBYVALUE_PREF_V8_V8: LowerLdSuperByValue(gate, glue, jsFunc); @@ -600,12 +597,12 @@ void SlowPathLowering::Lower(GateRef gate) case LDLEXVARDYN_PREF_IMM4_IMM4: case LDLEXVARDYN_PREF_IMM8_IMM8: case LDLEXVARDYN_PREF_IMM16_IMM16: - LowerLdLexVarDyn(gate, jsFunc); + LowerLdLexVarDyn(gate, glue); break; case STLEXVARDYN_PREF_IMM4_IMM4_V8: case STLEXVARDYN_PREF_IMM8_IMM8_V8: case STLEXVARDYN_PREF_IMM16_IMM16_V8: - LowerStLexVarDyn(gate, glue, jsFunc); + LowerStLexVarDyn(gate, glue); break; case CREATEOBJECTHAVINGMETHOD_PREF_IMM16: LowerCreateObjectHavingMethod(gate, glue, jsFunc); @@ -620,7 +617,7 @@ void SlowPathLowering::Lower(GateRef gate) LowerDefineFuncDyn(gate, glue, jsFunc); break; case COPYRESTARGS_PREF_IMM16: - LowerCopyRestArgs(gate, glue); + LowerCopyRestArgs(gate, glue, actualArgc); break; default: break; @@ -659,12 +656,85 @@ void SlowPathLowering::LowerCreateIterResultObj(GateRef gate, GateRef glue) ReplaceHirToCall(gate, newGate); } -void SlowPathLowering::LowerSuspendGenerator(GateRef gate, GateRef glue) +// When executing to SUSPENDGENERATOR instruction, save contextual information to GeneratorContext, +// including registers, acc, etc. +void SlowPathLowering::SaveFrameToContext(GateRef gate, GateRef glue, GateRef jsFunc) +{ + GateRef genObj = acc_.GetValueIn(gate, 1); + GateRef saveRegister = acc_.GetDep(gate); + ASSERT(acc_.GetOpCode(saveRegister) == OpCode::SAVE_REGISTER); + std::vector saveRegisterGates {}; + while (acc_.GetOpCode(saveRegister) == OpCode::SAVE_REGISTER) { + saveRegisterGates.emplace_back(saveRegister); + saveRegister = acc_.GetDep(saveRegister); + } + acc_.SetDep(gate, saveRegister); + builder_.SetDepend(saveRegister); + GateRef context = + builder_.Load(VariableType::JS_POINTER(), genObj, builder_.IntPtr(JSGeneratorObject::GENERATOR_CONTEXT_OFFSET)); + // new tagged array + const size_t arrLength = 65536; // 65536: Maximum number of virtual registers + GateRef length = builder_.Int32((arrLength)); + GateRef taggedLength = builder_.TaggedTypeNGC(builder_.ZExtInt32ToInt64(length)); + const int arrayId = RTSTUB_ID(NewTaggedArray); + GateRef taggedArray = LowerCallRuntime(glue, arrayId, {taggedLength}); + // setRegsArrays + for (auto item : saveRegisterGates) { + auto index = acc_.GetBitField(item); + auto valueGate = acc_.GetValueIn(item); + builder_.SetValueToTaggedArray(VariableType::JS_ANY(), glue, taggedArray, builder_.Int32(index), valueGate); + acc_.DeleteGate(item); + } + + // setRegsArrays + GateRef regsArrayOffset = builder_.IntPtr(GeneratorContext::GENERATOR_REGS_ARRAY_OFFSET); + builder_.Store(VariableType::JS_POINTER(), glue, context, regsArrayOffset, taggedArray); + + // set method + GateRef methodOffset = builder_.IntPtr(GeneratorContext::GENERATOR_METHOD_OFFSET); + builder_.Store(VariableType::JS_ANY(), glue, context, methodOffset, jsFunc); + + // set acc + GateRef accOffset = builder_.IntPtr(GeneratorContext::GENERATOR_ACC_OFFSET); + GateRef curAccGate = acc_.GetValueIn(gate, 3); // get current acc + builder_.Store(VariableType::JS_ANY(), glue, context, accOffset, curAccGate); + + // set generator object + GateRef generatorObjectOffset = builder_.IntPtr(GeneratorContext::GENERATOR_GENERATOR_OBJECT_OFFSET); + builder_.Store(VariableType::JS_ANY(), glue, context, generatorObjectOffset, genObj); + + // set lexical env + const int id = RTSTUB_ID(GetAotLexicalEnv); + GateRef lexicalEnvGate = LowerCallRuntime(glue, id, {jsFunc}); + GateRef lexicalEnvOffset = builder_.IntPtr(GeneratorContext::GENERATOR_LEXICALENV_OFFSET); + builder_.Store(VariableType::JS_ANY(), glue, context, lexicalEnvOffset, lexicalEnvGate); + + // set nregs + GateRef nregsOffset = builder_.IntPtr(GeneratorContext::GENERATOR_NREGS_OFFSET); + builder_.Store(VariableType::INT32(), glue, context, nregsOffset, length); + + // set bc size + GateRef bcSizeOffset = builder_.IntPtr(GeneratorContext::GENERATOR_BC_OFFSET_OFFSET); + GateRef bcSizeGate = acc_.GetValueIn(gate, 0); // saved bc_offset + bcSizeGate = builder_.TruncInt64ToInt32(bcSizeGate); + builder_.Store(VariableType::INT32(), glue, context, bcSizeOffset, bcSizeGate); + + // set context to generator object + GateRef contextOffset = builder_.IntPtr(JSGeneratorObject::GENERATOR_CONTEXT_OFFSET); + builder_.Store(VariableType::JS_POINTER(), glue, genObj, contextOffset, context); + + // set generator object to context + builder_.Store(VariableType::JS_POINTER(), glue, context, generatorObjectOffset, genObj); +} + +void SlowPathLowering::LowerSuspendGenerator(GateRef gate, GateRef glue, [[maybe_unused]]GateRef jsFunc) { + // 4: number of value inputs + ASSERT(acc_.GetNumValueIn(gate) == 4); + SaveFrameToContext(gate, glue, jsFunc); + acc_.SetDep(gate, builder_.GetDepend()); const int id = RTSTUB_ID(SuspendAotGenerator); - // 2: number of value inputs - ASSERT(acc_.GetNumValueIn(gate) == 2); - GateRef newGate = LowerCallRuntime(glue, id, {acc_.GetValueIn(gate, 0), acc_.GetValueIn(gate, 1)}); + GateRef newGate = LowerCallRuntime(glue, id, {acc_.GetValueIn(gate, 1), acc_.GetValueIn(gate, 2)}); ReplaceHirToCall(gate, newGate); } @@ -703,10 +773,10 @@ void SlowPathLowering::LowerLoadStr(GateRef gate, GateRef glue) ReplaceHirToCall(gate, newGate); } -void SlowPathLowering::LowerLexicalEnv(GateRef gate, GateRef glue, GateRef jsFunc) +void SlowPathLowering::LowerLexicalEnv(GateRef gate, GateRef glue) { const int id = RTSTUB_ID(GetAotLexicalEnv); - GateRef newGate = LowerCallRuntime(glue, id, {jsFunc}); + GateRef newGate = LowerCallRuntime(glue, id, {}); ReplaceHirToCall(gate, newGate, true); } @@ -793,7 +863,6 @@ void SlowPathLowering::LowerGetIterator(GateRef gate, GateRef glue) ReplaceHirToSubCfg(gate, value, successControl, failControl); } - void SlowPathLowering::LowerToJSCall(GateRef gate, GateRef glue, const std::vector &args) { const CallSignature *cs = RuntimeStubCSigns::Get(RTSTUB_ID(JSCall)); @@ -807,11 +876,13 @@ void SlowPathLowering::LowerCallArg0Dyn(GateRef gate, GateRef glue) // 2: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 2); - GateRef actualArgc = builder_.Int32(ComputeCallArgc(gate, EcmaOpcode::CALLARG0DYN_PREF_V8)); + GateRef actualArgc = builder_.Int64(ComputeCallArgc(gate, EcmaOpcode::CALLARG0DYN_PREF_V8)); GateRef newTarget = builder_.Undefined(); GateRef thisObj = builder_.Undefined(); - LowerToJSCall(gate, glue, {glue, actualArgc, acc_.GetValueIn(gate, 0), newTarget, thisObj, - acc_.GetValueIn(gate, 1)}); + GateRef func = acc_.GetValueIn(gate, 0); + GateRef env = builder_.GetLexicalEnv(func); + GateRef bcOffset = acc_.GetValueIn(gate, 1); + LowerToJSCall(gate, glue, {glue, env, actualArgc, func, newTarget, thisObj, bcOffset}); } void SlowPathLowering::LowerCallArg1Dyn(GateRef gate, GateRef glue) @@ -819,11 +890,13 @@ void SlowPathLowering::LowerCallArg1Dyn(GateRef gate, GateRef glue) // 3: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 3); // 2: func and bcoffset - GateRef actualArgc = builder_.Int32(ComputeCallArgc(gate, EcmaOpcode::CALLARG1DYN_PREF_V8_V8)); + GateRef actualArgc = builder_.Int64(ComputeCallArgc(gate, EcmaOpcode::CALLARG1DYN_PREF_V8_V8)); GateRef newTarget = builder_.Undefined(); GateRef thisObj = builder_.Undefined(); - LowerToJSCall(gate, glue, {glue, actualArgc, - acc_.GetValueIn(gate, 0), newTarget, thisObj, acc_.GetValueIn(gate, 1), acc_.GetValueIn(gate, 2)}); + GateRef func = acc_.GetValueIn(gate, 0); + GateRef env = builder_.GetLexicalEnv(func); + GateRef bcOffset = acc_.GetValueIn(gate, 2); // 2: bytecode offset + LowerToJSCall(gate, glue, {glue, env, actualArgc, func, newTarget, thisObj, acc_.GetValueIn(gate, 1), bcOffset}); } void SlowPathLowering::LowerCallArgs2Dyn(GateRef gate, GateRef glue) @@ -831,25 +904,28 @@ void SlowPathLowering::LowerCallArgs2Dyn(GateRef gate, GateRef glue) // 4: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 4); // 2: func and bcoffset - GateRef actualArgc = builder_.Int32(ComputeCallArgc(gate, EcmaOpcode::CALLARGS2DYN_PREF_V8_V8_V8)); + GateRef actualArgc = builder_.Int64(ComputeCallArgc(gate, EcmaOpcode::CALLARGS2DYN_PREF_V8_V8_V8)); GateRef newTarget = builder_.Undefined(); GateRef thisObj = builder_.Undefined(); - LowerToJSCall(gate, glue, {glue, actualArgc, - acc_.GetValueIn(gate, 0), newTarget, thisObj, acc_.GetValueIn(gate, 1), acc_.GetValueIn(gate, 2), - acc_.GetValueIn(gate, 3)}); + GateRef func = acc_.GetValueIn(gate, 0); + GateRef env = builder_.GetLexicalEnv(func); + GateRef bcOffset = acc_.GetValueIn(gate, 3); // 3: bytecode offset + LowerToJSCall(gate, glue, {glue, env, actualArgc, func, newTarget, thisObj, acc_.GetValueIn(gate, 1), + acc_.GetValueIn(gate, 2), bcOffset}); } void SlowPathLowering::LowerCallArgs3Dyn(GateRef gate, GateRef glue) { // 5: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 5); - // 2: func and bcoffset - GateRef actualArgc = builder_.Int32(ComputeCallArgc(gate, EcmaOpcode::CALLARGS3DYN_PREF_V8_V8_V8_V8)); + GateRef actualArgc = builder_.Int64(ComputeCallArgc(gate, EcmaOpcode::CALLARGS3DYN_PREF_V8_V8_V8_V8)); GateRef newTarget = builder_.Undefined(); GateRef thisObj = builder_.Undefined(); - LowerToJSCall(gate, glue, {glue, actualArgc, - acc_.GetValueIn(gate, 0), newTarget, thisObj, acc_.GetValueIn(gate, 1), - acc_.GetValueIn(gate, 2), acc_.GetValueIn(gate, 3)}); + GateRef func = acc_.GetValueIn(gate, 0); + GateRef env = builder_.GetLexicalEnv(func); + GateRef bcOffset = acc_.GetValueIn(gate, 4); // 4: bytecode offset + LowerToJSCall(gate, glue, {glue, env, actualArgc, func, newTarget, thisObj, acc_.GetValueIn(gate, 1), + acc_.GetValueIn(gate, 2), acc_.GetValueIn(gate, 3), bcOffset}); } void SlowPathLowering::LowerCallIThisRangeDyn(GateRef gate, GateRef glue) @@ -858,17 +934,20 @@ void SlowPathLowering::LowerCallIThisRangeDyn(GateRef gate, GateRef glue) // The first register input is callTarget, second is thisObj and other inputs are common args. size_t fixedInputsNum = 2; ASSERT(acc_.GetNumValueIn(gate) - fixedInputsNum >= 0); - GateRef actualArgc = builder_.Int32(ComputeCallArgc(gate, EcmaOpcode::CALLITHISRANGEDYN_PREF_IMM16_V8)); + GateRef actualArgc = builder_.Int64(ComputeCallArgc(gate, EcmaOpcode::CALLITHISRANGEDYN_PREF_IMM16_V8)); GateRef callTarget = acc_.GetValueIn(gate, 0); GateRef thisObj = acc_.GetValueIn(gate, 1); GateRef newTarget = builder_.Undefined(); + GateRef env = builder_.GetLexicalEnv(callTarget); vec.emplace_back(glue); + vec.emplace_back(env); vec.emplace_back(actualArgc); vec.emplace_back(callTarget); vec.emplace_back(newTarget); vec.emplace_back(thisObj); // add common args - for (size_t i = fixedInputsNum; i < acc_.GetNumValueIn(gate); i++) { + size_t numIns = acc_.GetNumValueIn(gate); + for (size_t i = fixedInputsNum; i < numIns; i++) { vec.emplace_back(acc_.GetValueIn(gate, i)); } LowerToJSCall(gate, glue, vec); @@ -888,12 +967,14 @@ void SlowPathLowering::LowerCallSpreadDyn(GateRef gate, GateRef glue) void SlowPathLowering::LowerCallIRangeDyn(GateRef gate, GateRef glue) { std::vector vec; - size_t numArgs = acc_.GetNumValueIn(gate) - 1; - GateRef actualArgc = builder_.Int32(ComputeCallArgc(gate, EcmaOpcode::CALLIRANGEDYN_PREF_IMM16_V8)); + size_t numArgs = acc_.GetNumValueIn(gate); + GateRef actualArgc = builder_.Int64(ComputeCallArgc(gate, EcmaOpcode::CALLIRANGEDYN_PREF_IMM16_V8)); GateRef callTarget = acc_.GetValueIn(gate, 0); GateRef newTarget = builder_.Undefined(); GateRef thisObj = builder_.Undefined(); + GateRef env = builder_.GetLexicalEnv(callTarget); vec.emplace_back(glue); + vec.emplace_back(env); vec.emplace_back(actualArgc); vec.emplace_back(callTarget); vec.emplace_back(newTarget); @@ -918,8 +999,10 @@ void SlowPathLowering::LowerNewObjSpreadDyn(GateRef gate, GateRef glue) void SlowPathLowering::LowerThrowDyn(GateRef gate, GateRef glue) { GateRef exception = acc_.GetValueIn(gate, 0); + GateRef exceptionOffset = builder_.Int64(JSThread::GlueData::GetExceptionOffset(false)); + GateRef val = builder_.Int64Add(glue, exceptionOffset); GateRef setException = circuit_->NewGate(OpCode(OpCode::STORE), 0, - {dependEntry_, exception, glue}, VariableType::INT64().GetGateType()); + {dependEntry_, exception, val}, VariableType::INT64().GetGateType()); ReplaceHirToThrowCall(gate, setException); } @@ -950,9 +1033,28 @@ void SlowPathLowering::LowerThrowPatternNonCoercible(GateRef gate, GateRef glue) void SlowPathLowering::LowerThrowIfNotObject(GateRef gate, GateRef glue) { - const int id = RTSTUB_ID(ThrowIfNotObject); - GateRef newGate = LowerCallRuntime(glue, id, {}); - ReplaceHirToThrowCall(gate, newGate); + // 1: number of value inputs + ASSERT(acc_.GetNumValueIn(gate) == 1); + GateRef value = acc_.GetValueIn(gate, 0); + Label successExit(&builder_); + Label exceptionExit(&builder_); + Label isEcmaObject(&builder_); + Label notEcmaObject(&builder_); + Label isHeapObject(&builder_); + builder_.Branch(builder_.TaggedIsHeapObject(value), &isHeapObject, ¬EcmaObject); + builder_.Bind(&isHeapObject); + builder_.Branch(builder_.TaggedObjectIsEcmaObject(value), &isEcmaObject, ¬EcmaObject); + builder_.Bind(&isEcmaObject); + { + builder_.Jump(&successExit); + } + builder_.Bind(¬EcmaObject); + { + LowerCallRuntime(glue, RTSTUB_ID(ThrowIfNotObject), {}, true); + builder_.Jump(&exceptionExit); + } + CREATE_DOUBLE_EXIT(successExit, exceptionExit) + ReplaceHirToSubCfg(gate, Circuit::NullGate(), successControl, failControl); } void SlowPathLowering::LowerThrowUndefinedIfHole(GateRef gate, GateRef glue) @@ -998,14 +1100,16 @@ void SlowPathLowering::LowerThrowDeleteSuperProperty(GateRef gate, GateRef glue) void SlowPathLowering::LowerExceptionHandler(GateRef hirGate) { - GateRef glue = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::GLUE); + GateRef glue = argAcc_.GetCommonArgGate(CommonArgIdx::GLUE); GateRef depend = acc_.GetDep(hirGate); + GateRef exceptionOffset = builder_.Int64(JSThread::GlueData::GetExceptionOffset(false)); + GateRef val = builder_.Int64Add(glue, exceptionOffset); GateRef loadException = circuit_->NewGate(OpCode(OpCode::LOAD), VariableType::JS_ANY().GetMachineType(), - 0, { depend, glue }, VariableType::JS_ANY().GetGateType()); + 0, { depend, val }, VariableType::JS_ANY().GetGateType()); acc_.SetDep(loadException, depend); GateRef holeCst = builder_.HoleConstant(VariableType::JS_ANY().GetGateType()); GateRef clearException = circuit_->NewGate(OpCode(OpCode::STORE), 0, - { loadException, holeCst, glue }, VariableType::INT64().GetGateType()); + { loadException, holeCst, val }, VariableType::INT64().GetGateType()); auto uses = acc_.Uses(hirGate); for (auto it = uses.begin(); it != uses.end(); it++) { if (acc_.GetDep(*it) == hirGate && acc_.IsDependIn(it)) { @@ -1395,13 +1499,14 @@ void SlowPathLowering::LowerSetObjectWithProto(GateRef gate, GateRef glue) ReplaceHirToCall(gate, newGate); } -void SlowPathLowering::LowerLdBigInt(GateRef gate, GateRef glue, GateRef jsFunc) +void SlowPathLowering::LowerLdBigInt(GateRef gate, GateRef glue) { std::vector successControl; std::vector failControl; // 1: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 1); - GateRef numberBigInt = GetObjectFromConstPool(jsFunc, acc_.GetValueIn(gate, 0)); + GateRef stringId = builder_.TaggedTypeNGC(builder_.ZExtInt32ToInt64(acc_.GetValueIn(gate, 0))); + GateRef numberBigInt = LowerCallRuntime(glue, RTSTUB_ID(LoadValueFromConstantStringTable), { stringId }, true); GateRef result = LowerCallRuntime(glue, RTSTUB_ID(LdBigInt), {numberBigInt}, true); successControl.emplace_back(builder_.GetState()); successControl.emplace_back(builder_.GetDepend()); @@ -1858,13 +1963,13 @@ void SlowPathLowering::LowerDefineAsyncFunc(GateRef gate, GateRef glue, GateRef ReplaceHirToSubCfg(gate, result, successControl, failControl); } -void SlowPathLowering::LowerNewLexicalEnvDyn(GateRef gate, GateRef glue, GateRef jsFunc) +void SlowPathLowering::LowerNewLexicalEnvDyn(GateRef gate, GateRef glue) { std::vector successControl; std::vector failControl; // 1: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 1); - GateRef lexEnv = LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {jsFunc}, true); + GateRef lexEnv = LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {}, true); GateRef result = LowerCallRuntime(glue, RTSTUB_ID(NewAotLexicalEnvDyn), {builder_.TaggedTypeNGC(acc_.GetValueIn(gate, 0)), lexEnv}, true); successControl.emplace_back(builder_.GetState()); @@ -1880,10 +1985,10 @@ void SlowPathLowering::LowerNewLexicalEnvWithNameDyn(GateRef gate, GateRef glue, std::vector failControl; // 2: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 2); - GateRef lexEnv = LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {jsFunc}, true); + GateRef lexEnv = LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {}, true); auto args = { builder_.TaggedTypeNGC(acc_.GetValueIn(gate, 0)), builder_.TaggedTypeNGC(acc_.GetValueIn(gate, 1)), - lexEnv}; + lexEnv, jsFunc}; GateRef result = LowerCallRuntime(glue, RTSTUB_ID(NewAotLexicalEnvWithNameDyn), args, true); successControl.emplace_back(builder_.GetState()); successControl.emplace_back(builder_.GetDepend()); @@ -1892,14 +1997,11 @@ void SlowPathLowering::LowerNewLexicalEnvWithNameDyn(GateRef gate, GateRef glue, ReplaceHirToSubCfg(gate, result, successControl, failControl, true); } -void SlowPathLowering::LowerPopLexicalEnv(GateRef gate, GateRef glue, GateRef jsFunc) +void SlowPathLowering::LowerPopLexicalEnv(GateRef gate, GateRef glue) { std::vector successControl; std::vector failControl; - GateRef result = LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {jsFunc}, true); - GateRef index = builder_.Int32(LexicalEnv::PARENT_ENV_INDEX); - GateRef parentLexEnv = builder_.GetValueFromTaggedArray(VariableType::JS_ANY(), result, index); - builder_.SetLexicalEnvToFunction(glue, jsFunc, parentLexEnv); + LowerCallRuntime(glue, RTSTUB_ID(PopAotLexicalEnv), {}, true); successControl.emplace_back(builder_.GetState()); successControl.emplace_back(builder_.GetDepend()); failControl.emplace_back(Circuit::NullGate()); @@ -2477,13 +2579,14 @@ void SlowPathLowering::LowerStArraySpread(GateRef gate, GateRef glue) ReplaceHirToCall(gate, newGate); } -void SlowPathLowering::LowerLdLexVarDyn(GateRef gate, GateRef jsFunc) +void SlowPathLowering::LowerLdLexVarDyn(GateRef gate, GateRef glue) { // 2: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 2); GateRef level = builder_.TruncInt64ToInt32(acc_.GetValueIn(gate, 0)); GateRef slot = builder_.TruncInt64ToInt32(acc_.GetValueIn(gate, 1)); - DEFVAlUE(currentEnv, (&builder_), VariableType::JS_ANY(), GetCurrentEnv(jsFunc)); + DEFVAlUE(currentEnv, (&builder_), VariableType::JS_ANY(), + LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {}, true)); DEFVAlUE(i, (&builder_), VariableType::INT32(), builder_.Int32(0)); std::vector successControl; std::vector exceptionControl; @@ -2509,14 +2612,15 @@ void SlowPathLowering::LowerLdLexVarDyn(GateRef gate, GateRef jsFunc) ReplaceHirToSubCfg(gate, result, successControl, exceptionControl, true); } -void SlowPathLowering::LowerStLexVarDyn(GateRef gate, GateRef glue, GateRef jsFunc) +void SlowPathLowering::LowerStLexVarDyn(GateRef gate, GateRef glue) { // 3: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 3); GateRef level = builder_.TruncInt64ToInt32(acc_.GetValueIn(gate, 0)); GateRef slot = builder_.TruncInt64ToInt32(acc_.GetValueIn(gate, 1)); GateRef value = acc_.GetValueIn(gate, 2); - DEFVAlUE(currentEnv, (&builder_), VariableType::JS_ANY(), GetCurrentEnv(jsFunc)); + DEFVAlUE(currentEnv, (&builder_), VariableType::JS_ANY(), + LowerCallRuntime(glue, RTSTUB_ID(GetAotLexicalEnv), {}, true)); DEFVAlUE(i, (&builder_), VariableType::INT32(), builder_.Int32(0)); std::vector successControl; std::vector exceptionControl; @@ -2826,13 +2930,52 @@ void SlowPathLowering::LowerTypeOfDyn(GateRef gate, GateRef glue) ReplaceHirToSubCfg(gate, *result, successControl, failControl, true); } +GateRef SlowPathLowering::GetValueFromTaggedArray(GateRef arrayGate, GateRef indexOffset) +{ + GateRef offset = builder_.PtrMul(builder_.ChangeInt32ToIntPtr(indexOffset), + builder_.IntPtr(JSTaggedValue::TaggedTypeSize())); + GateRef dataOffset = builder_.PtrAdd(offset, builder_.IntPtr(TaggedArray::DATA_OFFSET)); + GateRef value = builder_.Load(VariableType::JS_ANY(), arrayGate, dataOffset); + return value; +} + void SlowPathLowering::LowerResumeGenerator(GateRef gate) { + GateRef obj = acc_.GetValueIn(gate, 0); + GateRef restoreGate = acc_.GetDep(gate); + std::vector registerGates {}; + + while (acc_.GetOpCode(restoreGate) == OpCode::RESTORE_REGISTER) { + registerGates.emplace_back(restoreGate); + restoreGate = acc_.GetDep(restoreGate); + } + + acc_.SetDep(gate, restoreGate); + builder_.SetDepend(restoreGate); + GateRef contextOffset = builder_.IntPtr(JSGeneratorObject::GENERATOR_CONTEXT_OFFSET); + GateRef contextGate = builder_.Load(VariableType::JS_POINTER(), obj, contextOffset); + GateRef arrayOffset = builder_.IntPtr(GeneratorContext::GENERATOR_REGS_ARRAY_OFFSET); + GateRef arrayGate = builder_.Load(VariableType::JS_POINTER(), contextGate, arrayOffset); + + for (auto item : registerGates) { + auto index = acc_.GetBitField(item); + auto indexOffset = builder_.Int32(index); + GateRef value = GetValueFromTaggedArray(arrayGate, indexOffset); + auto uses = acc_.Uses(item); + for (auto use = uses.begin(); use != uses.end(); use++) { + size_t valueStartIndex = acc_.GetStateCount(*use) + acc_.GetDependCount(*use); + size_t valueEndIndex = valueStartIndex + acc_.GetInValueCount(*use); + if (use.GetIndex() >= valueStartIndex && use.GetIndex() < valueEndIndex) { + acc_.ReplaceIn(use, value); + } + } + acc_.DeleteGate(item); + } + // 1: number of value inputs ASSERT(acc_.GetNumValueIn(gate) == 1); std::vector successControl; std::vector failControl; - GateRef obj = acc_.GetValueIn(gate, 0); GateRef resumeResultOffset = builder_.IntPtr(JSGeneratorObject::GENERATOR_RESUME_RESULT_OFFSET); GateRef result = builder_.Load(VariableType::JS_ANY(), obj, resumeResultOffset); successControl.emplace_back(builder_.GetState()); @@ -2963,40 +3106,22 @@ void SlowPathLowering::LowerDefineMethod(GateRef gate, GateRef glue, GateRef jsF ReplaceHirToSubCfg(gate, result, successControl, failControl); } -void SlowPathLowering::LowerGetUnmappedArgs(GateRef gate, GateRef glue) +void SlowPathLowering::LowerGetUnmappedArgs(GateRef gate, GateRef glue, GateRef actualArgc) { - GateRef actualArgc = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::ACTUAL_ARGC); GateRef taggedArgc = builder_.TaggedTypeNGC(builder_.ZExtInt32ToInt64(actualArgc)); - std::vector vec; - GateRef argList = Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST)); - auto uses = acc_.ConstUses(argList); - for (auto useIt = uses.begin(); useIt != uses.end(); useIt++) { - vec.emplace_back(*useIt); - } - std::vector args({vec.rbegin() + CommonArgIdx::NUM_OF_ARGS, vec.rend()}); - args.insert(args.begin(), taggedArgc); const int id = RTSTUB_ID(GetAotUnmapedArgs); - GateRef newGate = LowerCallRuntime(glue, id, args); + GateRef newGate = LowerCallRuntime(glue, id, {taggedArgc}); ReplaceHirToCall(gate, newGate); } -void SlowPathLowering::LowerCopyRestArgs(GateRef gate, GateRef glue) +void SlowPathLowering::LowerCopyRestArgs(GateRef gate, GateRef glue, GateRef actualArgc) { - GateRef actualArgc = bcBuilder_->GetCommonArgByIndex(CommonArgIdx::ACTUAL_ARGC); + GateRef taggedArgc = builder_.TaggedTypeNGC(builder_.ZExtInt32ToInt64(actualArgc)); GateRef restIdx = acc_.GetValueIn(gate, 0); - size_t restId = acc_.GetImmediateId(restIdx); - GateRef restNum = builder_.Int64Sub(builder_.ZExtInt32ToInt64(actualArgc), restIdx); - GateRef taggedRestNum = builder_.TaggedTypeNGC(restNum); - std::vector vec; - GateRef argList = Circuit::GetCircuitRoot(OpCode(OpCode::ARG_LIST)); - auto uses = acc_.ConstUses(argList); - for (auto useIt = uses.begin(); useIt != uses.end(); useIt++) { - vec.emplace_back(*useIt); - } - std::vector args({vec.rbegin() + CommonArgIdx::NUM_OF_ARGS + restId, vec.rend()}); - args.insert(args.begin(), taggedRestNum); + GateRef taggedRestIdx = builder_.TaggedTypeNGC(restIdx); + const int id = RTSTUB_ID(CopyAotRestArgs); - GateRef newGate = LowerCallRuntime(glue, id, args); + GateRef newGate = LowerCallRuntime(glue, id, {taggedArgc, taggedRestIdx}); ReplaceHirToCall(gate, newGate); } } // namespace panda::ecmascript diff --git a/ecmascript/compiler/slowpath_lowering.h b/ecmascript/compiler/slowpath_lowering.h index a200bce201d1933f5350e4cdaea18e9b5ce67469..268ecd7f77d865c3676001129750b0716f456390 100644 --- a/ecmascript/compiler/slowpath_lowering.h +++ b/ecmascript/compiler/slowpath_lowering.h @@ -13,14 +13,15 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_COMPILER_GENERIC_LOWERING_H -#define ECMASCRIPT_COMPILER_GENERIC_LOWERING_H +#ifndef ECMASCRIPT_COMPILER_SLOWPATH_LOWERING_H +#define ECMASCRIPT_COMPILER_SLOWPATH_LOWERING_H -#include "circuit.h" -#include "bytecode_circuit_builder.h" -#include "circuit_builder.h" -#include "circuit_builder-inl.h" -#include "gate_accessor.h" +#include "ecmascript/compiler/argument_accessor.h" +#include "ecmascript/compiler/bytecode_circuit_builder.h" +#include "ecmascript/compiler/circuit.h" +#include "ecmascript/compiler/circuit_builder.h" +#include "ecmascript/compiler/circuit_builder-inl.h" +#include "ecmascript/compiler/gate_accessor.h" namespace panda::ecmascript::kungfu { // slowPath Lowering Process @@ -111,8 +112,10 @@ class SlowPathLowering { public: SlowPathLowering(BytecodeCircuitBuilder *bcBuilder, Circuit *circuit, CompilationConfig *cmpCfg, bool enableLog) - : bcBuilder_(bcBuilder), circuit_(circuit), acc_(circuit), builder_(circuit, cmpCfg), - dependEntry_(Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY))), enableLog_(enableLog) {} + : bcBuilder_(bcBuilder), circuit_(circuit), acc_(circuit), + argAcc_(circuit), builder_(circuit, cmpCfg), + dependEntry_(Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY))), + enableLog_(enableLog) {} ~SlowPathLowering() = default; void CallRuntimeLowering(); @@ -133,8 +136,6 @@ private: // environment must be initialized GateRef GetConstPool(GateRef jsFunc); // environment must be initialized - GateRef GetCurrentEnv(GateRef jsFunc); - // environment must be initialized GateRef GetObjectFromConstPool(GateRef jsFunc, GateRef index); // environment must be initialized GateRef GetHomeObjectFromJSFunction(GateRef jsFunc); @@ -142,12 +143,13 @@ private: void Lower(GateRef gate); void LowerAdd2Dyn(GateRef gate, GateRef glue); void LowerCreateIterResultObj(GateRef gate, GateRef glue); - void LowerSuspendGenerator(GateRef gate, GateRef glue); + void SaveFrameToContext(GateRef gate, GateRef glue, GateRef jsFunc); + void LowerSuspendGenerator(GateRef gate, GateRef glue, [[maybe_unused]]GateRef jsFunc); void LowerAsyncFunctionAwaitUncaught(GateRef gate, GateRef glue); void LowerAsyncFunctionResolve(GateRef gate, GateRef glue); void LowerAsyncFunctionReject(GateRef gate, GateRef glue); void LowerLoadStr(GateRef gate, GateRef glue); - void LowerLexicalEnv(GateRef gate, GateRef glue, GateRef jsFunc); + void LowerLexicalEnv(GateRef gate, GateRef glue); void LowerStGlobalVar(GateRef gate, GateRef glue); void LowerTryLdGlobalByName(GateRef gate, GateRef glue); void LowerGetIterator(GateRef gate, GateRef glue); @@ -207,7 +209,7 @@ private: void LowerStModuleVar(GateRef gate, GateRef glue); void LowerGetTemplateObject(GateRef gate, GateRef glue); void LowerSetObjectWithProto(GateRef gate, GateRef glue); - void LowerLdBigInt(GateRef gate, GateRef glue, GateRef jsFunc); + void LowerLdBigInt(GateRef gate, GateRef glue); void LowerLdModuleVar(GateRef gate, GateRef glue); void LowerGetModuleNamespace(GateRef gate, GateRef glue); void LowerGetIteratorNext(GateRef gate, GateRef glue); @@ -226,9 +228,9 @@ private: void LowerDefineFuncDyn(GateRef gate, GateRef glue, GateRef jsFunc); void LowerDefineGeneratorFunc(GateRef gate, GateRef glue, GateRef jsFunc); void LowerDefineAsyncFunc(GateRef gate, GateRef glue, GateRef jsFunc); - void LowerNewLexicalEnvDyn(GateRef gate, GateRef glue, GateRef jsFunc); + void LowerNewLexicalEnvDyn(GateRef gate, GateRef glue); void LowerNewLexicalEnvWithNameDyn(GateRef gate, GateRef glue, GateRef jsFunc); - void LowerPopLexicalEnv(GateRef gate, GateRef glue, GateRef jsFunc); + void LowerPopLexicalEnv(GateRef gate, GateRef glue); void LowerLdSuperByValue(GateRef gate, GateRef glue, GateRef jsFunc); void LowerStSuperByValue(GateRef gate, GateRef glue, GateRef jsFunc); void LowerTryStGlobalByName(GateRef gate, GateRef glue); @@ -249,8 +251,8 @@ private: void LowerStObjByValue(GateRef gate, GateRef glue); void LowerCreateGeneratorObj(GateRef gate, GateRef glue); void LowerStArraySpread(GateRef gate, GateRef glue); - void LowerLdLexVarDyn(GateRef gate, GateRef jsFunc); - void LowerStLexVarDyn(GateRef gate, GateRef glue, GateRef jsFunc); + void LowerLdLexVarDyn(GateRef gate, GateRef glue); + void LowerStLexVarDyn(GateRef gate, GateRef glue); void LowerCreateObjectHavingMethod(GateRef gate, GateRef glue, GateRef jsFunc); void LowerLdHomeObject(GateRef gate, GateRef jsFunc); void LowerDefineClassWithBuffer(GateRef gate, GateRef glue, GateRef jsFunc); @@ -260,17 +262,19 @@ private: void LowerGetResumeMode(GateRef gate); void LowerDefineNCFuncDyn(GateRef gate, GateRef glue, GateRef jsFunc); void LowerDefineMethod(GateRef gate, GateRef glue, GateRef jsFunc); - void LowerGetUnmappedArgs(GateRef gate, GateRef glue); - void LowerCopyRestArgs(GateRef gate, GateRef glue); + void LowerGetUnmappedArgs(GateRef gate, GateRef glue, GateRef actualArgc); + void LowerCopyRestArgs(GateRef gate, GateRef glue, GateRef actualArgc); GateRef LowerCallRuntime(GateRef glue, int index, const std::vector &args, bool useLabel = false); int32_t ComputeCallArgc(GateRef gate, EcmaOpcode op); + GateRef GetValueFromTaggedArray(GateRef arrayGate, GateRef indexOffset); BytecodeCircuitBuilder *bcBuilder_; Circuit *circuit_; GateAccessor acc_; + ArgumentAccessor argAcc_; CircuitBuilder builder_; GateRef dependEntry_; bool enableLog_ {false}; }; } // panda::ecmascript::kungfu -#endif // ECMASCRIPT_COMPILER_GENERIC_LOWERING_H +#endif // ECMASCRIPT_COMPILER_SLOWPATH_LOWERING_H diff --git a/ecmascript/compiler/stub-inl.h b/ecmascript/compiler/stub-inl.h index e8672f881df94e9b3d30139f248e3eef29724da5..415867090382e2617d08868a6f7cf4592635c306 100644 --- a/ecmascript/compiler/stub-inl.h +++ b/ecmascript/compiler/stub-inl.h @@ -33,7 +33,6 @@ #include "ecmascript/message_string.h" #include "ecmascript/mem/slots.h" #include "ecmascript/mem/visitor.h" -#include "mem/region_space.h" namespace panda::ecmascript::kungfu { using JSFunction = panda::ecmascript::JSFunction; @@ -248,6 +247,21 @@ inline GateRef Stub::CallNGCRuntime(GateRef glue, int index, const std::initiali return result; } +inline GateRef Stub::UpdateLeaveFrameAndCallNGCRuntime(GateRef glue, int index, + const std::initializer_list& args) +{ + if (env_.IsAsmInterp()) { + // CpuProfiler will get the latest leaveFrame_ in thread to up frames. + // So it's necessary to update leaveFrame_ if the program enters the c++ environment. + // We use the latest asm interpreter frame to update it when CallNGCRuntime. + GateRef sp = PtrArgument(static_cast(InterpreterHandlerInputs::SP)); + GateRef spOffset = IntPtr(JSThread::GlueData::GetLeaveFrameOffset(env_.Is32Bit())); + Store(VariableType::NATIVE_POINTER(), glue, glue, spOffset, sp); + } + GateRef result = CallNGCRuntime(glue, index, args); + return result; +} + inline GateRef Stub::CallStub(GateRef glue, int index, const std::initializer_list& args) { SavePcIfNeeded(glue); @@ -257,12 +271,12 @@ inline GateRef Stub::CallStub(GateRef glue, int index, const std::initializer_li inline void Stub::DebugPrint(GateRef glue, std::initializer_list args) { - CallNGCRuntime(glue, RTSTUB_ID(DebugPrint), args); + UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(DebugPrint), args); } inline void Stub::FatalPrint(GateRef glue, std::initializer_list args) { - CallNGCRuntime(glue, RTSTUB_ID(FatalPrint), args); + UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(FatalPrint), args); } void Stub::SavePcIfNeeded(GateRef glue) @@ -562,7 +576,7 @@ inline GateRef Stub::BinaryOp(GateRef x, GateRef y) inline GateRef Stub::TaggedIsInt(GateRef x) { - return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_MASK)), + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_MARK)), Int64(JSTaggedValue::TAG_INT)); } @@ -573,7 +587,7 @@ inline GateRef Stub::TaggedIsDouble(GateRef x) inline GateRef Stub::TaggedIsObject(GateRef x) { - return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_MASK)), + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_MARK)), Int64(JSTaggedValue::TAG_OBJECT)); } @@ -605,12 +619,12 @@ inline GateRef Stub::TaggedIsException(GateRef x) inline GateRef Stub::TaggedIsSpecial(GateRef x) { return BoolOr(Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_SPECIAL_MARK)), - Int64(JSTaggedValue::TAG_SPECIAL_VALUE)), TaggedIsHole(x)); + Int64(JSTaggedValue::TAG_SPECIAL)), TaggedIsHole(x)); } inline GateRef Stub::TaggedIsHeapObject(GateRef x) { - return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_BOOLEAN)), Int64(0)); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_MARK)), Int64(0)); } inline GateRef Stub::TaggedIsGeneratorObject(GateRef x) @@ -632,7 +646,7 @@ inline GateRef Stub::TaggedIsPropertyBox(GateRef x) inline GateRef Stub::TaggedIsWeak(GateRef x) { - return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_WEAK)), Int64(1)); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_WEAK_MARK)), Int64(JSTaggedValue::TAG_WEAK)); } inline GateRef Stub::TaggedIsPrototypeHandler(GateRef x) @@ -677,8 +691,8 @@ inline GateRef Stub::TaggedIsNull(GateRef x) inline GateRef Stub::TaggedIsUndefinedOrNull(GateRef x) { - return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_BOOLEAN)), - Int64(JSTaggedValue::TAG_SPECIAL_VALUE)); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_MARK)), + Int64(JSTaggedValue::TAG_SPECIAL)); } inline GateRef Stub::TaggedIsTrue(GateRef x) @@ -693,42 +707,42 @@ inline GateRef Stub::TaggedIsFalse(GateRef x) inline GateRef Stub::TaggedIsBoolean(GateRef x) { - return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_BOOLEAN)), - Int64(JSTaggedValue::TAG_BOOLEAN_MASK)); + return Int64Equal(Int64And(x, Int64(JSTaggedValue::TAG_HEAPOBJECT_MARK)), + Int64(JSTaggedValue::TAG_BOOLEAN_MARK)); } inline GateRef Stub::TaggedGetInt(GateRef x) { - return TruncInt64ToInt32(Int64And(x, Int64(~JSTaggedValue::TAG_MASK))); + return TruncInt64ToInt32(Int64And(x, Int64(~JSTaggedValue::TAG_MARK))); } -inline GateRef Stub::Int8BuildTaggedTypeWithNoGC(GateRef x) +inline GateRef Stub::Int8ToTaggedTypeNGC(GateRef x) { - GateRef val = ZExtInt8ToInt64(x); + GateRef val = SExtInt8ToInt64(x); return Int64Or(val, Int64(JSTaggedValue::TAG_INT)); } -inline GateRef Stub::Int16BuildTaggedWithNoGC(GateRef x) +inline GateRef Stub::Int16ToTaggedNGC(GateRef x) { - GateRef val = ZExtInt16ToInt64(x); + GateRef val = SExtInt16ToInt64(x); return ChangeInt64ToTagged(Int64Or(val, Int64(JSTaggedValue::TAG_INT))); } -inline GateRef Stub::Int16BuildTaggedTypeWithNoGC(GateRef x) +inline GateRef Stub::Int16ToTaggedTypeNGC(GateRef x) { - GateRef val = ZExtInt16ToInt64(x); + GateRef val = SExtInt16ToInt64(x); return Int64Or(val, Int64(JSTaggedValue::TAG_INT)); } -inline GateRef Stub::IntBuildTaggedWithNoGC(GateRef x) +inline GateRef Stub::IntToTaggedNGC(GateRef x) { - GateRef val = ZExtInt32ToInt64(x); + GateRef val = SExtInt32ToInt64(x); return ChangeInt64ToTagged(Int64Or(val, Int64(JSTaggedValue::TAG_INT))); } -inline GateRef Stub::IntBuildTaggedTypeWithNoGC(GateRef x) +inline GateRef Stub::IntToTaggedTypeNGC(GateRef x) { - GateRef val = ZExtInt32ToInt64(x); + GateRef val = SExtInt32ToInt64(x); return Int64Or(val, Int64(JSTaggedValue::TAG_INT)); } @@ -999,20 +1013,6 @@ inline GateRef Stub::IsDictionaryElement(GateRef hClass) Int32(0)); } -inline GateRef Stub::NotBuiltinsConstructor(GateRef object) -{ - GateRef hclass = LoadHClass(object); - GateRef bitfieldOffset = IntPtr(JSHClass::BIT_FIELD_OFFSET); - - GateRef bitfield = Load(VariableType::INT32(), hclass, bitfieldOffset); - // decode - return Int32Equal( - Int32And( - Int32LSR(bitfield, Int32(JSHClass::BuiltinsCtorBit::START_BIT)), - Int32((1LU << JSHClass::BuiltinsCtorBit::SIZE) - 1)), - Int32(0)); -} - inline GateRef Stub::IsClassConstructorFromBitField(GateRef bitfield) { // decode @@ -1119,19 +1119,6 @@ inline GateRef Stub::IsConstructor(GateRef object) Int32(0)); } -inline GateRef Stub::IsBuiltinsConstructor(GateRef object) -{ - GateRef hClass = LoadHClass(object); - GateRef bitfieldOffset = IntPtr(JSHClass::BIT_FIELD_OFFSET); - - GateRef bitfield = Load(VariableType::INT32(), hClass, bitfieldOffset); - // decode - return Int32NotEqual( - Int32And(Int32LSR(bitfield, Int32(JSHClass::BuiltinsCtorBit::START_BIT)), - Int32((1LU << JSHClass::BuiltinsCtorBit::SIZE) - 1)), - Int32(0)); -} - inline GateRef Stub::IsBase(GateRef func) { GateRef bitfieldOffset = IntPtr(JSFunction::BIT_FIELD_OFFSET); @@ -1527,11 +1514,19 @@ inline GateRef Stub::IsSpecialIndexedObj(GateRef jsType) inline GateRef Stub::IsSpecialContainer(GateRef jsType) { - // arraylist and vector has fast pass now + // arraylist and vector has fast pass now + return TruncInt32ToInt1(Int32And( + ZExtInt1ToInt32( + Int32Equal(jsType, Int32(static_cast(JSType::JS_API_ARRAY_LIST)))), + ZExtInt1ToInt32(Int32Equal(jsType, Int32(static_cast(JSType::JS_API_VECTOR)))))); +} + +inline GateRef Stub::IsFastTypeArray(GateRef jsType) +{ return TruncInt32ToInt1(Int32And( ZExtInt1ToInt32( - Int32GreaterThanOrEqual(jsType, Int32(static_cast(JSType::JS_API_ARRAY_LIST)))), - ZExtInt1ToInt32(Int32LessThanOrEqual(jsType, Int32(static_cast(JSType::JS_API_QUEUE)))))); + Int32GreaterThanOrEqual(jsType, Int32(static_cast(JSType::JS_TYPED_ARRAY_BEGIN)))), + ZExtInt1ToInt32(Int32LessThanOrEqual(jsType, Int32(static_cast(JSType::JS_FLOAT64_ARRAY)))))); } inline GateRef Stub::IsAccessorInternal(GateRef value) @@ -1571,7 +1566,7 @@ inline GateRef Stub::GetPropertiesAddrFromLayoutInfo(GateRef layout) inline GateRef Stub::TaggedCastToInt64(GateRef x) { GateRef tagged = ChangeTaggedPointerToInt64(x); - return Int64And(tagged, Int64(~JSTaggedValue::TAG_MASK)); + return Int64And(tagged, Int64(~JSTaggedValue::TAG_MARK)); } inline GateRef Stub::TaggedCastToInt32(GateRef x) @@ -1594,7 +1589,7 @@ inline GateRef Stub::TaggedCastToDouble(GateRef x) inline GateRef Stub::TaggedCastToWeakReferentUnChecked(GateRef x) { x = ChangeTaggedPointerToInt64(x); - return Int64And(x, Int64(~JSTaggedValue::TAG_WEAK_MASK)); + return Int64And(x, Int64(~JSTaggedValue::TAG_WEAK)); } inline GateRef Stub::ChangeInt32ToFloat64(GateRef x) @@ -1632,6 +1627,16 @@ inline GateRef Stub::SExtInt32ToInt64(GateRef x) return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x); } +inline GateRef Stub::SExtInt16ToInt64(GateRef x) +{ + return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x); +} + +inline GateRef Stub::SExtInt8ToInt64(GateRef x) +{ + return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x); +} + inline GateRef Stub::SExtInt1ToInt64(GateRef x) { return env_.GetBulder()->UnaryArithmetic(OpCode(OpCode::SEXT_TO_INT64), x); @@ -2015,7 +2020,8 @@ inline GateRef Stub::GetGlobalConstantValue(VariableType type, GateRef glue, Con inline GateRef Stub::HasPendingException(GateRef glue) { - GateRef exception = Load(VariableType::JS_ANY(), glue); + GateRef exceptionOffset = IntPtr(JSThread::GlueData::GetExceptionOffset(env_.IsArch32Bit())); + GateRef exception = Load(VariableType::JS_ANY(), glue, exceptionOffset); return Int64NotEqual(exception, Int64(JSTaggedValue::VALUE_HOLE)); } } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/stub.cpp b/ecmascript/compiler/stub.cpp index ffcf0219528964d3b875be0f1b15056dd9c12606..80495f93caa7346c345d765fc37326f16d0dc851 100644 --- a/ecmascript/compiler/stub.cpp +++ b/ecmascript/compiler/stub.cpp @@ -155,7 +155,7 @@ GateRef Stub::FindElementWithCache(GateRef glue, GateRef layoutInfo, GateRef hCl Jump(&afterExceedCon); } Bind(&afterExceedCon); - result = CallNGCRuntime(glue, RTSTUB_ID(FindElementWithCache), { glue, hClass, key, propsNum }); + result = UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(FindElementWithCache), { glue, hClass, key, propsNum }); Jump(&exit); Bind(&exit); auto ret = *result; @@ -179,7 +179,7 @@ GateRef Stub::FindElementFromNumberDictionary(GateRef glue, GateRef elements, Ga DEFVARIABLE(count, VariableType::INT32(), Int32(1)); GateRef len = Int32(sizeof(int) / sizeof(uint8_t)); GateRef hash = CallRuntime(glue, RTSTUB_ID(GetHash32), - { IntBuildTaggedTypeWithNoGC(index), IntBuildTaggedTypeWithNoGC(len) }); + { IntToTaggedTypeNGC(index), IntToTaggedTypeNGC(len) }); DEFVARIABLE(entry, VariableType::INT32(), Int32And(TruncInt64ToInt32(ChangeTaggedPointerToInt64(hash)), Int32Sub(capacity, Int32(1)))); Label loopHead(env); @@ -575,7 +575,7 @@ GateRef Stub::CallGetterHelper(GateRef glue, GateRef receiver, GateRef holder, G } Bind(&objNotUndefined); { - auto retValue = JSCallDispatch(glue, getter, IntPtr(0), + auto retValue = JSCallDispatch(glue, getter, Int32(0), JSCallMode::CALL_GETTER, { receiver }); Label noPendingException(env); Branch(HasPendingException(glue), &exit, &noPendingException); @@ -615,15 +615,15 @@ GateRef Stub::CallSetterHelper(GateRef glue, GateRef receiver, GateRef accessor, Label objIsUndefined(env); Label objNotUndefined(env); Branch(TaggedIsUndefined(setter), &objIsUndefined, &objNotUndefined); - // if getter is undefined, return undefiend Bind(&objIsUndefined); { - result = Undefined(); + CallRuntime(glue, RTSTUB_ID(ThrowSetterIsUndefinedException), {}); + result = Exception(); Jump(&exit); } Bind(&objNotUndefined); { - auto retValue = JSCallDispatch(glue, setter, IntPtr(1), + auto retValue = JSCallDispatch(glue, setter, Int32(1), JSCallMode::CALL_SETTER, { receiver, value }); Label noPendingException(env); Branch(HasPendingException(glue), &exit, &noPendingException); @@ -700,11 +700,11 @@ void Stub::JSHClassAddProperty(GateRef glue, GateRef receiver, GateRef key, Gate Int32(JSTaggedValue::TaggedTypeSize())); GateRef inlineProps = GetInlinedPropertiesFromHClass(hclass); GateRef newJshclass = CallRuntime(glue, RTSTUB_ID(NewEcmaDynClass), - { IntBuildTaggedTypeWithNoGC(size), IntBuildTaggedTypeWithNoGC(type), - IntBuildTaggedTypeWithNoGC(inlineProps) }); + { IntToTaggedTypeNGC(size), IntToTaggedTypeNGC(type), + IntToTaggedTypeNGC(inlineProps) }); CopyAllHClass(glue, newJshclass, hclass); CallRuntime(glue, RTSTUB_ID(UpdateLayOutAndAddTransition), - { hclass, newJshclass, key, IntBuildTaggedTypeWithNoGC(attr) }); + { hclass, newJshclass, key, IntToTaggedTypeNGC(attr) }); #if ECMASCRIPT_ENABLE_IC NotifyHClassChanged(glue, hclass, newJshclass); #endif @@ -785,7 +785,7 @@ GateRef Stub::AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(&lenIsZero); { length = Int32(JSObject::MIN_PROPERTIES_LENGTH); - array = CallRuntime(glue, RTSTUB_ID(NewTaggedArray), { IntBuildTaggedTypeWithNoGC(*length) }); + array = CallRuntime(glue, RTSTUB_ID(NewTaggedArray), { IntToTaggedTypeNGC(*length) }); SetPropertiesArray(VariableType::JS_POINTER(), glue, receiver, *array); Jump(&afterLenCon); } @@ -800,7 +800,7 @@ GateRef Stub::AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(&isDictMode); { GateRef res = CallRuntime(glue, RTSTUB_ID(NameDictPutIfAbsent), - {receiver, *array, key, value, IntBuildTaggedTypeWithNoGC(*attr), TaggedFalse()}); + {receiver, *array, key, value, IntToTaggedTypeNGC(*attr), TaggedFalse()}); SetPropertiesArray(VariableType::JS_POINTER(), glue, receiver, res); Jump(&exit); } @@ -826,7 +826,7 @@ GateRef Stub::AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat attr = SetDictionaryOrderFieldInPropAttr(*attr, Int32(PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES)); GateRef res = CallRuntime(glue, RTSTUB_ID(NameDictPutIfAbsent), - { receiver, *array, key, value, IntBuildTaggedTypeWithNoGC(*attr), TaggedTrue() }); + { receiver, *array, key, value, IntToTaggedTypeNGC(*attr), TaggedTrue() }); SetPropertiesArray(VariableType::JS_POINTER(), glue, receiver, res); result = Undefined(VariableType::INT64()); Jump(&exit); @@ -837,7 +837,7 @@ GateRef Stub::AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(&afterDictChangeCon); GateRef capacity = ComputePropertyCapacityInJSObj(*length); array = CallRuntime(glue, RTSTUB_ID(CopyArray), - { *array, IntBuildTaggedTypeWithNoGC(*length), IntBuildTaggedTypeWithNoGC(capacity) }); + { *array, IntToTaggedTypeNGC(*length), IntToTaggedTypeNGC(capacity) }); SetPropertiesArray(VariableType::JS_POINTER(), glue, receiver, *array); Jump(&afterArrLenCon); } @@ -862,7 +862,7 @@ GateRef Stub::AddPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat void Stub::ThrowTypeAndReturn(GateRef glue, int messageId, GateRef val) { GateRef msgIntId = Int32(messageId); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(msgIntId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(msgIntId) }); Return(val); } @@ -978,7 +978,7 @@ void Stub::SetValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRe } Bind(&isNullPtr); { - CallNGCRuntime(glue, + UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(InsertOldToNewRSet), { glue, objectRegion, slotAddr }); Jump(¬ValidIndex); @@ -994,7 +994,7 @@ void Stub::SetValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRe Branch(Int64Equal(stateBitField, Int64(0)), &exit, &marking); Bind(&marking); - CallNGCRuntime(glue, + UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(MarkingBarrier), { glue, slotAddr, objectRegion, TaggedCastToIntPtr(value), valueRegion }); Jump(&exit); @@ -1452,7 +1452,7 @@ GateRef Stub::LoadElement(GateRef receiver, GateRef key) Label lengthNotLessIndex(env); DEFVARIABLE(result, VariableType::JS_ANY(), Hole()); GateRef index = TryToElementsIndex(key); - Branch(Int32UnsignedLessThan(index, Int32(0)), &indexLessZero, &indexNotLessZero); + Branch(Int32LessThan(index, Int32(0)), &indexLessZero, &indexNotLessZero); Bind(&indexLessZero); { Jump(&exit); @@ -1496,7 +1496,7 @@ GateRef Stub::ICStoreElement(GateRef glue, GateRef receiver, GateRef key, GateRe DEFVARIABLE(result, VariableType::INT64(), Hole(VariableType::INT64())); DEFVARIABLE(varHandler, VariableType::JS_ANY(), handler); GateRef index = TryToElementsIndex(key); - Branch(Int32UnsignedLessThan(index, Int32(0)), &indexLessZero, &indexNotLessZero); + Branch(Int32LessThan(index, Int32(0)), &indexLessZero, &indexNotLessZero); Bind(&indexLessZero); { Jump(&exit); @@ -1517,7 +1517,7 @@ GateRef Stub::ICStoreElement(GateRef glue, GateRef receiver, GateRef key, GateRe Bind(&indexGreaterLength); Store(VariableType::INT64(), glue, receiver, IntPtr(panda::ecmascript::JSArray::LENGTH_OFFSET), - IntBuildTaggedWithNoGC(Int32Add(index, Int32(1)))); + IntToTaggedNGC(Int32Add(index, Int32(1)))); Jump(&handerInfoNotJSArray); } Bind(&handerInfoNotJSArray); @@ -1529,8 +1529,8 @@ GateRef Stub::ICStoreElement(GateRef glue, GateRef receiver, GateRef key, GateRe { result = ChangeTaggedPointerToInt64(CallRuntime(glue, RTSTUB_ID(TaggedArraySetValue), - { receiver, value, elements, IntBuildTaggedTypeWithNoGC(index), - IntBuildTaggedTypeWithNoGC(capacity) })); + { receiver, value, elements, IntToTaggedTypeNGC(index), + IntToTaggedTypeNGC(capacity) })); Jump(&exit); } Bind(&storeElement); @@ -1729,8 +1729,8 @@ void Stub::StoreWithTransition(GateRef glue, GateRef receiver, GateRef value, Ga { CallRuntime(glue, RTSTUB_ID(PropertiesSetValue), - { receiver, value, array, IntBuildTaggedTypeWithNoGC(capacity), - IntBuildTaggedTypeWithNoGC(index) }); + { receiver, value, array, IntToTaggedTypeNGC(capacity), + IntToTaggedTypeNGC(index) }); Jump(&exit); } Bind(&indexLessCapacity); @@ -1844,7 +1844,7 @@ inline void Stub::UpdateValueAndAttributes(GateRef glue, GateRef elements, GateR GateRef attroffset = PtrMul(ChangeInt32ToIntPtr(attributesIndex), IntPtr(JSTaggedValue::TaggedTypeSize())); GateRef dataOffset = PtrAdd(attroffset, IntPtr(TaggedArray::DATA_OFFSET)); - Store(VariableType::INT64(), glue, elements, dataOffset, IntBuildTaggedWithNoGC(attr)); + Store(VariableType::INT64(), glue, elements, dataOffset, IntToTaggedNGC(attr)); } inline void Stub::UpdateValueInDict(GateRef glue, GateRef elements, GateRef index, GateRef value) @@ -1877,6 +1877,18 @@ GateRef Stub::GetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index) Branch(IsSpecialIndexedObj(jsType), &isSpecialIndexed, ¬SpecialIndexed); Bind(&isSpecialIndexed); { + // TypeArray + Label isFastTypeArray(env); + Label notFastTypeArray(env); + Branch(IsFastTypeArray(jsType), &isFastTypeArray, ¬FastTypeArray); + Bind(&isFastTypeArray); + { + result = CallRuntime(glue, RTSTUB_ID(GetTypeArrayPropertyByIndex), + { *holder, IntToTaggedTypeNGC(index), IntToTaggedTypeNGC(jsType)}); + Jump(&exit); + } + Bind(¬FastTypeArray); + Label isSpecialContainer(env); Label notSpecialContainer(env); // Add SpecialContainer @@ -1973,6 +1985,81 @@ GateRef Stub::GetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index) return ret; } +GateRef Stub::GetPropertyByValue(GateRef glue, GateRef receiver, GateRef keyValue) +{ + auto env = GetEnvironment(); + Label entry(env); + env->SubCfgEntry(&entry); + DEFVARIABLE(key, VariableType::JS_ANY(), keyValue); + DEFVARIABLE(result, VariableType::JS_ANY(), Hole()); + Label isNumberOrStringSymbol(env); + Label notNumber(env); + Label isStringOrSymbol(env); + Label notStringOrSymbol(env); + Label exit(env); + + Branch(TaggedIsNumber(*key), &isNumberOrStringSymbol, ¬Number); + Bind(¬Number); + { + Branch(TaggedIsStringOrSymbol(*key), &isNumberOrStringSymbol, ¬StringOrSymbol); + Bind(¬StringOrSymbol); + { + result = Hole(); + Jump(&exit); + } + } + Bind(&isNumberOrStringSymbol); + { + GateRef index = TryToElementsIndex(*key); + Label validIndex(env); + Label notValidIndex(env); + Branch(Int32GreaterThanOrEqual(index, Int32(0)), &validIndex, ¬ValidIndex); + Bind(&validIndex); + { + result = GetPropertyByIndex(glue, receiver, index); + Jump(&exit); + } + Bind(¬ValidIndex); + { + Label notNumber1(env); + Label getByName(env); + Branch(TaggedIsNumber(*key), &exit, ¬Number1); + Bind(¬Number1); + { + Label isString(env); + Label notString(env); + Label isInternalString(env); + Label notIntenalString(env); + Branch(TaggedIsString(*key), &isString, ¬String); + Bind(&isString); + { + Branch(IsInternalString(*key), &isInternalString, ¬IntenalString); + Bind(&isInternalString); + Jump(&getByName); + Bind(¬IntenalString); + { + key = CallRuntime(glue, RTSTUB_ID(NewInternalString), { *key }); + Jump(&getByName); + } + } + Bind(¬String); + { + Jump(&getByName); + } + } + Bind(&getByName); + { + result = GetPropertyByName(glue, receiver, *key); + Jump(&exit); + } + } + } + Bind(&exit); + auto ret = *result; + env->SubCfgExit(); + return ret; +} + GateRef Stub::GetPropertyByName(GateRef glue, GateRef receiver, GateRef key) { auto env = GetEnvironment(); @@ -1995,8 +2082,29 @@ GateRef Stub::GetPropertyByName(GateRef glue, GateRef receiver, GateRef key) Branch(IsSpecialIndexedObj(jsType), &isSIndexObj, ¬SIndexObj); Bind(&isSIndexObj); { - result = Hole(); - Jump(&exit); + // TypeArray + Label isFastTypeArray(env); + Label notFastTypeArray(env); + Branch(IsFastTypeArray(jsType), &isFastTypeArray, ¬FastTypeArray); + Bind(&isFastTypeArray); + { + result = GetTypeArrayPropertyByName(glue, receiver, *holder, key, jsType); + Label isNull(env); + Label notNull(env); + Branch(TaggedIsNull(*result), &isNull, ¬Null); + Bind(&isNull); + { + result = Hole(); + Jump(&exit); + } + Bind(¬Null); + Branch(TaggedIsHole(*result), ¬SIndexObj, &exit); + } + Bind(¬FastTypeArray); + { + result = Hole(); + Jump(&exit); + } } Bind(¬SIndexObj); { @@ -2220,6 +2328,17 @@ GateRef Stub::SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index, Branch(IsSpecialIndexedObj(jsType), &isSpecialIndex, ¬SpecialIndex); Bind(&isSpecialIndex); { + // TypeArray + Label isFastTypeArray(env); + Label notFastTypeArray(env); + Branch(IsFastTypeArray(jsType), &isFastTypeArray, ¬FastTypeArray); + Bind(&isFastTypeArray); + { + returnValue = ChangeTaggedPointerToInt64(CallRuntime(glue, RTSTUB_ID(SetTypeArrayPropertyByIndex), + { receiver, IntToTaggedTypeNGC(index), value, IntToTaggedTypeNGC(jsType)})); + Jump(&exit); + } + Bind(¬FastTypeArray); returnValue = Hole(VariableType::INT64()); Jump(&exit); } @@ -2288,8 +2407,8 @@ GateRef Stub::SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index, Bind(&isExtensible); { GateRef result = CallRuntime(glue, RTSTUB_ID(AddElementInternal), - { receiver, IntBuildTaggedTypeWithNoGC(index), value, - IntBuildTaggedTypeWithNoGC(Int32(PropertyAttributes::GetDefaultAttributes())) }); + { receiver, IntToTaggedTypeNGC(index), value, + IntToTaggedTypeNGC(Int32(PropertyAttributes::GetDefaultAttributes())) }); Label success(env); Label failed(env); Branch(TaggedIsTrue(result), &success, &failed); @@ -2307,7 +2426,7 @@ GateRef Stub::SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index, Bind(¬Extensible); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(SetPropertyWhenNotExtensible)); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(taggedId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(taggedId) }); returnValue = Exception(VariableType::INT64()); Jump(&exit); } @@ -2345,6 +2464,26 @@ GateRef Stub::SetPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Branch(IsSpecialIndexedObj(jsType), &isSIndexObj, ¬SIndexObj); Bind(&isSIndexObj); { + Label isFastTypeArray(env); + Label notFastTypeArray(env); + Branch(IsFastTypeArray(jsType), &isFastTypeArray, ¬FastTypeArray); + Bind(&isFastTypeArray); + { + result = + ChangeTaggedPointerToInt64(SetTypeArrayPropertyByName(glue, receiver, *holder, key, value, jsType)); + Label isNull(env); + Label notNull(env); + Branch(TaggedIsNull(*result), &isNull, ¬Null); + Bind(&isNull); + { + result = Hole(VariableType::INT64()); + Jump(&exit); + } + Bind(¬Null); + Branch(TaggedIsHole(*result), ¬SIndexObj, &exit); + } + Bind(¬FastTypeArray); + Label isSpecialContainer(env); Label notSpecialContainer(env); // Add SpecialContainer @@ -2352,7 +2491,7 @@ GateRef Stub::SetPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(&isSpecialContainer); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(CanNotSetPropertyOnContainer)); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(taggedId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(taggedId) }); result = Exception(VariableType::INT64()); Jump(&exit); } @@ -2412,7 +2551,7 @@ GateRef Stub::SetPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(¬Writable); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(SetReadOnlyProperty)); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(taggedId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(taggedId) }); result = Exception(VariableType::INT64()); Jump(&exit); } @@ -2477,7 +2616,7 @@ GateRef Stub::SetPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(¬Writable1); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(SetReadOnlyProperty)); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(taggedId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(taggedId) }); result = Exception(VariableType::INT64()); Jump(&exit); } @@ -2522,7 +2661,7 @@ GateRef Stub::SetPropertyByName(GateRef glue, GateRef receiver, GateRef key, Gat Bind(&inextensible); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(SetPropertyWhenNotExtensible)); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(taggedId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(taggedId) }); result = Exception(VariableType::INT64()); Jump(&exit); } @@ -2640,7 +2779,7 @@ GateRef Stub::GetContainerProperty(GateRef glue, GateRef receiver, GateRef index Label entry(env); env->SubCfgEntry(&entry); Label exit(env); - DEFVARIABLE(result, VariableType::JS_ANY(), Undefined()); + DEFVARIABLE(result, VariableType::JS_ANY(), Hole()); Label isDefaultLabel(env); Label noDefaultLabel(env); @@ -2888,7 +3027,7 @@ GateRef Stub::FastStrictEqual(GateRef glue, GateRef left, GateRef right) &exit); Bind(&contentsCompare); { - result = CallNGCRuntime(glue, RTSTUB_ID(StringsAreEquals), { left, right }); + result = UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(StringsAreEquals), { left, right }); Jump(&exit); } } @@ -2902,7 +3041,7 @@ GateRef Stub::FastStrictEqual(GateRef glue, GateRef left, GateRef right) Label rightIsBigInt(env); Branch(TaggedIsBigInt(right), &rightIsBigInt, &exit); Bind(&rightIsBigInt); - result = CallNGCRuntime(glue, RTSTUB_ID(BigIntEquals), { left, right }); + result = UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(BigIntEquals), { left, right }); Jump(&exit); } } @@ -3065,13 +3204,13 @@ GateRef Stub::FastToBoolean(GateRef value) Branch(IsBigInt(value), &isBigint, &returnTrue); Bind(&isBigint); { - auto data = Load(VariableType::JS_POINTER(), value, IntPtr(BigInt::DATA_OFFSET)); - auto len = GetLengthOfTaggedArray(data); + auto len = Load(VariableType::INT32(), value, IntPtr(BigInt::LENGTH_OFFSET)); Branch(Int32Equal(len, Int32(1)), &lengthIsOne, &returnTrue); Bind(&lengthIsOne); { - auto data0 = GetValueFromTaggedArray(VariableType::JS_POINTER(), data, Int32(0)); - Branch(Int64Equal(data0, Int64(JSTaggedValue::VALUE_ZERO)), &returnFalse, &returnTrue); + auto data = PtrAdd(value, IntPtr(BigInt::DATA_OFFSET)); + auto data0 = Load(VariableType::INT32(), data, Int32(0)); + Branch(Int32Equal(data0, Int32(0)), &returnFalse, &returnTrue); } } } @@ -3313,7 +3452,7 @@ GateRef Stub::FastAddSubAndMul(GateRef left, GateRef right) } Bind(¬Overflow); { - result = IntBuildTaggedWithNoGC(ChangeInt64ToInt32(res)); + result = IntToTaggedNGC(ChangeInt64ToInt32(res)); Jump(&exit); } Bind(&exit); @@ -3373,7 +3512,7 @@ GateRef Stub::FastMod(GateRef glue, GateRef left, GateRef right) Branch(Int32GreaterThan(*intRight, Int32(0)), &rightGreaterZero, &leftNotIntOrRightNotInt); Bind(&rightGreaterZero); { - result = IntBuildTaggedWithNoGC(Int32Mod(*intLeft, *intRight)); + result = IntToTaggedNGC(Int32Mod(*intLeft, *intRight)); Jump(&exit); } } @@ -3464,7 +3603,8 @@ GateRef Stub::FastMod(GateRef glue, GateRef left, GateRef right) Branch(DoubleIsINF(*doubleRight), &leftIsZeroOrRightIsInf, &rightNotInf); Bind(&rightNotInf); { - result = CallNGCRuntime(glue, RTSTUB_ID(FloatMod), { *doubleLeft, *doubleRight }); + result = UpdateLeaveFrameAndCallNGCRuntime( + glue, RTSTUB_ID(FloatMod), { *doubleLeft, *doubleRight }); Jump(&exit); } } @@ -3510,7 +3650,7 @@ GateRef Stub::JSAPIContainerGet(GateRef glue, GateRef receiver, GateRef index) Label entry(env); env->SubCfgEntry(&entry); Label exit(env); - DEFVARIABLE(result, VariableType::JS_ANY(), Undefined()); + DEFVARIABLE(result, VariableType::JS_ANY(), Hole()); GateRef lengthOffset = IntPtr(panda::ecmascript::JSAPIArrayList::LENGTH_OFFSET); GateRef length = TaggedCastToInt32(Load(VariableType::INT64(), receiver, lengthOffset)); @@ -3527,7 +3667,7 @@ GateRef Stub::JSAPIContainerGet(GateRef glue, GateRef receiver, GateRef index) Bind(¬ValidIndex); { GateRef taggedId = Int32(GET_MESSAGE_STRING_ID(GetPropertyOutOfBounds)); - CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntBuildTaggedTypeWithNoGC(taggedId) }); + CallRuntime(glue, RTSTUB_ID(ThrowTypeError), { IntToTaggedTypeNGC(taggedId) }); result = Exception(); Jump(&exit); } @@ -3564,7 +3704,7 @@ GateRef Stub::DoubleToInt(GateRef glue, GateRef x) } Bind(&overflow); { - result = CallNGCRuntime(glue, RTSTUB_ID(DoubleToInt), { x }); + result = UpdateLeaveFrameAndCallNGCRuntime(glue, RTSTUB_ID(DoubleToInt), { x }); Jump(&exit); } Bind(&exit); @@ -3580,7 +3720,8 @@ void Stub::ReturnExceptionIfAbruptCompletion(GateRef glue) env->SubCfgEntry(&entry); Label exit(env); Label hasPendingException(env); - GateRef exception = Load(VariableType::JS_ANY(), glue); + GateRef exceptionOffset = IntPtr(JSThread::GlueData::GetExceptionOffset(env->IsArch32Bit())); + GateRef exception = Load(VariableType::JS_ANY(), glue, exceptionOffset); Branch(Int64NotEqual(exception, Int64(JSTaggedValue::VALUE_HOLE)), &hasPendingException, &exit); Bind(&hasPendingException); Return(Exception()); @@ -3641,7 +3782,7 @@ GateRef Stub::AllocateInYoung(GateRef glue, GateRef size) Bind(&callRuntime); { result = CallRuntime(glue, RTSTUB_ID(AllocateInYoung), { - IntBuildTaggedTypeWithNoGC(size) }); + IntToTaggedTypeNGC(size) }); Jump(&exit); } Bind(&exit); @@ -3808,22 +3949,23 @@ GateRef Stub::JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, IntPtr(JSMethod::GetBytecodeArrayOffset(env->IsArch32Bit()))); GateRef newTarget = Undefined(); GateRef thisValue = Undefined(); + actualNumArgs = Int32Add(actualNumArgs, Int32(NUM_MANDATORY_JSFUNC_ARGS)); switch (mode) { case JSCallMode::CALL_ARG0: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgsAndDispatchNative), - { glue, nativeCode, actualNumArgs, func, newTarget, thisValue }); + { nativeCode, glue, actualNumArgs, func, newTarget, thisValue }); break; case JSCallMode::CALL_ARG1: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgsAndDispatchNative), - { glue, nativeCode, actualNumArgs, func, newTarget, thisValue, data[0]}); + { nativeCode, glue, actualNumArgs, func, newTarget, thisValue, data[0]}); break; case JSCallMode::CALL_ARG2: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgsAndDispatchNative), - { glue, nativeCode, actualNumArgs, func, newTarget, thisValue, data[0], data[1] }); + { nativeCode, glue, actualNumArgs, func, newTarget, thisValue, data[0], data[1] }); break; case JSCallMode::CALL_ARG3: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgsAndDispatchNative), - { glue, nativeCode, actualNumArgs, func, + { nativeCode, glue, actualNumArgs, func, newTarget, thisValue, data[0], data[1], data[2] }); // 2: args2 break; case JSCallMode::CALL_THIS_WITH_ARGV: { @@ -3840,13 +3982,11 @@ GateRef Stub::JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, break; case JSCallMode::CALL_GETTER: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgsAndDispatchNative), - { glue, nativeCode, actualNumArgs, func, - newTarget, data[0] }); + { nativeCode, glue, actualNumArgs, func, newTarget, data[0] }); break; case JSCallMode::CALL_SETTER: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgsAndDispatchNative), - { glue, nativeCode, actualNumArgs, func, - newTarget, data[0], data[1] }); + { nativeCode, glue, actualNumArgs, func, newTarget, data[0], data[1] }); break; default: UNREACHABLE(); @@ -3855,9 +3995,9 @@ GateRef Stub::JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, } // 4. call nonNative Bind(&methodNotNative); + Label funcIsClassConstructor(env); + Label funcNotClassConstructor(env); if (mode != JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV) { - Label funcIsClassConstructor(env); - Label funcNotClassConstructor(env); Branch(IsClassConstructorFromBitField(bitfield), &funcIsClassConstructor, &funcNotClassConstructor); Bind(&funcIsClassConstructor); { @@ -3870,7 +4010,67 @@ GateRef Stub::JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, if (env->IsAsmInterp()) { sp = PtrArgument(static_cast(InterpreterHandlerInputs::SP)); } + Label methodisAot(env); + Label methodNotAot(env); { + GateRef isAotMask = Int64(static_cast(1) << JSMethod::IsAotCodeBit::START_BIT); + Branch(Int64Equal(Int64And(callField, isAotMask), Int64(0)), &methodNotAot, &methodisAot); + Bind(&methodisAot); + { + GateRef newTarget = Undefined(); + GateRef thisValue = Undefined(); + GateRef lexEnv = builder_.GetLexicalEnv(func); + GateRef realNumArgs = Int64Add(ZExtInt32ToInt64(actualNumArgs), Int64(NUM_MANDATORY_JSFUNC_ARGS)); + switch (mode) { + case JSCallMode::CALL_ARG0: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), + { glue, lexEnv, realNumArgs, func, newTarget, thisValue}); + Jump(&exit); + break; + case JSCallMode::CALL_ARG1: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), + { glue, lexEnv, realNumArgs, func, newTarget, thisValue, data[0] }); + Jump(&exit); + break; + case JSCallMode::CALL_ARG2: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), + { glue, lexEnv, realNumArgs, func, newTarget, thisValue, data[0], data[1] }); + Jump(&exit); + break; + case JSCallMode::CALL_ARG3: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), + { glue, lexEnv, realNumArgs, func, newTarget, thisValue, + data[0], data[1], data[2] }); // 2: args2 + Jump(&exit); + break; + case JSCallMode::CALL_THIS_WITH_ARGV: + thisValue = data[2]; // 2: this input + [[fallthrough]]; + case JSCallMode::CALL_WITH_ARGV: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCallWithArgV), + { glue, ZExtInt32ToInt64(actualNumArgs), func, newTarget, thisValue, data[1] }); + Jump(&exit); + break; + case JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCallWithArgV), + { glue, ZExtInt32ToInt64(actualNumArgs), func, func, data[2], data[1]}); + Jump(&exit); + break; + case JSCallMode::CALL_GETTER: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), + { glue, lexEnv, realNumArgs, func, newTarget, data[0]}); + Jump(&exit); + break; + case JSCallMode::CALL_SETTER: + result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), + { glue, lexEnv, realNumArgs, func, newTarget, data[0], data[1]}); + Jump(&exit); + break; + default: + UNREACHABLE(); + } + } + Bind(&methodNotAot); switch (mode) { case JSCallMode::CALL_ARG0: result = CallNGCRuntime(glue, RTSTUB_ID(PushCallArgs0AndDispatch), @@ -3926,4 +4126,226 @@ GateRef Stub::JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, env->SubCfgExit(); return ret; } + +GateRef Stub::TryStringOrSymbelToElementIndex(GateRef key) +{ + auto env = GetEnvironment(); + Label entry(env); + env->SubCfgEntry(&entry); + Label exit(env); + DEFVARIABLE(result, VariableType::INT32(), Int32(-1)); + + Label keyNotSymbol(env); + Branch(IsSymbol(key), &exit, &keyNotSymbol); + Bind(&keyNotSymbol); + + Label greatThanZero(env); + Label inRange(env); + auto len = GetLengthFromString(key); + Branch(Int32Equal(len, Int32(0)), &exit, &greatThanZero); + Bind(&greatThanZero); + Branch(Int32GreaterThan(len, Int32(MAX_INDEX_LEN)), &exit, &inRange); + Bind(&inRange); + { + Label isUtf8(env); + Branch(IsUtf16String(key), &exit, &isUtf8); + Bind(&isUtf8); + + GateRef data = PtrAdd(key, IntPtr(EcmaString::DATA_OFFSET)); + DEFVARIABLE(c, VariableType::INT32(), Int32(0)); + c = ZExtInt8ToInt32(Load(VariableType::INT8(), data)); + Label isDigitZero(env); + Label notDigitZero(env); + Branch(Int32Equal(*c, Int32('0')), &isDigitZero, ¬DigitZero); + Bind(&isDigitZero); + { + Label lengthIsOne(env); + Branch(Int32Equal(len, Int32(1)), &lengthIsOne, &exit); + Bind(&lengthIsOne); + { + result = Int32(0); + Jump(&exit); + } + } + Bind(¬DigitZero); + { + Label isDigit(env); + Label notIsDigit(env); + DEFVARIABLE(i, VariableType::INT32(), Int32(1)); + DEFVARIABLE(n, VariableType::INT32(), Int32Sub(*c, Int32('0'))); + + Branch(IsDigit(*c), &isDigit, ¬IsDigit); + Label loopHead(env); + Label loopEnd(env); + Label afterLoop(env); + Bind(&isDigit); + Branch(Int32UnsignedLessThan(*i, len), &loopHead, &afterLoop); + LoopBegin(&loopHead); + { + c = ZExtInt8ToInt32(Load(VariableType::INT8(), data, ChangeInt32ToIntPtr(*i))); + Label isDigit2(env); + Label notDigit2(env); + Branch(IsDigit(*c), &isDigit2, ¬Digit2); + Bind(&isDigit2); + { + // 10 means the base of digit is 10. + n = Int32Add(Int32Mul(*n, Int32(10)), + Int32Sub(*c, Int32('0'))); + i = Int32Add(*i, Int32(1)); + Branch(Int32UnsignedLessThan(*i, len), &loopEnd, &afterLoop); + } + Bind(¬Digit2); + { + Label hasPoint(env); + Branch(Int32Equal(*c, Int32('.')), &hasPoint, &exit); + Bind(&hasPoint); + { + result = Int32(-2); // -2:return -2 means should goto slow path + Jump(&exit); + } + } + } + Bind(&loopEnd); + LoopEnd(&loopHead); + Bind(&afterLoop); + { + Label lessThanMaxIndex(env); + Branch(Int32UnsignedLessThan(*n, Int32(JSObject::MAX_ELEMENT_INDEX)), + &lessThanMaxIndex, &exit); + Bind(&lessThanMaxIndex); + { + result = *n; + Jump(&exit); + } + } + Bind(¬IsDigit); + { + Label isNegative(env); + Branch(Int32Equal(*c, Int32('-')), &isNegative, &exit); + Bind(&isNegative); + { + result = Int32(-2); // -2:return -2 means should goto slow path + Jump(&exit); + } + } + } + } + Bind(&exit); + auto ret = *result; + env->SubCfgExit(); + return ret; +} + +GateRef Stub::GetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef jsType) +{ + auto env = GetEnvironment(); + Label entry(env); + env->SubCfgEntry(&entry); + Label exit(env); + DEFVARIABLE(result, VariableType::JS_ANY(), Hole()); + + Label notOnProtoChain(env); + Branch(Int64NotEqual(receiver, holder), &exit, ¬OnProtoChain); + Bind(¬OnProtoChain); + + auto negativeZero = GetGlobalConstantValue( + VariableType::JS_POINTER(), glue, ConstantIndex::NEGATIVE_ZERO_STRING_INDEX); + Label isNegativeZero(env); + Label notNegativeZero(env); + Branch(Int64Equal(negativeZero, key), &isNegativeZero, ¬NegativeZero); + Bind(&isNegativeZero); + { + result = Undefined(); + Jump(&exit); + } + Bind(¬NegativeZero); + { + GateRef index = TryStringOrSymbelToElementIndex(key); + Label validIndex(env); + Label notValidIndex(env); + Branch(Int32GreaterThanOrEqual(index, Int32(0)), &validIndex, ¬ValidIndex); + Bind(&validIndex); + { + result = CallRuntime(glue, RTSTUB_ID(GetTypeArrayPropertyByIndex), + { holder, IntToTaggedTypeNGC(index), IntToTaggedTypeNGC(jsType) }); + Jump(&exit); + } + Bind(¬ValidIndex); + { + Label returnNull(env); + Branch(Int32Equal(index, Int32(-2)), &returnNull, &exit); // -2:equal -2 means should goto slow path + Bind(&returnNull); + { + result = Null(); + Jump(&exit); + } + } + } + + Bind(&exit); + auto ret = *result; + env->SubCfgExit(); + return ret; +} + +GateRef Stub::SetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef value, + GateRef jsType) +{ + auto env = GetEnvironment(); + Label entry(env); + env->SubCfgEntry(&entry); + Label exit(env); + DEFVARIABLE(result, VariableType::JS_ANY(), Hole()); + Label notOnProtoChain(env); + Branch(Int64NotEqual(receiver, holder), &exit, ¬OnProtoChain); + Bind(¬OnProtoChain); + + auto negativeZero = GetGlobalConstantValue( + VariableType::JS_POINTER(), glue, ConstantIndex::NEGATIVE_ZERO_STRING_INDEX); + Label isNegativeZero(env); + Label notNegativeZero(env); + Branch(Int64Equal(negativeZero, key), &isNegativeZero, ¬NegativeZero); + Bind(&isNegativeZero); + { + Label isObj(env); + Label notObj(env); + Branch(TaggedObjectIsEcmaObject(value), &isObj, ¬Obj); + Bind(&isObj); + { + result = Null(); + Jump(&exit); + } + Bind(¬Obj); + result = Undefined(); + Jump(&exit); + } + Bind(¬NegativeZero); + { + GateRef index = TryStringOrSymbelToElementIndex(key); + Label validIndex(env); + Label notValidIndex(env); + Branch(Int32GreaterThanOrEqual(index, Int32(0)), &validIndex, ¬ValidIndex); + Bind(&validIndex); + { + result = CallRuntime(glue, RTSTUB_ID(SetTypeArrayPropertyByIndex), + { receiver, IntToTaggedTypeNGC(index), value, IntToTaggedTypeNGC(jsType) }); + Jump(&exit); + } + Bind(¬ValidIndex); + { + Label returnNull(env); + Branch(Int32Equal(index, Int32(-2)), &returnNull, &exit); // -2:equal -2 means should goto slow path + Bind(&returnNull); + { + result = Null(); + Jump(&exit); + } + } + } + + Bind(&exit); + auto ret = *result; + env->SubCfgExit(); + return ret; +} } // namespace panda::ecmascript::kungfu diff --git a/ecmascript/compiler/stub.h b/ecmascript/compiler/stub.h index 33678217e43955ee1b5160856211db8c3047cd2f..7b8f7d8cfc05c287d44019706c3f472a903cc6f9 100644 --- a/ecmascript/compiler/stub.h +++ b/ecmascript/compiler/stub.h @@ -99,6 +99,7 @@ public: GateRef CallRuntime(GateRef glue, int index, const std::initializer_list& args); GateRef CallRuntime(GateRef glue, int index, GateRef argc, GateRef argv); GateRef CallNGCRuntime(GateRef glue, int index, const std::initializer_list& args); + GateRef UpdateLeaveFrameAndCallNGCRuntime(GateRef glue, int index, const std::initializer_list& args); GateRef CallStub(GateRef glue, int index, const std::initializer_list& args); void DebugPrint(GateRef thread, std::initializer_list args); void FatalPrint(GateRef thread, std::initializer_list args); @@ -182,11 +183,11 @@ public: GateRef TaggedIsFalse(GateRef x); GateRef TaggedIsBoolean(GateRef x); GateRef TaggedGetInt(GateRef x); - GateRef Int8BuildTaggedTypeWithNoGC(GateRef x); - GateRef Int16BuildTaggedWithNoGC(GateRef x); - GateRef Int16BuildTaggedTypeWithNoGC(GateRef x); - GateRef IntBuildTaggedWithNoGC(GateRef x); - GateRef IntBuildTaggedTypeWithNoGC(GateRef x); + GateRef Int8ToTaggedTypeNGC(GateRef x); + GateRef Int16ToTaggedNGC(GateRef x); + GateRef Int16ToTaggedTypeNGC(GateRef x); + GateRef IntToTaggedNGC(GateRef x); + GateRef IntToTaggedTypeNGC(GateRef x); GateRef DoubleBuildTaggedWithNoGC(GateRef x); GateRef DoubleBuildTaggedTypeWithNoGC(GateRef x); GateRef CastDoubleToInt64(GateRef x); @@ -240,7 +241,6 @@ public: GateRef IsDictionaryMode(GateRef object); GateRef IsDictionaryModeByHClass(GateRef hClass); GateRef IsDictionaryElement(GateRef hClass); - GateRef NotBuiltinsConstructor(GateRef object); GateRef IsClassConstructorFromBitField(GateRef bitfield); GateRef IsClassConstructor(GateRef object); GateRef IsClassPrototype(GateRef object); @@ -253,7 +253,6 @@ public: GateRef IsJsProxy(GateRef obj); GateRef IsJSFunctionBase(GateRef obj); GateRef IsConstructor(GateRef object); - GateRef IsBuiltinsConstructor(GateRef object); GateRef IsBase(GateRef func); GateRef IsJsArray(GateRef obj); GateRef IsJSObject(GateRef obj); @@ -371,6 +370,8 @@ public: GateRef ChangeInt64ToTagged(GateRef x); GateRef CastInt64ToFloat64(GateRef x); GateRef SExtInt32ToInt64(GateRef x); + GateRef SExtInt16ToInt64(GateRef x); + GateRef SExtInt8ToInt64(GateRef x); GateRef SExtInt1ToInt64(GateRef x); GateRef SExtInt1ToInt32(GateRef x); GateRef ZExtInt8ToInt16(GateRef x); @@ -402,6 +403,7 @@ public: void SetValueWithBarrier(GateRef glue, GateRef obj, GateRef offset, GateRef value); GateRef GetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index); GateRef GetPropertyByName(GateRef glue, GateRef receiver, GateRef key); + GateRef GetPropertyByValue(GateRef glue, GateRef receiver, GateRef keyValue); GateRef SetPropertyByIndex(GateRef glue, GateRef receiver, GateRef index, GateRef value, bool useOwn); GateRef SetPropertyByName(GateRef glue, GateRef receiver, GateRef key, GateRef value, bool useOwn); // Crawl prototype chain @@ -465,6 +467,11 @@ public: GateRef CallGetterHelper(GateRef glue, GateRef receiver, GateRef holder, GateRef accessor); GateRef JSCallDispatch(GateRef glue, GateRef func, GateRef actualNumArgs, JSCallMode mode, std::initializer_list args); + GateRef IsFastTypeArray(GateRef jsType); + GateRef GetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef jsType); + GateRef SetTypeArrayPropertyByName(GateRef glue, GateRef receiver, GateRef holder, GateRef key, GateRef value, + GateRef jsType); + GateRef TryStringOrSymbelToElementIndex(GateRef string); private: using BinaryOperation = std::function; template diff --git a/ecmascript/compiler/stub_compiler.cpp b/ecmascript/compiler/stub_compiler.cpp index 0a35290a491128466dfe9133c6c846ceff64875d..0a4c11693abdfa45a136d19d98ac1614fa779ba3 100644 --- a/ecmascript/compiler/stub_compiler.cpp +++ b/ecmascript/compiler/stub_compiler.cpp @@ -71,7 +71,7 @@ public: bool Run(StubPassData *data, [[maybe_unused]] bool enableLog) { auto stub = data->GetStub(); - COMPILER_LOG(INFO) << "Stub Name: " << stub->GetMethodName(); + LOG_COMPILER(INFO) << "Stub Name: " << stub->GetMethodName(); stub->GenerateCircuit(data->GetCompilationConfig()); return true; } @@ -129,14 +129,14 @@ bool StubCompiler::BuildStubModuleAndSave(const std::string &triple, const std:: const CompilerLog *log = GetLog(); StubFileGenerator generator(log); if (!stubFile.empty()) { - COMPILER_LOG(INFO) << "compiling bytecode handler stubs"; + LOG_COMPILER(INFO) << "compiling bytecode handler stubs"; LLVMModule bcStubModule("bc_stub", triple); LLVMAssembler bcStubAssembler(bcStubModule.GetModule(), LOptions(optLevel, false)); bcStubModule.SetUpForBytecodeHandlerStubs(); RunPipeline(&bcStubModule); generator.AddModule(&bcStubModule, &bcStubAssembler); res++; - COMPILER_LOG(INFO) << "compiling common stubs"; + LOG_COMPILER(INFO) << "compiling common stubs"; LLVMModule comStubModule("com_stub", triple); LLVMAssembler comStubAssembler(comStubModule.GetModule(), LOptions(optLevel, true)); comStubModule.SetUpForCommonStubs(); @@ -181,7 +181,7 @@ int main(const int argc, const char **argv) panda::ecmascript::EcmaVM *vm = panda::JSNApi::CreateEcmaVM(runtimeOptions); if (vm == nullptr) { - COMPILER_LOG(INFO) << "Can't Create EcmaVM"; + LOG_COMPILER(INFO) << "Can't Create EcmaVM"; return -1; } std::string tripleString = runtimeOptions.GetTargetTriple(); @@ -192,7 +192,7 @@ int main(const int argc, const char **argv) panda::ecmascript::kungfu::StubCompiler compiler(&log); bool res = compiler.BuildStubModuleAndSave(tripleString, stubFile, optLevel); - COMPILER_LOG(INFO) << "stub compiler run finish, result condition(T/F):" << std::boolalpha << res; + LOG_COMPILER(INFO) << "stub compiler run finish, result condition(T/F):" << std::boolalpha << res; panda::JSNApi::DestroyJSVM(vm); return res ? 0 : -1; } diff --git a/ecmascript/compiler/test_stubs.cpp b/ecmascript/compiler/test_stubs.cpp index 6ef172f0233ad9e76afb324c4182be65317f5b5e..b20c4f03e6989fe7782d1185c395e0ae32779c3c 100644 --- a/ecmascript/compiler/test_stubs.cpp +++ b/ecmascript/compiler/test_stubs.cpp @@ -27,18 +27,20 @@ void FooAOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bcOffset = Int32Argument(1); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bcOffset = Int32(1); (void)calltarget; - GateRef barIndex = IntBuildTaggedWithNoGC(Int32(CommonStubCSigns::BarAOT)); - GateRef numArgs = IntBuildTaggedWithNoGC(Int32(2)); + GateRef barIndex = IntToTaggedNGC(Int32(CommonStubCSigns::BarAOT)); + GateRef numArgs = IntToTaggedNGC(Int32(2)); GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs}); - GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, barfunc, newtarget, thisObj, a, b, bcOffset}); + GateRef result = + CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, argc, barfunc, newtarget, thisObj, a, b, bcOffset}); Return(result); } @@ -46,12 +48,13 @@ void BarAOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - [[maybe_unused]] GateRef argc = Int32Argument(1); - [[maybe_unused]] GateRef calltarget = TaggedArgument(2); - [[maybe_unused]] GateRef newtarget = TaggedArgument(3); - [[maybe_unused]] GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); + [[maybe_unused]] GateRef env = TaggedArgument(1); + [[maybe_unused]] GateRef argc = Int64Argument(2); + [[maybe_unused]] GateRef calltarget = TaggedArgument(3); + [[maybe_unused]] GateRef newtarget = TaggedArgument(4); + [[maybe_unused]] GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); GateRef result = CallRuntime(glue, RTSTUB_ID(Add2Dyn), {a, b}); Return(result); } @@ -60,18 +63,20 @@ void Foo1AOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bcOffset = Int32Argument(1); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bcOffset = Int32(1); (void)calltarget; - GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::Bar1AOT)); - GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(3)); + GateRef barIndex = IntToTaggedTypeNGC(Int32(CommonStubCSigns::Bar1AOT)); + GateRef numArgs = IntToTaggedTypeNGC(Int32(3)); GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs}); - GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, barfunc, newtarget, thisObj, a, b, bcOffset}); + GateRef result = + CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, argc, barfunc, newtarget, thisObj, a, b, bcOffset}); Return(result); } @@ -79,17 +84,19 @@ void Bar1AOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + (void)env; (void)argc; (void)calltarget; (void)newtarget; (void)thisObj; - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef c = TaggedArgument(7); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef c = TaggedArgument(8); GateRef result = CallRuntime(glue, RTSTUB_ID(Add2Dyn), {a, b}); GateRef result2 = CallRuntime(glue, RTSTUB_ID(Add2Dyn), {result, c}); Return(result2); @@ -99,19 +106,20 @@ void Foo2AOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bcOffset = Int32Argument(1); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bcOffset = Int32(1); (void)calltarget; - GateRef actualArgC = Int32Add(argc, Int32(1)); - GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::BarAOT)); - GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2)); + GateRef actualArgC = Int64Add(argc, Int64(1)); + GateRef barIndex = IntToTaggedTypeNGC(Int32(CommonStubCSigns::BarAOT)); + GateRef numArgs = IntToTaggedTypeNGC(Int32(2)); GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs}); - GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, actualArgC, barfunc, newtarget, thisObj, + GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, actualArgC, barfunc, newtarget, thisObj, a, b, Undefined(), bcOffset}); Return(result); } @@ -120,17 +128,18 @@ void FooNativeAOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bcOffset = Int32Argument(1); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bcOffset = Int32(1); (void)calltarget; - GateRef actualArgC = Int32Add(argc, Int32(1)); + GateRef actualArgC = Int64Add(argc, Int64(1)); GateRef printfunc = CallRuntime(glue, RTSTUB_ID(GetPrintFunc), {}); - GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, actualArgC, printfunc, newtarget, thisObj, + GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, actualArgC, printfunc, newtarget, thisObj, a, b, Undefined(), bcOffset}); Return(result); } @@ -139,22 +148,23 @@ void FooBoundAOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bindArguments = IntBuildTaggedTypeWithNoGC(Int32(37)); - GateRef bcOffset = Int32Argument(1); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bindArguments = IntToTaggedTypeNGC(Int32(37)); + GateRef bcOffset = Int32(1); (void)calltarget; - GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2)); - GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::BarAOT)); + GateRef numArgs = IntToTaggedTypeNGC(Int32(2)); + GateRef barIndex = IntToTaggedTypeNGC(Int32(CommonStubCSigns::BarAOT)); GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs}); GateRef bindfunc = CallRuntime(glue, RTSTUB_ID(GetBindFunc), {barfunc}); - GateRef newjsfunc = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, Int32(5), bindfunc, newtarget, barfunc, + GateRef newjsfunc = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, Int64(5), bindfunc, newtarget, barfunc, Int64(0x02), bindArguments, bcOffset}); - GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, newjsfunc, newtarget, thisObj, + GateRef result = CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, argc, newjsfunc, newtarget, thisObj, a, b, bcOffset}); Return(result); } @@ -163,21 +173,22 @@ void FooProxyAOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - [[maybe_unused]] GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bcOffset = Int32Argument(1); - - GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::BarAOT)); - GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2)); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + [[maybe_unused]] GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bcOffset = Int32(1); + + GateRef barIndex = IntToTaggedTypeNGC(Int32(CommonStubCSigns::BarAOT)); + GateRef numArgs = IntToTaggedTypeNGC(Int32(2)); GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs}); GateRef proxyfunc = CallRuntime(glue, RTSTUB_ID(DefineProxyFunc), {barfunc}); GateRef result = - CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, proxyfunc, newtarget, thisObj, a, b, bcOffset}); + CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, argc, proxyfunc, newtarget, thisObj, a, b, bcOffset}); Return(result); } @@ -185,22 +196,23 @@ void FooProxy2AOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); GateRef glue = PtrArgument(0); - GateRef argc = Int32Argument(1); - [[maybe_unused]] GateRef calltarget = TaggedArgument(2); - GateRef newtarget = TaggedArgument(3); - GateRef thisObj = TaggedArgument(4); - GateRef a = TaggedArgument(5); - GateRef b = TaggedArgument(6); - GateRef bcOffset = Int32Argument(1); - - GateRef barIndex = IntBuildTaggedTypeWithNoGC(Int32(CommonStubCSigns::Bar2AOT)); - GateRef numArgs = IntBuildTaggedTypeWithNoGC(Int32(2)); + GateRef env = TaggedArgument(1); + GateRef argc = Int64Argument(2); + [[maybe_unused]] GateRef calltarget = TaggedArgument(3); + GateRef newtarget = TaggedArgument(4); + GateRef thisObj = TaggedArgument(5); + GateRef a = TaggedArgument(6); + GateRef b = TaggedArgument(7); + GateRef bcOffset = Int32(1); + + GateRef barIndex = IntToTaggedTypeNGC(Int32(CommonStubCSigns::Bar2AOT)); + GateRef numArgs = IntToTaggedTypeNGC(Int32(2)); GateRef barfunc = CallRuntime(glue, RTSTUB_ID(DefineAotFunc), {barIndex, numArgs}); GateRef proxyHandler = CallRuntime(glue, RTSTUB_ID(DefineProxyHandler), {barfunc}); GateRef proxyfunc = CallRuntime(glue, RTSTUB_ID(DefineProxyFunc2), {barfunc, proxyHandler}); GateRef result = - CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, argc, proxyfunc, newtarget, thisObj, a, b, bcOffset}); + CallNGCRuntime(glue, RTSTUB_ID(JSCall), {glue, env, argc, proxyfunc, newtarget, thisObj, a, b, bcOffset}); Return(result); } @@ -208,10 +220,11 @@ void Bar2AOTStub::GenerateCircuit(const CompilationConfig *cfg) { Stub::GenerateCircuit(cfg); [[maybe_unused]] GateRef glue = PtrArgument(0); - [[maybe_unused]] GateRef argc = Int32Argument(1); - [[maybe_unused]] GateRef calltarget = TaggedArgument(2); - [[maybe_unused]] GateRef newtarget = TaggedArgument(3); - [[maybe_unused]] GateRef thisObj = TaggedArgument(4); + [[maybe_unused]] GateRef env = TaggedArgument(1); + [[maybe_unused]] GateRef argc = Int64Argument(2); + [[maybe_unused]] GateRef calltarget = TaggedArgument(3); + [[maybe_unused]] GateRef newtarget = TaggedArgument(4); + [[maybe_unused]] GateRef thisObj = TaggedArgument(5); CallRuntime(glue, RTSTUB_ID(DumpTaggedType), {thisObj}); Return(thisObj); } diff --git a/ecmascript/compiler/test_stubs.h b/ecmascript/compiler/test_stubs.h index 3281136fe92ac3695989aa801d8f3209d147237c..8415378f96db0c3ff6415db15e15559e0d10a7c4 100644 --- a/ecmascript/compiler/test_stubs.h +++ b/ecmascript/compiler/test_stubs.h @@ -39,8 +39,8 @@ namespace panda::ecmascript::kungfu { class FooAOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit FooAOTStub(Circuit *circuit) : Stub("FooAOT", 7, circuit) + // 8 : 8 means argument counts + explicit FooAOTStub(Circuit *circuit) : Stub("FooAOT", 8, circuit) { } ~FooAOTStub() = default; @@ -51,8 +51,8 @@ public: class BarAOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit BarAOTStub(Circuit *circuit) : Stub("BarAOT", 7, circuit) + // 8 : 8 means argument counts + explicit BarAOTStub(Circuit *circuit) : Stub("BarAOT", 8, circuit) { } ~BarAOTStub() = default; @@ -63,8 +63,8 @@ public: class Foo1AOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit Foo1AOTStub(Circuit *circuit) : Stub("Foo1AOT", 7, circuit) + // 8 : 8 means argument counts + explicit Foo1AOTStub(Circuit *circuit) : Stub("Foo1AOT", 8, circuit) { } ~Foo1AOTStub() = default; @@ -75,8 +75,8 @@ public: class Foo2AOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit Foo2AOTStub(Circuit *circuit) : Stub("Foo2AOT", 7, circuit) + // 8 : 8 means argument counts + explicit Foo2AOTStub(Circuit *circuit) : Stub("Foo2AOT", 8, circuit) { } ~Foo2AOTStub() = default; @@ -87,8 +87,8 @@ public: class FooNativeAOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit FooNativeAOTStub(Circuit *circuit) : Stub("FooNativeAOT", 7, circuit) + // 8 : 8 means argument counts + explicit FooNativeAOTStub(Circuit *circuit) : Stub("FooNativeAOT", 8, circuit) { } ~FooNativeAOTStub() = default; @@ -99,8 +99,8 @@ public: class FooBoundAOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit FooBoundAOTStub(Circuit *circuit) : Stub("FooBoundAOT", 7, circuit) + // 8 : 8 means argument counts + explicit FooBoundAOTStub(Circuit *circuit) : Stub("FooBoundAOT", 8, circuit) { } ~FooBoundAOTStub() = default; @@ -111,8 +111,8 @@ public: class Bar1AOTStub : public Stub { public: - // 8 : 8 means argument counts - explicit Bar1AOTStub(Circuit *circuit) : Stub("Bar1AOT", 8, circuit) + // 9 : 9 means argument counts + explicit Bar1AOTStub(Circuit *circuit) : Stub("Bar1AOT", 9, circuit) { } ~Bar1AOTStub() = default; @@ -123,8 +123,8 @@ public: class FooProxyAOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit FooProxyAOTStub(Circuit *circuit) : Stub("FooProxyAOT", 7, circuit) + // 8 : 8 means argument counts + explicit FooProxyAOTStub(Circuit *circuit) : Stub("FooProxyAOT", 8, circuit) { } ~FooProxyAOTStub() = default; @@ -135,8 +135,8 @@ public: class FooProxy2AOTStub : public Stub { public: - // 7 : 7 means argument counts - explicit FooProxy2AOTStub(Circuit *circuit) : Stub("FooProxy2AOTStub", 7, circuit) + // 8 : 8 means argument counts + explicit FooProxy2AOTStub(Circuit *circuit) : Stub("FooProxy2AOTStub", 8, circuit) { } ~FooProxy2AOTStub() = default; @@ -147,8 +147,8 @@ public: class Bar2AOTStub : public Stub { public: - // 5 : 5 means argument counts - explicit Bar2AOTStub(Circuit *circuit) : Stub("Bar2AOT", 5, circuit) + // 6 : 6 means argument counts + explicit Bar2AOTStub(Circuit *circuit) : Stub("Bar2AOT", 6, circuit) { } ~Bar2AOTStub() = default; diff --git a/ecmascript/compiler/test_stubs_signature.cpp b/ecmascript/compiler/test_stubs_signature.cpp index 182136a67270acc64736cfabdcc4c0d9f7c30388..370a492ac3fbbacb4e63da590cc095efa17d7ab8 100644 --- a/ecmascript/compiler/test_stubs_signature.cpp +++ b/ecmascript/compiler/test_stubs_signature.cpp @@ -19,12 +19,13 @@ namespace panda::ecmascript::kungfu { DEF_CALL_SIGNATURE(FooAOT) { // 7 : 7 input parameters - CallSignature fooAot("FooAOT", 0, 7, + CallSignature fooAot("FooAOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = fooAot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -38,12 +39,13 @@ DEF_CALL_SIGNATURE(FooAOT) DEF_CALL_SIGNATURE(Foo1AOT) { // 7 : 7 input parameters - CallSignature foo1Aot("Foo1AOT", 0, 7, + CallSignature foo1Aot("Foo1AOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = foo1Aot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -57,12 +59,13 @@ DEF_CALL_SIGNATURE(Foo1AOT) DEF_CALL_SIGNATURE(Foo2AOT) { // 7 : 7 input parameters - CallSignature foo2Aot("Foo2AOT", 0, 7, + CallSignature foo2Aot("Foo2AOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = foo2Aot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -76,12 +79,13 @@ DEF_CALL_SIGNATURE(Foo2AOT) DEF_CALL_SIGNATURE(FooNativeAOT) { // 7 : 7 input parameters - CallSignature foo2Aot("FooNativeAOT", 0, 7, + CallSignature foo2Aot("FooNativeAOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = foo2Aot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -95,12 +99,13 @@ DEF_CALL_SIGNATURE(FooNativeAOT) DEF_CALL_SIGNATURE(FooBoundAOT) { // 7 : 7 input parameters - CallSignature foo2Aot("FooBoundAOT", 0, 7, + CallSignature foo2Aot("FooBoundAOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = foo2Aot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -114,12 +119,13 @@ DEF_CALL_SIGNATURE(FooBoundAOT) DEF_CALL_SIGNATURE(Bar1AOT) { // 8 : 8 input parameters - CallSignature barAot("Bar1AOT", 0, 8, + CallSignature barAot("Bar1AOT", 0, 9, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = barAot; - std::array params = { // 8 : 8 input parameters + std::array params = { // 9 : 9 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -134,12 +140,13 @@ DEF_CALL_SIGNATURE(Bar1AOT) DEF_CALL_SIGNATURE(BarAOT) { // 7 : 7 input parameters - CallSignature barAot("BarAOT", 0, 7, + CallSignature barAot("BarAOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = barAot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexEnv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -153,12 +160,13 @@ DEF_CALL_SIGNATURE(BarAOT) DEF_CALL_SIGNATURE(FooProxyAOT) { // 8 : 8 input parameters - CallSignature fooProxyAot("FooProxyAOT", 0, 7, + CallSignature fooProxyAot("FooProxyAOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = fooProxyAot; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexEnv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -172,12 +180,13 @@ DEF_CALL_SIGNATURE(FooProxyAOT) DEF_CALL_SIGNATURE(FooProxy2AOT) { // 8 : 8 input parameters - CallSignature FooProxy2AOT("FooProxy2AOT", 0, 7, + CallSignature FooProxy2AOT("FooProxy2AOT", 0, 8, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = FooProxy2AOT; - std::array params = { // 7 : 7 input parameters + std::array params = { // 8 : 8 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexEnv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget @@ -191,12 +200,13 @@ DEF_CALL_SIGNATURE(FooProxy2AOT) DEF_CALL_SIGNATURE(Bar2AOT) { // 7 : 7 input parameters - CallSignature bar2Aot("Bar2AOT", 0, 5, + CallSignature bar2Aot("Bar2AOT", 0, 6, ArgumentsOrder::DEFAULT_ORDER, VariableType::JS_ANY()); *callSign = bar2Aot; - std::array params = { // 5 : 5 input parameters + std::array params = { // 6 : 6 input parameters VariableType::NATIVE_POINTER(), - VariableType::INT32(), + VariableType::JS_ANY(), // lexenv + VariableType::INT64(), VariableType::JS_ANY(), // calltarget VariableType::JS_ANY(), // newTarget VariableType::JS_ANY(), // thisTarget diff --git a/ecmascript/compiler/tests/BUILD.gn b/ecmascript/compiler/tests/BUILD.gn index 42a8c571fc43cf11f2fe22fdec1e772ceda66fdf..dcf74e1f4d199caa404328657994471ae2d5c96c 100644 --- a/ecmascript/compiler/tests/BUILD.gn +++ b/ecmascript/compiler/tests/BUILD.gn @@ -113,7 +113,6 @@ host_unittest_action("StubTest") { deps = [ "$ark_root/libpandabase:libarkbase", - "//ark/js_runtime/ecmascript/compiler:gen_stub_file(${host_toolchain})", "//ark/js_runtime/ecmascript/compiler:libark_jsoptimizer_test", sdk_libc_secshared_dep, ] @@ -223,7 +222,7 @@ host_unittest_action("CircuitOptimizerTest") { ] if (compile_llvm_online) { - lib_dirs = [ "//third_party/llvm-project/build/lib" ] + lib_dirs = [ "//third_party/third_party_llvm-project/build/lib" ] } else { lib_dirs = [ "//prebuilts/ark_tools/ark_js_prebuilts/llvm_prebuilts/build/lib" ] diff --git a/ecmascript/compiler/tests/stub_tests.cpp b/ecmascript/compiler/tests/stub_tests.cpp index a0cc408fefba926343c93d69f79dd9368cf4e2a2..5fdfd2ce2cac032ba9e4327a475010bc54fda20b 100644 --- a/ecmascript/compiler/tests/stub_tests.cpp +++ b/ecmascript/compiler/tests/stub_tests.cpp @@ -21,7 +21,7 @@ #include "ecmascript/compiler/common_stubs.h" #include "ecmascript/compiler/llvm_codegen.h" #include "ecmascript/compiler/llvm_ir_builder.h" -#include "ecmascript/compiler/llvm/llvm_stackmap_parser.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "ecmascript/compiler/scheduler.h" #include "ecmascript/compiler/call_signature.h" #include "ecmascript/compiler/verifier.h" @@ -39,7 +39,6 @@ #include "ecmascript/compiler/assembler_module.h" namespace panda::test { -using namespace panda::coretypes; using namespace panda::ecmascript; using namespace panda::ecmascript::kungfu; using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler; @@ -65,7 +64,7 @@ public: { if (thread->GetEcmaVM()->GetJSOptions().WasSetlogCompiledMethods()) { for (size_t bbIdx = 0; bbIdx < cfg.size(); bbIdx++) { - COMPILER_LOG(INFO) << (netOfGates.GetOpCode(cfg[bbIdx].front()).IsCFGMerge() ? "MERGE_" : "BB_") + LOG_COMPILER(INFO) << (netOfGates.GetOpCode(cfg[bbIdx].front()).IsCFGMerge() ? "MERGE_" : "BB_") << bbIdx << ":"; for (size_t instIdx = cfg[bbIdx].size(); instIdx > 0; instIdx--) { netOfGates.Print(cfg[bbIdx][instIdx - 1]); @@ -118,16 +117,16 @@ HWTEST_F_L0(StubTest, FastAddTest) JSTaggedValue(2).GetRawData()); // 2 : test case auto resC = fn(thread->GetGlueAddr(), JSTaggedValue(11).GetRawData(), JSTaggedValue(11).GetRawData()); // 11 : test case - COMPILER_LOG(INFO) << "res for FastAdd(1, 1) = " << resA.GetNumber(); - COMPILER_LOG(INFO) << "res for FastAdd(2, 2) = " << resB.GetNumber(); - COMPILER_LOG(INFO) << "res for FastAdd(11, 11) = " << resC.GetNumber(); + LOG_COMPILER(INFO) << "res for FastAdd(1, 1) = " << resA.GetNumber(); + LOG_COMPILER(INFO) << "res for FastAdd(2, 2) = " << resB.GetNumber(); + LOG_COMPILER(INFO) << "res for FastAdd(11, 11) = " << resC.GetNumber(); EXPECT_EQ(resA.GetNumber(), JSTaggedValue(2).GetNumber()); EXPECT_EQ(resB.GetNumber(), JSTaggedValue(4).GetNumber()); EXPECT_EQ(resC.GetNumber(), JSTaggedValue(22).GetNumber()); int x1 = 2147483647; int y1 = 15; auto resG = fn(thread->GetGlueAddr(), JSTaggedValue(x1).GetRawData(), JSTaggedValue(y1).GetRawData()); - auto expectedG = FastRuntimeStub::FastAdd(JSTaggedValue(x1), JSTaggedValue(y1)); + auto expectedG = SlowRuntimeStub::Add2Dyn(thread, JSTaggedValue(x1), JSTaggedValue(y1)); EXPECT_EQ(resG, expectedG); } @@ -155,9 +154,9 @@ HWTEST_F_L0(StubTest, FastSubTest) JSTaggedValue(2).GetRawData()); // 7, 2 : test cases auto resC = fn(thread->GetGlueAddr(), JSTaggedValue(11).GetRawData(), JSTaggedValue(11).GetRawData()); // 11 : test case - COMPILER_LOG(INFO) << "res for FastSub(2, 1) = " << resA.GetNumber(); - COMPILER_LOG(INFO) << "res for FastSub(7, 2) = " << resB.GetNumber(); - COMPILER_LOG(INFO) << "res for FastSub(11, 11) = " << resC.GetNumber(); + LOG_COMPILER(INFO) << "res for FastSub(2, 1) = " << resA.GetNumber(); + LOG_COMPILER(INFO) << "res for FastSub(7, 2) = " << resB.GetNumber(); + LOG_COMPILER(INFO) << "res for FastSub(11, 11) = " << resC.GetNumber(); EXPECT_EQ(resA, JSTaggedValue(1)); EXPECT_EQ(resB, JSTaggedValue(5)); EXPECT_EQ(resC, JSTaggedValue(0)); @@ -188,9 +187,9 @@ HWTEST_F_L0(StubTest, FastMulTest) JSTaggedValue(-2).GetRawData()); // -7, -2 : test case auto resC = fn(thread->GetGlueAddr(), JSTaggedValue(11).GetRawData(), JSTaggedValue(11).GetRawData()); // 11 : test case - COMPILER_LOG(INFO) << "res for FastMul(-2, 1) = " << std::dec << resA.GetNumber(); - COMPILER_LOG(INFO) << "res for FastMul(-7, -2) = " << std::dec << resB.GetNumber(); - COMPILER_LOG(INFO) << "res for FastMul(11, 11) = " << std::dec << resC.GetNumber(); + LOG_COMPILER(INFO) << "res for FastMul(-2, 1) = " << std::dec << resA.GetNumber(); + LOG_COMPILER(INFO) << "res for FastMul(-7, -2) = " << std::dec << resB.GetNumber(); + LOG_COMPILER(INFO) << "res for FastMul(11, 11) = " << std::dec << resC.GetNumber(); EXPECT_EQ(resA.GetNumber(), -2); // -2: test case EXPECT_EQ(resB.GetNumber(), 14); // 14: test case EXPECT_EQ(resC.GetNumber(), 121); // 121: test case @@ -236,27 +235,27 @@ HWTEST_F_L0(StubTest, FastDivTest) // test normal Division operation uint64_t x1 = JSTaggedValue(50).GetRawData(); uint64_t y1 = JSTaggedValue(25).GetRawData(); - COMPILER_LOG(INFO) << "x1 = " << x1 << " y1 = " << y1; + LOG_COMPILER(INFO) << "x1 = " << x1 << " y1 = " << y1; auto res1 = fn(thread->GetGlueAddr(), x1, y1); - COMPILER_LOG(INFO) << "res for FastDiv(50, 25) = " << res1.GetRawData(); + LOG_COMPILER(INFO) << "res for FastDiv(50, 25) = " << res1.GetRawData(); auto expectedG1 = FastRuntimeStub::FastDiv(JSTaggedValue(x1), JSTaggedValue(y1)); EXPECT_EQ(res1, expectedG1); // test x == 0.0 or std::isnan(x) uint64_t x2 = JSTaggedValue(base::NAN_VALUE).GetRawData(); uint64_t y2 = JSTaggedValue(0).GetRawData(); - COMPILER_LOG(INFO) << "x2 = " << x1 << " y2 = " << y2; + LOG_COMPILER(INFO) << "x2 = " << x1 << " y2 = " << y2; auto res2 = fn(thread->GetGlueAddr(), x2, y2); - COMPILER_LOG(INFO) << "res for FastDiv(base::NAN_VALUE, 0) = " << res2.GetRawData(); + LOG_COMPILER(INFO) << "res for FastDiv(base::NAN_VALUE, 0) = " << res2.GetRawData(); auto expectedG2 = FastRuntimeStub::FastDiv(JSTaggedValue(x2), JSTaggedValue(y2)); EXPECT_EQ(res2, expectedG2); // test other uint64_t x3 = JSTaggedValue(7).GetRawData(); uint64_t y3 = JSTaggedValue(0).GetRawData(); - COMPILER_LOG(INFO) << "x2 = " << x3 << " y2 = " << y3; + LOG_COMPILER(INFO) << "x2 = " << x3 << " y2 = " << y3; auto res3 = fn(thread->GetGlueAddr(), x3, y3); - COMPILER_LOG(INFO) << "res for FastDiv(7, 0) = " << res3.GetRawData(); + LOG_COMPILER(INFO) << "res for FastDiv(7, 0) = " << res3.GetRawData(); auto expectedG3 = FastRuntimeStub::FastDiv(JSTaggedValue(x3), JSTaggedValue(y3)); EXPECT_EQ(res3, expectedG3); } @@ -291,8 +290,8 @@ HWTEST_F_L0(StubTest, FastModTest) auto result2 = fn(thread->GetGlueAddr(), JSTaggedValue(x2).GetRawData(), JSTaggedValue(y2).GetRawData()); auto expectRes2 = FastRuntimeStub::FastMod(JSTaggedValue(x2), JSTaggedValue(y2)); EXPECT_EQ(result2, expectRes2); - COMPILER_LOG(INFO) << "result2 for FastMod(7, 'helloworld') = " << result2.GetRawData(); - COMPILER_LOG(INFO) << "expectRes2 for FastMod(7, 'helloworld') = " << expectRes2.GetRawData(); + LOG_COMPILER(INFO) << "result2 for FastMod(7, 'helloworld') = " << result2.GetRawData(); + LOG_COMPILER(INFO) << "expectRes2 for FastMod(7, 'helloworld') = " << expectRes2.GetRawData(); // // test modular operation under normal conditions auto sp = const_cast(thread->GetCurrentSPFrame()); @@ -309,8 +308,8 @@ HWTEST_F_L0(StubTest, FastModTest) auto result4 = fn(thread->GetGlueAddr(), JSTaggedValue(x4).GetRawData(), JSTaggedValue(y4).GetRawData()); auto expectRes4 = FastRuntimeStub::FastMod(JSTaggedValue(x4), JSTaggedValue(y4)); - COMPILER_LOG(INFO) << "result4 for FastMod(base::NAN_VALUE, 7) = " << result4.GetRawData(); - COMPILER_LOG(INFO) << "expectRes4 for FastMod(base::NAN_VALUE, 7) = " << expectRes4.GetRawData(); + LOG_COMPILER(INFO) << "result4 for FastMod(base::NAN_VALUE, 7) = " << result4.GetRawData(); + LOG_COMPILER(INFO) << "expectRes4 for FastMod(base::NAN_VALUE, 7) = " << expectRes4.GetRawData(); EXPECT_EQ(result4, expectRes4); // test all non-conforming conditions @@ -321,7 +320,7 @@ HWTEST_F_L0(StubTest, FastModTest) auto result5 = fn(thread->GetGlueAddr(), JSTaggedValue(x5).GetRawData(), y5.GetTaggedValue().GetRawData()); EXPECT_EQ(result5, JSTaggedValue::Hole()); auto expectRes5 = FastRuntimeStub::FastMod(JSTaggedValue(x5), y5.GetTaggedValue()); - COMPILER_LOG(INFO) << "result1 for FastMod(7, 'helloworld') = " << result5.GetRawData(); + LOG_COMPILER(INFO) << "result1 for FastMod(7, 'helloworld') = " << result5.GetRawData(); EXPECT_EQ(result5, expectRes5); } @@ -402,12 +401,12 @@ public: StubCallRunTimeThreadFpLock(struct ThreadTy *thread, intptr_t newFp) : oldRbp_(thread->fp), thread_(thread) { thread_->fp = *(reinterpret_cast(newFp)); - COMPILER_LOG(INFO) << "StubCallRunTimeThreadFpLock newFp: " << newFp << " oldRbp_ : " << oldRbp_ + LOG_COMPILER(INFO) << "StubCallRunTimeThreadFpLock newFp: " << newFp << " oldRbp_ : " << oldRbp_ << " thread_->fp:" << thread_->fp; } ~StubCallRunTimeThreadFpLock() { - COMPILER_LOG(INFO) << "~StubCallRunTimeThreadFpLock oldRbp_: " << oldRbp_ << " thread_->fp:" << thread_->fp; + LOG_COMPILER(INFO) << "~StubCallRunTimeThreadFpLock oldRbp_: " << oldRbp_ << " thread_->fp:" << thread_->fp; thread_->fp = oldRbp_; } @@ -431,31 +430,31 @@ int64_t (*g_stub2Func)(struct ThreadTy *) = nullptr; int RuntimeFunc1(struct ThreadTy *fpInfo) { - COMPILER_LOG(INFO) << "RuntimeFunc1 -"; + LOG_COMPILER(INFO) << "RuntimeFunc1 -"; int64_t newRbp; asm("mov %%rbp, %0" : "=rm"(newRbp)); StubCallRunTimeThreadFpLock lock(fpInfo, newRbp); - COMPILER_LOG(INFO) << std::hex << "g_stub2Func " << reinterpret_cast(g_stub2Func); + LOG_COMPILER(INFO) << std::hex << "g_stub2Func " << reinterpret_cast(g_stub2Func); if (g_stub2Func != nullptr) { g_stub2Func(fpInfo); } - COMPILER_LOG(INFO) << "RuntimeFunc1 +"; + LOG_COMPILER(INFO) << "RuntimeFunc1 +"; return 0; } int RuntimeFunc2(struct ThreadTy *fpInfo) { - COMPILER_LOG(INFO) << "RuntimeFunc2 -"; + LOG_COMPILER(INFO) << "RuntimeFunc2 -"; // update thread.fp int64_t newRbp; asm("mov %%rbp, %0" : "=rm"(newRbp)); StubCallRunTimeThreadFpLock lock(fpInfo, newRbp); auto rbp = reinterpret_cast(fpInfo->fp); - COMPILER_LOG(INFO) << " RuntimeFunc2 rbp:" << rbp; + LOG_COMPILER(INFO) << " RuntimeFunc2 rbp:" << rbp; for (int i = 0; i < 40; i++) { // print 40 ptr value for debug - COMPILER_LOG(INFO) << std::hex << &(rbp[i]) << " :" << rbp[i]; + LOG_COMPILER(INFO) << std::hex << &(rbp[i]) << " :" << rbp[i]; } /* walk back stack frame: 0 pre rbp <-- rbp @@ -464,7 +463,7 @@ int RuntimeFunc2(struct ThreadTy *fpInfo) */ int64_t *frameType = nullptr; int64_t *gcFp = nullptr; - COMPILER_LOG(INFO) << "-----------------walkback----------------"; + LOG_COMPILER(INFO) << "-----------------walkback----------------"; do { frameType = rbp - 1; if (*frameType == 1) { @@ -473,11 +472,11 @@ int RuntimeFunc2(struct ThreadTy *fpInfo) gcFp = rbp; } rbp = reinterpret_cast(*gcFp); - COMPILER_LOG(INFO) << std::hex << "frameType :" << *frameType << " gcFp:" << *gcFp; + LOG_COMPILER(INFO) << std::hex << "frameType :" << *frameType << " gcFp:" << *gcFp; } while (*gcFp != 0); - COMPILER_LOG(INFO) << "+++++++++++++++++walkback++++++++++++++++"; - COMPILER_LOG(INFO) << "call RuntimeFunc2 func ThreadTy fp: " << fpInfo->fp << " magic:" << fpInfo->magic; - COMPILER_LOG(INFO) << "RuntimeFunc2 +"; + LOG_COMPILER(INFO) << "+++++++++++++++++walkback++++++++++++++++"; + LOG_COMPILER(INFO) << "call RuntimeFunc2 func ThreadTy fp: " << fpInfo->fp << " magic:" << fpInfo->magic; + LOG_COMPILER(INFO) << "RuntimeFunc2 +"; return 0; } } @@ -520,7 +519,7 @@ LLVMValueRef CallingFp(LLVMModuleRef &module, LLVMBuilderRef &builder) std::vector args = {LLVMConstInt(LLVMInt32Type(), 0, false)}; auto fn = LLVMGetNamedFunction(module, "llvm.frameaddress.p0i8"); if (!fn) { - COMPILER_LOG(INFO) << "Could not find function "; + LOG_COMPILER(INFO) << "Could not find function "; return LLVMConstInt(LLVMInt64Type(), 0, false); } LLVMValueRef fAddrRet = LLVMBuildCall(builder, fn, args.data(), 1, ""); @@ -531,7 +530,7 @@ LLVMValueRef CallingFp(LLVMModuleRef &module, LLVMBuilderRef &builder) #ifdef ARK_GC_SUPPORT HWTEST_F_L0(StubTest, JSEntryTest) { - COMPILER_LOG(INFO) << " ---------- JSEntryTest ------------- "; + LOG_COMPILER(INFO) << " ---------- JSEntryTest ------------- "; LLVMModuleRef module = LLVMModuleCreateWithName("simple_module"); LLVMSetTarget(module, "x86_64-unknown-linux-gnu"); LLVMBuilderRef builder = LLVMCreateBuilder(); @@ -658,10 +657,10 @@ HWTEST_F_L0(StubTest, JSEntryTest) auto stub1Func = reinterpret_cast(stub1Code); g_stub2Func = reinterpret_cast(stub2Code); int64_t result = stub1Func(¶meters); - COMPILER_LOG(INFO) << "parameters magic:" << parameters.magic << " parameters.fp " << parameters.fp; + LOG_COMPILER(INFO) << "parameters magic:" << parameters.magic << " parameters.fp " << parameters.fp; EXPECT_EQ(parameters.fp, 0x0); EXPECT_EQ(result, 1); - COMPILER_LOG(INFO) << " ++++++++++ JSEntryTest +++++++++++++ "; + LOG_COMPILER(INFO) << " ++++++++++ JSEntryTest +++++++++++++ "; } /* @@ -676,7 +675,7 @@ main push rbp */ HWTEST_F_L0(StubTest, Prologue) { - COMPILER_LOG(INFO) << " ---------- Prologue ------------- "; + LOG_COMPILER(INFO) << " ---------- Prologue ------------- "; LLVMModuleRef module = LLVMModuleCreateWithName("simple_module"); LLVMSetTarget(module); LLVMBuilderRef builder = LLVMCreateBuilder(); @@ -723,7 +722,7 @@ HWTEST_F_L0(StubTest, Prologue) auto mainFunc = reinterpret_cast(mainCode); int64_t result = mainFunc(1, 2); EXPECT_EQ(result, 3); - COMPILER_LOG(INFO) << " ++++++++++ Prologue +++++++++++++ "; + LOG_COMPILER(INFO) << " ++++++++++ Prologue +++++++++++++ "; } /* @@ -734,7 +733,7 @@ test: */ HWTEST_F_L0(StubTest, CEntryFp) { - COMPILER_LOG(INFO) << " ---------- CEntryFp ------------- "; + LOG_COMPILER(INFO) << " ---------- CEntryFp ------------- "; LLVMModuleRef module = LLVMModuleCreateWithName("simple_module"); LLVMSetTarget(module); LLVMBuilderRef builder = LLVMCreateBuilder(); @@ -782,7 +781,7 @@ HWTEST_F_L0(StubTest, CEntryFp) LLVMValueRef runTimeFunc = LLVMAddFunction(module, "RuntimeFunc", funcType); std::vector argValue = {value}; - COMPILER_LOG(INFO); + LOG_COMPILER(INFO); LLVMValueRef retVal = LLVMBuildCall(builder, runTimeFunc, argValue.data(), 1, ""); LLVMBuildRet(builder, retVal); char *error = nullptr; @@ -792,25 +791,25 @@ HWTEST_F_L0(StubTest, CEntryFp) assembler.Run(); auto engine = assembler.GetEngine(); uint64_t nativeCode = LLVMGetFunctionAddress(engine, "main"); - COMPILER_LOG(INFO) << " nativeCode : " << nativeCode; + LOG_COMPILER(INFO) << " nativeCode : " << nativeCode; struct ThreadTy parameters = {0x0, 0x0}; auto mainFunc = reinterpret_cast(nativeCode); int64_t result = mainFunc(¶meters); EXPECT_EQ(result, 1); - COMPILER_LOG(INFO) << " ++++++++++ CEntryFp +++++++++++++ "; + LOG_COMPILER(INFO) << " ++++++++++ CEntryFp +++++++++++++ "; } HWTEST_F_L0(StubTest, LoadGCIRTest) { - COMPILER_LOG(INFO) << "--------------LoadGCIRTest--------------------"; + LOG_COMPILER(INFO) << "--------------LoadGCIRTest--------------------"; char *path = get_current_dir_name(); std::string filePath = std::string(path) + "/ark/js_runtime/ecmascript/compiler/tests/satepoint_GC_0.ll"; char resolvedPath[PATH_MAX]; char *res = realpath(filePath.c_str(), resolvedPath); if (res == nullptr) { - COMPILER_LOG(ERROR) << "filePath :" << filePath.c_str() << " is not exist !"; + LOG_COMPILER(ERROR) << "filePath :" << filePath.c_str() << " is not exist !"; return; } @@ -820,7 +819,7 @@ HWTEST_F_L0(StubTest, LoadGCIRTest) // Load the input module... std::unique_ptr rawModule = parseIRFile(inputFilename, err, context); if (!rawModule) { - COMPILER_LOG(INFO) << "parseIRFile :" << inputFilename.data() << " failed !"; + LOG_COMPILER(INFO) << "parseIRFile :" << inputFilename.data() << " failed !"; err.print("parseIRFile ", llvm::errs()); return; } @@ -835,42 +834,10 @@ HWTEST_F_L0(StubTest, LoadGCIRTest) LLVMStackMapParser::GetInstance().CalculateStackMap(ptr); int value = reinterpret_cast(mainPtr)(); - COMPILER_LOG(INFO) << " value:" << value; + LOG_COMPILER(INFO) << " value:" << value; } #endif -extern "C" { -void DoSafepoint() -{ - uintptr_t *rbp; - asm("mov %%rbp, %0" : "=rm" (rbp)); - for (int i = 0; i < 3; i++) { // 3: call back depth - uintptr_t returnAddr = *(rbp + 1); - uintptr_t *rsp = rbp + 2; // move 2 steps from rbp to get rsp - rbp = reinterpret_cast(*rbp); - const kungfu::CallSiteInfo *infos = - kungfu::LLVMStackMapParser::GetInstance().GetCallSiteInfoByPc(returnAddr); - if (infos != nullptr) { - for (auto &info : *infos) { - uintptr_t **address = nullptr; - if (info.first == GCStackMapRegisters::SP) { - address = reinterpret_cast(reinterpret_cast(rsp) + info.second); - } else if (info.first == GCStackMapRegisters::FP) { - address = reinterpret_cast(reinterpret_cast(rbp) + info.second); - } - // print ref and vlue for debug - COMPILER_LOG(INFO) << std::hex << "ref addr:" << address; - COMPILER_LOG(INFO) << " value:" << *address; - COMPILER_LOG(INFO) << " *value :" << **address; - } - } - COMPILER_LOG(INFO) << std::hex << "+++++++++++++++++++ returnAddr : 0x" << returnAddr << " rbp:" << rbp - << " rsp: " << rsp; - } - COMPILER_LOG(INFO) << "do_safepoint +++ "; -} -} - HWTEST_F_L0(StubTest, GetPropertyByIndexStub) { auto module = stubModule.GetModule(); @@ -892,8 +859,8 @@ HWTEST_F_L0(StubTest, GetPropertyByIndexStub) JSHandle obj = factory->NewEmptyJSObject(); int x = 213; int y = 10; - FastRuntimeStub::SetOwnElement(thread, obj.GetTaggedValue(), 1, JSTaggedValue(x)); - FastRuntimeStub::SetOwnElement(thread, obj.GetTaggedValue(), 10250, JSTaggedValue(y)); + FastRuntimeStub::SetPropertyByIndex(thread, obj.GetTaggedValue(), 1, JSTaggedValue(x)); + FastRuntimeStub::SetPropertyByIndex(thread, obj.GetTaggedValue(), 10250, JSTaggedValue(y)); JSTaggedValue resVal = getpropertyByIndex(thread->GetGlueAddr(), obj.GetTaggedValue(), 1); EXPECT_EQ(resVal.GetNumber(), x); resVal = getpropertyByIndex(thread->GetGlueAddr(), obj.GetTaggedValue(), 10250); @@ -1057,8 +1024,8 @@ HWTEST_F_L0(StubTest, GetPropertyByValueStub) int x = 213; int y = 10; auto sp = const_cast(thread->GetCurrentSPFrame()); - FastRuntimeStub::SetOwnElement(thread, obj.GetTaggedValue(), 1, JSTaggedValue(x)); - FastRuntimeStub::SetOwnElement(thread, obj.GetTaggedValue(), 10250, JSTaggedValue(y)); + FastRuntimeStub::SetPropertyByIndex(thread, obj.GetTaggedValue(), 1, JSTaggedValue(x)); + FastRuntimeStub::SetPropertyByIndex(thread, obj.GetTaggedValue(), 10250, JSTaggedValue(y)); JSHandle strA(factory->NewFromASCII("a")); JSHandle strBig(factory->NewFromASCII("biggest")); @@ -1241,8 +1208,8 @@ HWTEST_F_L0(StubTest, FastEqualTest) // test for obj == obj JSHandle obj1 = factory->NewEmptyJSObject(); JSHandle obj2 = factory->NewEmptyJSObject(); - FastRuntimeStub::SetOwnElement(thread, obj1.GetTaggedValue(), 1, JSTaggedValue(1)); - FastRuntimeStub::SetOwnElement(thread, obj2.GetTaggedValue(), 1, JSTaggedValue(1)); + FastRuntimeStub::SetPropertyByIndex(thread, obj1.GetTaggedValue(), 1, JSTaggedValue(1)); + FastRuntimeStub::SetPropertyByIndex(thread, obj2.GetTaggedValue(), 1, JSTaggedValue(1)); auto resI = fn(thread->GetGlueAddr(), obj1.GetTaggedValue().GetRawData(), obj2.GetTaggedValue().GetRawData()); auto expectI = FastRuntimeStub::FastEqual(obj1.GetTaggedValue(), obj2.GetTaggedValue()); EXPECT_EQ(resI, expectI); @@ -1303,12 +1270,13 @@ HWTEST_F_L0(StubTest, JSCallTest2) auto glue = thread->GetGlueAddr(); int x = 1; int y = 2; - JSTaggedType argV[5] = { + JSTaggedType argV[6] = { foo1target.GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue(x).GetRawData(), JSTaggedValue(y).GetRawData(), + JSTaggedValue::Undefined().GetRawData(), }; auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry); @@ -1324,12 +1292,13 @@ HWTEST_F_L0(StubTest, JSCallNativeTest) auto glue = thread->GetGlueAddr(); int x = 1; int y = 2; - JSTaggedType argV[5] = { + JSTaggedType argV[6] = { footarget.GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue(x).GetRawData(), JSTaggedValue(y).GetRawData(), + JSTaggedValue::Undefined().GetRawData(), }; auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry); auto result = reinterpret_cast(entry)(glue, @@ -1344,12 +1313,13 @@ HWTEST_F_L0(StubTest, JSCallBoundTest) auto glue = thread->GetGlueAddr(); int x = 1; int y = 2; - JSTaggedType argV[5] = { + JSTaggedType argV[6] = { footarget.GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue(x).GetRawData(), JSTaggedValue(y).GetRawData(), + JSTaggedValue::Undefined().GetRawData(), }; auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry); @@ -1366,19 +1336,20 @@ HWTEST_F_L0(StubTest, JSCallTest3) auto glue = thread->GetGlueAddr(); int x = 1; int y = 2; - JSTaggedType argV[6] = { + JSTaggedType argV[7] = { foo2target.GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue::Undefined().GetRawData(), JSTaggedValue(x).GetRawData(), JSTaggedValue(y).GetRawData(), JSTaggedValue::Undefined().GetRawData(), + JSTaggedValue::Undefined().GetRawData(), }; JSThread::GlueData::GetCOStubEntriesOffset(false); JSThread::GlueData::GetCOStubEntriesOffset(true); auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry); auto result = reinterpret_cast(entry)(glue, - reinterpret_cast(thread->GetCurrentSPFrame()), 5, 5, argV, fooProxyEntry); + reinterpret_cast(thread->GetCurrentSPFrame()), 6, 6, argV, fooProxyEntry); EXPECT_EQ(result, JSTaggedValue(3.0).GetRawData()); } diff --git a/ecmascript/compiler/trampoline/aarch64/assembler_stubs.cpp b/ecmascript/compiler/trampoline/aarch64/assembler_stubs.cpp index 1cd2cedee38af7df5e731ca79f8b05760a4e8fb0..c4b0f7537eb69a03066f413d04cbf95bc3bcaa4b 100644 --- a/ecmascript/compiler/trampoline/aarch64/assembler_stubs.cpp +++ b/ecmascript/compiler/trampoline/aarch64/assembler_stubs.cpp @@ -16,6 +16,7 @@ #include "assembler_stubs.h" #include "ecmascript/compiler/assembler/assembler.h" +#include "ecmascript/compiler/argument_accessor.h" #include "ecmascript/compiler/common_stubs.h" #include "ecmascript/compiler/rt_call_signature.h" #include "ecmascript/ecma_runtime_call_info.h" @@ -66,21 +67,21 @@ using Label = panda::ecmascript::Label; void AssemblerStubs::CallRuntime(ExtendedAssembler *assembler) { Register glue(X0); - Register fp(X29); + Register fp(FP); Register tmp(X19); Register sp(SP); Register argC(X1); Register argV(X2); __ BindAssemblerStub(RTSTUB_ID(CallRuntime)); - __ SaveFpAndLr(); + __ PushFpAndLr(); Register frameType(X2); - __ Str(fp, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); - // construct Leave Frame and callee save __ Mov(frameType, Immediate(static_cast(FrameType::LEAVE_FRAME))); __ Stp(tmp, frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); + __ Add(fp, sp, Immediate(16)); // 16: skip frame type and tmp + __ Str(fp, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); // load runtime trampoline address Register rtfunc(X19); @@ -102,6 +103,22 @@ void AssemblerStubs::CallRuntime(ExtendedAssembler *assembler) __ Ret(); } +void AssemblerStubs::IncreaseStackForArguments(ExtendedAssembler *assembler, Register argc, Register currentSp) +{ + Register sp(SP); + __ Mov(currentSp, sp); + // add extra aguments, env and numArgs + __ Add(argc, argc, Immediate(static_cast(CommonArgIdx::ACTUAL_ARGC))); + __ Sub(currentSp, currentSp, Operand(argc, UXTW, SHIFT_OF_FRAMESLOT)); + Label aligned; + __ Tst(currentSp, LogicalImmediate::Create(0xf, RegXSize)); // 0xf: 0x1111 + __ B(Condition::EQ, &aligned); + __ Sub(currentSp, currentSp, Immediate(FRAME_SLOT_SIZE)); + __ Bind(&aligned); + __ Mov(sp, currentSp); + __ Add(currentSp, currentSp, Operand(argc, UXTW, SHIFT_OF_FRAMESLOT)); +} + // uint64_t JSFunctionEntry(uintptr_t glue, uintptr_t prevFp, uint32_t expectedNumArgs, // uint32_t actualNumArgs, const JSTaggedType argV[], uintptr_t codeAddr) // Input: %x0 - glue @@ -131,81 +148,54 @@ void AssemblerStubs::JSFunctionEntry(ExtendedAssembler *assembler) Register argV(X4); Register codeAddr(X5); Register sp(SP); - Register fp(X29); - - __ BindAssemblerStub(RTSTUB_ID(JSFunctionEntry)); - __ Str(Register(X30), MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ CalleeSave(); - __ Str(fp, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ Mov(fp, sp); - - - Register frameType(X19); - // construct frame - __ Mov(frameType, Immediate(static_cast(FrameType::OPTIMIZED_ENTRY_FRAME))); - __ Stp(prevFp, frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); - - Label copyUndefined; + Register currentSp(X6); Label copyArguments; - Register tmp(X19, W); - __ Mov(glue, Register(X0)); - __ Mov(tmp, expectedNumArgs.W()); - __ Cmp(tmp, actualNumArgs.W()); - __ B(Condition::LS, ©Arguments); - Register count(X9, W); - Register undefValue(X8); - __ Mov(count, tmp.W()); - __ Mov(undefValue, Immediate(JSTaggedValue::VALUE_UNDEFINED)); - __ Bind(©Undefined); - __ Sub(count, count, Immediate(1)); - __ Cmp(count, actualNumArgs.W()); - __ Str(undefValue, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ B(Condition::HI, ©Undefined); + __ BindAssemblerStub(RTSTUB_ID(JSFunctionEntry)); + PushJSFunctionEntryFrame (assembler, prevFp); + Register argC(X7); + __ Cmp(expectedNumArgs, actualNumArgs); + __ CMov(argC, expectedNumArgs, actualNumArgs, Condition::HI); + IncreaseStackForArguments(assembler, argC, currentSp); Label invokeCompiledJSFunction; + { + TempRegister1Scope scope1(assembler); + TempRegister2Scope scope2(assembler); + Register argc = __ TempRegister1(); + Register undefinedValue = __ TempRegister2(); + __ Subs(argc, expectedNumArgs, Operand(actualNumArgs)); + __ B(Condition::LS, ©Arguments); + PushUndefinedWithArgc(assembler, argc, undefinedValue, currentSp, nullptr); + } __ Bind(©Arguments); + __ Cbz(actualNumArgs, &invokeCompiledJSFunction); { - Register argVEnd(X9); - Register argC(X8, W); - Register argValue(X10); - Label copyArgLoop; - - // expectedNumArgs <= actualNumArgs - __ Cmp(tmp.W(), actualNumArgs.W()); - __ CMov(argC, tmp.W(), actualNumArgs.W(), Condition::LO); - __ Cbz(argC, &invokeCompiledJSFunction); - __ Sub(argVEnd.W(), argC, Immediate(1)); - __ Add(argVEnd, argV, Operand(argVEnd.W(), UXTW, 3)); - - __ Bind(©ArgLoop); - __ Ldr(argValue, MemoryOperand(argVEnd, -FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Subs(argC, argC, Immediate(1)); - __ Str(argValue, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ B(Condition::NE, ©ArgLoop); + TempRegister1Scope scope1(assembler); + TempRegister2Scope scope2(assembler); + Register argc = __ TempRegister1(); + Register argValue = __ TempRegister2(); + __ Mov(argc, actualNumArgs); + __ PushArgsWithArgv(argc, argV, argValue, currentSp, &invokeCompiledJSFunction); } __ Bind(&invokeCompiledJSFunction); { - __ Str(actualNumArgs, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + TempRegister1Scope scope1(assembler); + Register env = __ TempRegister1(); + __ Mov(Register(X19), expectedNumArgs); + __ Ldr(env, MemoryOperand(argV, actualNumArgs, UXTW, SHIFT_OF_FRAMESLOT)); + __ Str(actualNumArgs, MemoryOperand(sp, FRAME_SLOT_SIZE)); + __ Str(env, MemoryOperand(sp, 0)); __ Blr(codeAddr); } - // pop argV argC + // pop argV // 3 : 3 means argC * 8 - __ Add(sp, sp, Operand(tmp, UXTW, 3)); - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); + __ Ldr(actualNumArgs, MemoryOperand(sp, FRAME_SLOT_SIZE)); + PopJSFunctionArgs(assembler, Register(X19), actualNumArgs); // pop prevLeaveFrameFp to restore thread->currentFrame_ - __ Ldr(prevFp, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Str(prevFp, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); - - // pop entry frame type and c-fp - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); - __ Ldr(fp, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - - __ CalleeRestore(); - // restore return address - __ Ldr(Register(X30), MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + PopJSFunctionEntryFrame(assembler, glue); __ Ret(); } @@ -216,6 +206,7 @@ void AssemblerStubs::JSFunctionEntry(ExtendedAssembler *assembler) // %w2 - actualNumArgs // %x3 - codeAddr // %x4 - argv +// %x5 - env // sp[0 * 8] - argc // sp[1 * 8] - argv[0] @@ -232,76 +223,63 @@ void AssemblerStubs::OptimizedCallOptimized(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(OptimizedCallOptimized)); Register expectedNumArgs(X1); - Register sp(SP); - __ SaveFpAndLr(); - // Construct frame - Register frameType(X5); - __ Mov(frameType, Immediate(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME))); - __ Str(frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - - // callee save - Register tmp(X19); - __ Str(tmp, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - - Register count(X5, W); Register actualNumArgs(X2, W); + Register codeAddr(X3); + Register argV(X4); + Register env(X5); + Register currentSp(X6); + Register sp(SP); Label copyArguments; - __ Mov(count, expectedNumArgs); - __ Cmp(count, actualNumArgs); - __ B(Condition::LS, ©Arguments); - - Register undefValue(X8); - __ Mov(undefValue, Immediate(JSTaggedValue::VALUE_UNDEFINED)); - Label copyUndefined; - __ Sub(count, count, Immediate(1)); - __ Str(undefValue, MemoryOperand(sp, -FRAME_SLOT_SIZE, PREINDEX)); - __ Cmp(count, actualNumArgs); - __ B(Condition::HI, ©Undefined); - Label invokeCompiledJSFunction; - Register saveNumArgs(X19); + + // construct frame + PushOptimizedJSFunctionFrame(assembler); + Register argC(X7); + __ Cmp(expectedNumArgs, actualNumArgs); + __ CMov(argC, expectedNumArgs, actualNumArgs, Condition::HI); + IncreaseStackForArguments(assembler, argC, currentSp); + { + TempRegister1Scope scope1(assembler); + TempRegister2Scope scope2(assembler); + Register tmp = __ TempRegister1(); + Register undefinedValue = __ TempRegister2(); + __ Subs(tmp, expectedNumArgs, actualNumArgs); + __ B(Condition::LS, ©Arguments); + PushUndefinedWithArgc(assembler, tmp, undefinedValue, currentSp, nullptr); + } __ Bind(©Arguments); + __ Cbz(actualNumArgs, &invokeCompiledJSFunction); { - __ Cmp(expectedNumArgs.W(), actualNumArgs.W()); - __ CMov(count, expectedNumArgs.W(), actualNumArgs.W(), Condition::LO); - __ Cbz(count, &invokeCompiledJSFunction); - - Register argVEnd(X4); - Register argValue(X10); - Label copyArgLoop; - __ Mov(saveNumArgs, expectedNumArgs); - __ Subs(count, count, Immediate(1)); - // 3 : 3 means count * 8 - __ Add(argVEnd, argVEnd, Operand(count, UXTW, 3)); - __ Bind(©ArgLoop); - __ Ldr(argValue, MemoryOperand(argVEnd, -FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Subs(count, count, Immediate(1)); - __ Str(argValue, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ B(Condition::PL, ©ArgLoop); + TempRegister1Scope scope1(assembler); + TempRegister2Scope scope2(assembler); + Register argc = __ TempRegister1(); + Register argValue = __ TempRegister2(); + __ Mov(argc, actualNumArgs); + __ PushArgsWithArgv(argc, argV, argValue, currentSp, &invokeCompiledJSFunction); } - - Register codeAddr(X3); __ Bind(&invokeCompiledJSFunction); - __ Str(actualNumArgs, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ Blr(codeAddr); - // pop argv - // 3 : 3 means count * 8 - __ Add(sp, sp, Operand(saveNumArgs, UXTW, 3)); - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); - // callee restore - __ Ldr(saveNumArgs, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - // desconstruct frame - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); - __ RestoreFpAndLr(); + { + __ Mov(Register(X19), expectedNumArgs); + __ Str(actualNumArgs, MemoryOperand(sp, FRAME_SLOT_SIZE)); + __ Str(env, MemoryOperand(sp, 0)); + __ Blr(codeAddr); + } + + // pop argV argC + // 3 : 3 means argC * 8 + __ Ldr(actualNumArgs, MemoryOperand(sp, FRAME_SLOT_SIZE)); + PopJSFunctionArgs(assembler, Register(X19), actualNumArgs); + // pop prevLeaveFrameFp to restore thread->currentFrame_ + PopOptimizedJSFunctionFrame(assembler); __ Ret(); } void AssemblerStubs::OptimizedCallAsmInterpreter(ExtendedAssembler *assembler) { Label target; - PushAsmInterpEntryFrame(assembler, false); + PushAsmInterpBridgeFrame(assembler); __ Bl(&target); - PopAsmInterpEntryFrame(assembler, false); + PopAsmInterpBridgeFrame(assembler); __ Ret(); __ Bind(&target); { @@ -310,23 +288,72 @@ void AssemblerStubs::OptimizedCallAsmInterpreter(ExtendedAssembler *assembler) } } +void AssemblerStubs::PushLeaveFrame(ExtendedAssembler *assembler, Register glue, bool isBuiltin) +{ + TempRegister2Scope temp2Scope(assembler); + Register frameType = __ TempRegister2(); + Register currentSp(X6); + Register sp(SP); + Register prevfp(X29); + + // construct leave frame + if (isBuiltin) { + __ Mov(frameType, Immediate(static_cast(FrameType::BUILTIN_CALL_LEAVE_FRAME))); + // current sp is not 16bytes aligned because native code address has pushed. + __ Mov(currentSp, sp); + __ Sub(sp, sp, Immediate(3 * FRAME_SLOT_SIZE)); // 3 : 3 for 16bytes align + // 2 : 2 means pairs + __ Stp(prevfp, Register(X30), MemoryOperand(currentSp, -2 * FRAME_SLOT_SIZE, PREINDEX)); + __ Str(frameType, MemoryOperand(currentSp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Add(prevfp, sp, Immediate(FRAME_SLOT_SIZE)); + } else { + __ Mov(frameType, Immediate(static_cast(FrameType::LEAVE_FRAME))); + __ SaveFpAndLr(); + // 2 : 2 means pairs + __ Stp(Register(X19), frameType, MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + } + // save to thread currentLeaveFrame_; + __ Str(prevfp, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); +} + + +void AssemblerStubs::PopLeaveFrame(ExtendedAssembler *assembler, bool isBuiltin) +{ + Register sp(SP); + Register currentSp(X6); + TempRegister2Scope temp2Scope(assembler); + Register frameType = __ TempRegister2(); + if (isBuiltin) { + __ Add(currentSp, sp, Immediate(FRAME_SLOT_SIZE)); // skip frame type + __ Add(sp, sp, Immediate(3 * FRAME_SLOT_SIZE)); // 3 : 3 means for 16bytes align + // 2 : 2 means pairs + __ Ldp(Register(X29), Register(X30), MemoryOperand(currentSp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + } else { + // 2 : 2 means pairs + __ Ldp(Register(X19), frameType, MemoryOperand(sp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + __ RestoreFpAndLr(); + } +} + // uint64_t CallBuiltinTrampoline(uintptr_t glue, uintptr_t codeAddress, uint32_t argc, ...) // webkit_jscc calling convention call runtime_id's runtion function(c-abi) // Input: // %x0 - glue // stack layout: sp + N*8 argvN // ........ -// sp + 24: argv1 -// sp + 16: argv0 -// sp + 8: actualArgc +// sp + 24: argv0 +// sp + 16: actualArgc +// sp + 8: env // sp: codeAddress // construct Native Leave Frame // +--------------------------+ // | argv0 | calltarget , newtARGET, this, .... // +--------------------------+ --- // | argc | ^ +// |--------------------------| | +// | env | thread | | // |--------------------------| Fixed -// | codeAddress | OptimizedLeaveFrame +// | codeAddress | OptimizedBuiltinLeaveFrame // |--------------------------| | // | returnAddr | | // |--------------------------| | @@ -341,52 +368,20 @@ void AssemblerStubs::OptimizedCallAsmInterpreter(ExtendedAssembler *assembler) void AssemblerStubs::CallBuiltinTrampoline(ExtendedAssembler *assembler) { - __ BindAssemblerStub(RTSTUB_ID(CallBuiltinTrampoline)); - __ SaveFpAndLr(); - // save to thread currentLeaveFrame_; Register fp(X29); Register glue(X0); Register sp(SP); - __ Str(fp, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); + Register nativeFuncAddr(X4); - Register nativeFuncAddr(X19); + PushLeaveFrame(assembler, glue, true); - // construct leave frame and callee save - Register frameType(X1); - __ Mov(frameType, Immediate(static_cast(FrameType::LEAVE_FRAME))); - // 2 : 2 means pair - __ Stp(nativeFuncAddr, frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); - - // load runtime trampoline address - __ Ldr(nativeFuncAddr, MemoryOperand(fp, GetStackArgOffSetToFp(0))); - - // construct ecma_runtime_call_info - __ Sub(sp, sp, Immediate(sizeof(EcmaRuntimeCallInfo))); - Register glueToThread(X1); - Register thread(X0); - __ Mov(glueToThread, JSThread::GetGlueDataOffset()); - __ Sub(thread, glue, glueToThread); // thread - __ Str(thread, MemoryOperand(sp, 0)); - Register argC(X0); - // 1 : 1 means argC id - __ Ldr(argC, MemoryOperand(fp, GetStackArgOffSetToFp(1))); // argc - __ Sub(argC, argC, Immediate(NUM_MANDATORY_JSFUNC_ARGS)); - __ Str(argC, MemoryOperand(sp, EcmaRuntimeCallInfo::GetNumArgsOffset())); - Register argV(X0); - // 2 : 2 means argV id - __ Add(argV, fp, Immediate(GetStackArgOffSetToFp(2))); // argV - __ Str(argV, MemoryOperand(sp, EcmaRuntimeCallInfo::GetStackArgsOffset())); - - Register callInfo(X0); - __ Mov(callInfo, sp); + __ Str(glue, MemoryOperand(fp, GetStackArgOffSetToFp(BuiltinsLeaveFrameArgId::ENV))); // thread (instead of env) + __ Add(Register(X0), fp, Immediate(GetStackArgOffSetToFp(BuiltinsLeaveFrameArgId::ENV))); __ Blr(nativeFuncAddr); - __ Add(sp, sp, Immediate(sizeof(EcmaRuntimeCallInfo))); - // descontruct leave frame and callee save register - __ Ldp(nativeFuncAddr, frameType, MemoryOperand(sp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ RestoreFpAndLr(); - __ Add(sp, sp, Immediate(8)); // 8 : 8 skip native code address + PopLeaveFrame(assembler, true); + __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); // skip native code address __ Ret(); } @@ -424,7 +419,7 @@ void AssemblerStubs::JSCall(ExtendedAssembler *assembler) __ BindAssemblerStub(RTSTUB_ID(JSCall)); Register jsfunc(X1); Register sp(SP); - __ Ldr(jsfunc, MemoryOperand(sp, FRAME_SLOT_SIZE)); + __ Ldr(jsfunc, MemoryOperand(sp, FRAME_SLOT_SIZE * 2)); // 2: skip env and argc JSCallBody(assembler, jsfunc); } @@ -434,11 +429,11 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) Register taggedValue(X2); Label nonCallable; Label notJSFunction; - __ Mov(taggedValue, JSTaggedValue::TAG_MASK); + __ Mov(taggedValue, JSTaggedValue::TAG_MARK); __ Cmp(jsfunc, taggedValue); __ B(Condition::HS, &nonCallable); __ Cbz(jsfunc, &nonCallable); - __ Mov(taggedValue, JSTaggedValue::TAG_SPECIAL_VALUE); + __ Mov(taggedValue, JSTaggedValue::TAG_SPECIAL); __ And(taggedValue, jsfunc, taggedValue); __ Cbnz(taggedValue, &nonCallable); @@ -451,9 +446,10 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) Register jstype(X3, W); __ And(jstype, bitfield, LogicalImmediate::Create(0xFF, RegWSize)); // 4 : 4 means JSType::JS_FUNCTION_BEGIN - __ Sub(jstype, jstype, Immediate(4)); + __ Sub(jstype, jstype, Immediate(static_cast(JSType::JS_FUNCTION_BEGIN))); // 9 : 9 means JSType::JS_FUNCTION_END - JSType::JS_FUNCTION_BEGIN + 1 - __ Cmp(jstype, Immediate(9)); + __ Cmp(jstype, Immediate(static_cast(JSType::JS_FUNCTION_END) + - static_cast(JSType::JS_FUNCTION_BEGIN) + 1)); __ B(Condition::HS, ¬JSFunction); Register method(X2); @@ -462,14 +458,14 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) Label callNativeMethod; Label callOptimizedMethod; __ Ldr(method, MemoryOperand(jsfunc, JSFunction::METHOD_OFFSET)); - __ Ldr(actualArgC, MemoryOperand(sp, 0)); + __ Ldr(actualArgC, MemoryOperand(sp, FRAME_SLOT_SIZE)); __ Ldr(callField, MemoryOperand(method, JSMethod::GetCallFieldOffset(false))); __ Tbnz(callField, JSMethod::IsNativeBit::START_BIT, &callNativeMethod); __ Tbnz(callField, JSMethod::IsAotCodeBit::START_BIT, &callOptimizedMethod); { Register argV(X5); - // 8 : 8 mean argV = sp + 8 - __ Add(argV, sp, Immediate(8)); + // argV = sp + 16 + __ Add(argV, sp, Immediate(DOUBLE_SLOT_SIZE)); OptimizedCallAsmInterpreter(assembler); } @@ -479,7 +475,7 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) __ Ldr(nativeFuncAddr, MemoryOperand(method, JSMethod::GetNativePointerOffset())); // -8 : -8 means sp increase step __ Str(nativeFuncAddr, MemoryOperand(sp, -8, AddrMode::PREINDEX)); - __ CallAssemblerStub(RTSTUB_ID(CallBuiltinTrampoline), true); + CallBuiltinTrampoline(assembler); } __ Bind(&callOptimizedMethod); @@ -488,16 +484,19 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) Register arg2(X2); Register codeAddress(X3); Register argV(X4); + Register env(X5); Label directCallCodeEntry; + const int64_t argoffsetSlot = static_cast(CommonArgIdx::FUNC) - 1; + __ Mov(Register(X5), jsfunc); __ Mov(arg2, actualArgC); - __ Ldr(codeAddress, MemoryOperand(jsfunc, JSFunctionBase::CODE_ENTRY_OFFSET)); __ Lsr(callField, callField, JSMethod::NumArgsBits::START_BIT); __ And(callField.W(), callField.W(), LogicalImmediate::Create(JSMethod::NumArgsBits::Mask() >> JSMethod::NumArgsBits::START_BIT, RegWSize)); __ Add(expectedNumArgs, callField.W(), Immediate(NUM_MANDATORY_JSFUNC_ARGS)); __ Cmp(arg2.W(), expectedNumArgs); - // 8 : 8 mean argV = sp + 8 - __ Add(argV, sp, Immediate(8)); + __ Add(argV, sp, Immediate(argoffsetSlot * FRAME_SLOT_SIZE)); // skip env and numArgs + __ Ldr(codeAddress, MemoryOperand(Register(X5), JSFunctionBase::CODE_ENTRY_OFFSET)); + __ Ldr(env, MemoryOperand(sp, 0)); __ B(Condition::HS, &directCallCodeEntry); __ CallAssemblerStub(RTSTUB_ID(OptimizedCallOptimized), true); __ Bind(&directCallCodeEntry); @@ -518,82 +517,69 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) __ Bind(&jsBoundFunction); { - __ SaveFpAndLr(); // construct frame - Register frameType(X5); - Register fp(X29); - __ Mov(frameType, Immediate(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME))); - __ Str(frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - Register argVEnd(X4); - __ Add(argVEnd, fp, Immediate(GetStackArgOffSetToFp(0))); - __ Ldr(actualArgC, MemoryOperand(argVEnd, 0)); - // callee save - Register tmp(X19); - __ Str(tmp, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + PushOptimizedJSFunctionFrame(assembler); + Register basefp(X29); + Register fp = __ AvailableRegister1(); + Register env(X5); + + Register argV(X6); + __ Add(argV, basefp, Immediate(GetStackArgOffSetToFp(0))); + __ Ldr(actualArgC, MemoryOperand(argV, FRAME_SLOT_SIZE)); + __ Ldr(env, MemoryOperand(argV, 0)); Register boundLength(X2); - Register realArgC(X19, W); + Register realArgC(X7, W); Label copyBoundArgument; - Label copyArgument; Label pushCallTarget; // get bound arguments __ Ldr(boundLength, MemoryOperand(jsfunc, JSBoundFunction::BOUND_ARGUMENTS_OFFSET)); // get bound length __ Ldr(boundLength, MemoryOperand(boundLength, TaggedArray::LENGTH_OFFSET)); __ Add(realArgC, boundLength.W(), actualArgC.W()); - // 3 : 3 mean *8 - __ Add(argVEnd, argVEnd, Operand(actualArgC.W(), UXTW, 3)); + __ Mov(Register(X19), realArgC); + IncreaseStackForArguments(assembler, realArgC, fp); __ Sub(actualArgC.W(), actualArgC.W(), Immediate(NUM_MANDATORY_JSFUNC_ARGS)); __ Cmp(actualArgC.W(), Immediate(0)); __ B(Condition::EQ, ©BoundArgument); - __ Bind(©Argument); { - Register argValue(X5); - __ Ldr(argValue, MemoryOperand(argVEnd, -FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Str(argValue, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ Sub(actualArgC.W(), actualArgC.W(), Immediate(1)); - __ Cmp(actualArgC.W(), Immediate(0)); - __ B(Condition::NE, ©Argument); + TempRegister1Scope scope1(assembler); + Register tmp = __ TempRegister1(); + const int64_t argoffsetSlot = static_cast(CommonArgIdx::FUNC) - 1; + __ Add(argV, argV, Immediate((NUM_MANDATORY_JSFUNC_ARGS + argoffsetSlot) *FRAME_SLOT_SIZE)); + __ PushArgsWithArgv(actualArgC, argV, tmp, fp, nullptr); } __ Bind(©BoundArgument); { Register boundArgs(X4); - Label copyBoundArgumentLoop; __ Ldr(boundArgs, MemoryOperand(jsfunc, JSBoundFunction::BOUND_ARGUMENTS_OFFSET)); __ Add(boundArgs, boundArgs, Immediate(TaggedArray::DATA_OFFSET)); __ Cmp(boundLength.W(), Immediate(0)); __ B(Condition::EQ, &pushCallTarget); - __ Sub(boundLength.W(), boundLength.W(), Immediate(1)); - // 3 : 3 means 2^3 = 8 - __ Add(boundArgs, boundArgs, Operand(boundLength.W(), UXTW, 3)); - __ Bind(©BoundArgumentLoop); { - Register boundargValue(X5); - __ Ldr(boundargValue, MemoryOperand(boundArgs, -FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Str(boundargValue, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ Subs(boundLength.W(), boundLength.W(), Immediate(1)); - __ B(Condition::PL, ©BoundArgumentLoop); + TempRegister1Scope scope1(assembler); + Register tmp = __ TempRegister1(); + __ PushArgsWithArgv(boundLength, boundArgs, tmp, fp, nullptr); } } __ Bind(&pushCallTarget); { - Register thisObj(X5); + Register thisObj(X4); Register newTarget(X6); Register boundTarget(X7); __ Ldr(thisObj, MemoryOperand(jsfunc, JSBoundFunction::BOUND_THIS_OFFSET)); __ Mov(newTarget, Immediate(JSTaggedValue::VALUE_UNDEFINED)); - __ Stp(newTarget, thisObj, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); + // 2 : 2 means pair + __ Stp(newTarget, thisObj, MemoryOperand(fp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); __ Ldr(boundTarget, MemoryOperand(jsfunc, JSBoundFunction::BOUND_TARGET_OFFSET)); // 2 : 2 means pair - __ Stp(realArgC.X(), boundTarget, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); + __ Stp(Register(X19), boundTarget, MemoryOperand(fp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); + __ Str(env, MemoryOperand(fp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } __ CallAssemblerStub(RTSTUB_ID(JSCall), false); - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); - // 3 : 3 means 2^3 = 8 - __ Add(sp, sp, Operand(realArgC, UXTW, 3)); - __ Ldr(tmp, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); - __ RestoreFpAndLr(); + + PopJSFunctionArgs(assembler, Register(X19), Register(X19)); + PopOptimizedJSFunctionFrame(assembler); __ Ret(); } __ Bind(&jsProxy); @@ -601,15 +587,14 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) // input: x1(calltarget) // output: glue:x0 argc:x1 calltarget:x2 argv:x3 __ Mov(Register(X2), jsfunc); - __ Ldr(Register(X1), MemoryOperand(sp, 0)); - __ Add(X3, sp, Immediate(FRAME_SLOT_SIZE)); + __ Ldr(Register(X1), MemoryOperand(sp, FRAME_SLOT_SIZE)); // 8: skip env + __ Add(X3, sp, Immediate(FRAME_SLOT_SIZE * 2)); // 2: get argv Register proxyCallInternalId(Register(X9).W()); Register codeAddress(X10); __ Mov(proxyCallInternalId, Immediate(CommonStubCSigns::JsProxyCallInternal)); __ Add(codeAddress, X0, Immediate(JSThread::GlueData::GetCOStubEntriesOffset(false))); - // 3 : 3 means 2 << 3 = 8 - __ Ldr(codeAddress, MemoryOperand(codeAddress, proxyCallInternalId, UXTW, 3)); + __ Ldr(codeAddress, MemoryOperand(codeAddress, proxyCallInternalId, UXTW, SHIFT_OF_FRAMESLOT)); __ Br(codeAddress); } __ Bind(&nonCallable); @@ -637,9 +622,9 @@ void AssemblerStubs::JSCallBody(ExtendedAssembler *assembler, Register jsfunc) } } -void AssemblerStubs::JSCallWithArgV(ExtendedAssembler *assembler) +void AssemblerStubs::JSProxyCallInternalWithArgV(ExtendedAssembler *assembler) { - __ BindAssemblerStub(RTSTUB_ID(JSCallWithArgV)); + __ BindAssemblerStub(RTSTUB_ID(JSProxyCallInternalWithArgV)); Register jsfunc(X1); Register argv(X3); __ Mov(jsfunc, Register(X2)); @@ -683,16 +668,19 @@ void AssemblerStubs::CallRuntimeWithArgv(ExtendedAssembler *assembler) // Generate code for entering asm interpreter // c++ calling convention -// Input: %X0 - glue -// %X1 - argc -// %X2 - argv( are at the beginning of argv) +// Input: glue - %X0 +// callTarget - %X1 +// method - %X2 +// callField - %X3 +// argc - %X4 +// argv - %X5( are at the beginning of argv) void AssemblerStubs::AsmInterpreterEntry(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(AsmInterpreterEntry)); Label target; - PushAsmInterpEntryFrame(assembler, true); + PushAsmInterpEntryFrame(assembler); __ Bl(&target); - PopAsmInterpEntryFrame(assembler, true); + PopAsmInterpEntryFrame(assembler); __ Ret(); __ Bind(&target); @@ -701,29 +689,26 @@ void AssemblerStubs::AsmInterpreterEntry(ExtendedAssembler *assembler) } } -// Input: glueRegister - %X0 -// argcRegister - %X1 -// argvRegister - %X2( are at the beginning of argv) -// prevSpRegister - %X29 +// Input: glue - %X0 +// callTarget - %X1 +// method - %X2 +// callField - %X3 +// argc - %X4 +// argv - %X5( are at the beginning of argv) void AssemblerStubs::JSCallDispatch(ExtendedAssembler *assembler) { Label notJSFunction; Label callNativeEntry; Label callJSFunctionEntry; - Label pushArgsSlowPath; - Label callJSProxyEntry; Label notCallable; Register glueRegister(X0); - Register argcRegister(X1, W); - Register argvRegister(X2); - Register prevSpRegister(X29); - - Register callTargetRegister(X3); - Register methodRegister(X4); - Register bitFieldRegister(X5); - Register tempRegister(X6); // can not be used to store any variable - Register functionTypeRegister(X7, W); - __ Ldr(callTargetRegister, MemoryOperand(argvRegister, 0)); + Register argcRegister(X4, W); + Register argvRegister(X5); + Register callTargetRegister(X1); + Register callFieldRegister(X3); + Register bitFieldRegister(X16); + Register tempRegister(X17); // can not be used to store any variable + Register functionTypeRegister(X18, W); __ Ldr(tempRegister, MemoryOperand(callTargetRegister, 0)); // hclass __ Ldr(bitFieldRegister, MemoryOperand(tempRegister, JSHClass::BIT_FIELD_OFFSET)); __ And(functionTypeRegister, bitFieldRegister.W(), LogicalImmediate::Create(0xFF, RegWSize)); @@ -738,39 +723,17 @@ void AssemblerStubs::JSCallDispatch(ExtendedAssembler *assembler) __ Tst(bitFieldRegister, LogicalImmediate::Create(static_cast(1ULL << JSHClass::CallableBit::START_BIT), RegXSize)); __ B(Condition::EQ, ¬Callable); - __ Mov(tempRegister.W(), Immediate(static_cast(JSType::JS_PROXY))); - __ Cmp(functionTypeRegister, tempRegister.W()); - __ B(Condition::EQ, &callJSProxyEntry); - // bound function branch, default native - __ Ldr(methodRegister, MemoryOperand(callTargetRegister, JSFunctionBase::METHOD_OFFSET)); // fall through } __ Bind(&callNativeEntry); CallNativeEntry(assembler); - __ Bind(&callJSProxyEntry); - { - __ Ldr(methodRegister, MemoryOperand(callTargetRegister, JSProxy::METHOD_OFFSET)); - __ B(&callNativeEntry); - } __ Bind(&callJSFunctionEntry); { - __ Ldr(methodRegister, MemoryOperand(callTargetRegister, JSFunctionBase::METHOD_OFFSET)); - Register callFieldRegister(X7); - __ Ldr(callFieldRegister, MemoryOperand(methodRegister, JSMethod::GetCallFieldOffset(false))); __ Tbnz(callFieldRegister, JSMethod::IsNativeBit::START_BIT, &callNativeEntry); - Register declaredNumArgsRegister(X9); - GetDeclaredNumArgsFromCallField(assembler, callFieldRegister, declaredNumArgsRegister); - __ Cmp(declaredNumArgsRegister.W(), argcRegister); - __ B(Condition::NE, &pushArgsSlowPath); // fast path __ PushFpAndLr(); - Register fpRegister(X10); - __ Mov(fpRegister, Register(SP)); - PushArgsFastPath(assembler, glueRegister, argcRegister, argvRegister, callTargetRegister, methodRegister, - prevSpRegister, fpRegister, callFieldRegister); - __ Bind(&pushArgsSlowPath); - PushArgsSlowPath(assembler, glueRegister, declaredNumArgsRegister, argcRegister, argvRegister, - callTargetRegister, methodRegister, prevSpRegister, callFieldRegister); + __ Add(argvRegister, argvRegister, Immediate(NUM_MANDATORY_JSFUNC_ARGS * JSTaggedValue::TaggedTypeSize())); + JSCallCommonEntry(assembler, JSCallMode::CALL_ENTRY); } __ Bind(¬Callable); { @@ -798,8 +761,8 @@ void AssemblerStubs::JSCallCommonEntry(ExtendedAssembler *assembler, JSCallMode Register thisRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG2); [[maybe_unused]] TempRegister1Scope scope(assembler); Register tempArgcRegister = __ TempRegister1(); - __ PushArgc(argcRegister, tempArgcRegister); - __ Str(thisRegister, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ PushArgc(argcRegister, tempArgcRegister, fpRegister); + __ Str(thisRegister, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); jumpSize = 0; } @@ -837,6 +800,7 @@ void AssemblerStubs::JSCallCommonEntry(ExtendedAssembler *assembler, JSCallMode void AssemblerStubs::JSCallCommonFastPath(ExtendedAssembler *assembler, JSCallMode mode, Label *pushCallThis) { auto argc = kungfu::AssemblerModule::GetArgcFromJSCallMode(mode); + Register fpRegister = __ AvailableRegister1(); // call range if (argc < 0) { Register numRegister = __ AvailableRegister2(); @@ -845,19 +809,19 @@ void AssemblerStubs::JSCallCommonFastPath(ExtendedAssembler *assembler, JSCallMo __ Mov(numRegister, argcRegister); [[maybe_unused]] TempRegister1Scope scope(assembler); Register opRegister = __ TempRegister1(); - __ PushArgsWithArgv(numRegister, argvRegister, opRegister, pushCallThis); + __ PushArgsWithArgv(numRegister, argvRegister, opRegister, fpRegister, pushCallThis); } else if (argc > 0) { Register arg0 = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG0); Register arg1 = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); Register arg2 = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG2); if (argc > 2) { // 2: call arg2 - __ Str(arg2, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(arg2, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } if (argc > 1) { - __ Str(arg1, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(arg1, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } if (argc > 0) { - __ Str(arg0, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(arg0, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } } } @@ -868,7 +832,7 @@ void AssemblerStubs::JSCallCommonSlowPath(ExtendedAssembler *assembler, JSCallMo Register callFieldRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::CALL_FIELD); Register argcRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARGC); Register argvRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARGV); - + Register fpRegister = __ AvailableRegister1(); Register arg0 = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG0); Register arg1 = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); Label noExtraEntry; @@ -882,9 +846,9 @@ void AssemblerStubs::JSCallCommonSlowPath(ExtendedAssembler *assembler, JSCallMo [[maybe_unused]] TempRegister1Scope scope1(assembler); Register tempArgcRegister = __ TempRegister1(); if (argc >= 0) { - __ PushArgc(argc, tempArgcRegister); + __ PushArgc(argc, tempArgcRegister, fpRegister); } else { - __ PushArgc(argcRegister, tempArgcRegister); + __ PushArgc(argcRegister, tempArgcRegister, fpRegister); } // fall through } @@ -894,7 +858,8 @@ void AssemblerStubs::JSCallCommonSlowPath(ExtendedAssembler *assembler, JSCallMo { [[maybe_unused]] TempRegister1Scope scope(assembler); Register tempRegister = __ TempRegister1(); - PushUndefinedWithArgc(assembler, declaredNumArgsRegister, tempRegister, nullptr); + PushUndefinedWithArgc(assembler, + declaredNumArgsRegister, tempRegister, fpRegister, nullptr); } __ B(fastPathEntry); return; @@ -908,7 +873,7 @@ void AssemblerStubs::JSCallCommonSlowPath(ExtendedAssembler *assembler, JSCallMo } [[maybe_unused]] TempRegister2Scope scope2(assembler); Register tempRegister = __ TempRegister2(); - PushUndefinedWithArgc(assembler, diffRegister, tempRegister, &pushArgsEntry); + PushUndefinedWithArgc(assembler, diffRegister, tempRegister, fpRegister, &pushArgsEntry); __ B(fastPathEntry); } // declare < actual @@ -927,19 +892,19 @@ void AssemblerStubs::JSCallCommonSlowPath(ExtendedAssembler *assembler, JSCallMo if (argc < 0) { [[maybe_unused]] TempRegister1Scope scope(assembler); Register opRegister = __ TempRegister1(); - __ PushArgsWithArgv(declaredNumArgsRegister, argvRegister, opRegister, nullptr); + __ PushArgsWithArgv(declaredNumArgsRegister, argvRegister, opRegister, fpRegister, nullptr); } else if (argc > 0) { Label pushArgs0; if (argc > 2) { // 2: call arg2 // decalare is 2 or 1 now __ Cmp(declaredNumArgsRegister, Immediate(1)); __ B(Condition::EQ, &pushArgs0); - __ Str(arg1, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(arg1, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } if (argc > 1) { __ Bind(&pushArgs0); // decalare is is 1 now - __ Str(arg0, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(arg0, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } } __ B(pushCallThis); @@ -955,8 +920,34 @@ Register AssemblerStubs::GetThisRegsiter(ExtendedAssembler *assembler, JSCallMod return __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); case JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV: case JSCallMode::CALL_THIS_WITH_ARGV: - case JSCallMode::CALL_FROM_AOT: return __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG2); + case JSCallMode::CALL_FROM_AOT: + case JSCallMode::CALL_ENTRY: { + Register argvRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); + Register thisRegister = __ AvailableRegister2(); + __ Ldur(thisRegister, MemoryOperand(argvRegister, -FRAME_SLOT_SIZE)); + return thisRegister; + } + default: + UNREACHABLE(); + } + return INVALID_REG; +} + +Register AssemblerStubs::GetNewTargetRegsiter(ExtendedAssembler *assembler, JSCallMode mode) +{ + switch (mode) { + case JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV: + case JSCallMode::CALL_THIS_WITH_ARGV: + return __ CallDispatcherArgument(kungfu::CallDispatchInputs::CALL_TARGET); + case JSCallMode::CALL_FROM_AOT: + case JSCallMode::CALL_ENTRY: { + Register argvRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); + Register newTargetRegister = __ AvailableRegister2(); + // 2: new Target index + __ Ldur(newTargetRegister, MemoryOperand(argvRegister, -2 * FRAME_SLOT_SIZE)); + return newTargetRegister; + } default: UNREACHABLE(); } @@ -1048,52 +1039,61 @@ void AssemblerStubs::CallNativeWithArgv(ExtendedAssembler *assembler, bool callN Register opArgc(X8); Register opArgv(X9); Register temp(X10); - Register stackArgs(X11); - Register sp(SP); + Register fpRegister(X11); + Register spRegister(SP); Label pushThis; - - PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_FRAME_WITH_ARGV, temp); - + PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_FRAME_WITH_ARGV, temp, argc); StackOverflowCheck(assembler); - __ Str(argc, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Mov(fpRegister, spRegister); __ Mov(opArgc, argc); __ Mov(opArgv, argv); - __ PushArgsWithArgv(opArgc, opArgv, temp, &pushThis); + __ PushArgsWithArgv(opArgc, opArgv, temp, fpRegister, &pushThis); __ Bind(&pushThis); - __ Str(thisObj, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // this // newTarget if (callNew) { - __ Str(callTarget, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + // 16: this & newTarget + __ Stp(callTarget, thisObj, MemoryOperand(fpRegister, -16, AddrMode::PREINDEX)); } else { __ Mov(temp, Immediate(JSTaggedValue::VALUE_UNDEFINED)); - __ Str(temp, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + // 16: this & newTarget + __ Stp(temp, thisObj, MemoryOperand(fpRegister, -16, AddrMode::PREINDEX)); } - __ Str(callTarget, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // callTarget - __ Mov(stackArgs, sp); + // callTarget + __ Str(callTarget, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Add(temp, fpRegister, Immediate(40)); // 40: skip frame type, numArgs, func, newTarget and this + __ Add(Register(FP), temp, Operand(argc, LSL, 3)); // 3: argc * 8 + + __ Add(temp, argc, Immediate(NUM_MANDATORY_JSFUNC_ARGS)); + // 2: thread & argc + __ Stp(glue, temp, MemoryOperand(fpRegister, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Add(Register(X0), fpRegister, Immediate(0)); + + __ Align16(fpRegister); + __ Mov(spRegister, fpRegister); - CallNativeInternal(assembler, glue, argc, stackArgs, nativeCode); + CallNativeInternal(assembler, nativeCode); __ Ret(); } -// uint64_t PushCallArgsAndDispatchNative(uintptr_t glue, uintptr_t codeAddress, uint32_t argc, ...) +// uint64_t PushCallArgsAndDispatchNative(uintptr_t codeAddress, uintptr_t glue, uint32_t argc, ...) // webkit_jscc calling convention call runtime_id's runtion function(c-abi) -// Input: X0 - glue +// Input: X0 - codeAddress // stack layout: sp + N*8 argvN // ........ // sp + 24: argv1 // sp + 16: argv0 // sp + 8: actualArgc -// sp: codeAddress +// sp: thread // construct Native Leave Frame // +--------------------------+ // | argv0 | calltarget , newTarget, this, .... // +--------------------------+ --- // | argc | ^ // |--------------------------| Fixed -// | codeAddress | BuiltinFrame +// | thread | BuiltinFrame // |--------------------------| | // | returnAddr | | // |--------------------------| | @@ -1105,39 +1105,49 @@ void AssemblerStubs::PushCallArgsAndDispatchNative(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(PushCallArgsAndDispatchNative)); - Register glue(X0); - Register nativeCode = __ AvailableRegister1(); - Register argc(X4); + Register nativeCode(X0); + Register glue(X1); Register argv(X5); Register temp(X6); - Register fp(FP); + Register sp(SP); + Register nativeCodeTemp(X2); - PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_FRAME, temp); + __ Mov(nativeCodeTemp, nativeCode); - __ Ldr(nativeCode, MemoryOperand(fp, BuiltinFrame::GetNativeCodeToFpDelta(false))); - __ Ldr(argc, MemoryOperand(fp, BuiltinFrame::GetNumArgsToFpDelta(false))); - __ Add(argv, fp, Immediate(BuiltinFrame::GetStackArgsToFpDelta(false))); + __ Ldr(glue, MemoryOperand(sp, 0)); + __ Add(Register(X0), sp, Immediate(0)); + PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_FRAME, temp, argv); - CallNativeInternal(assembler, glue, argc, argv, nativeCode); + CallNativeInternal(assembler, nativeCodeTemp); __ Ret(); } -void AssemblerStubs::PushBuiltinFrame(ExtendedAssembler *assembler, Register glue, FrameType type, Register op) +void AssemblerStubs::PushBuiltinFrame(ExtendedAssembler *assembler, Register glue, + FrameType type, Register op, Register next) { - __ SaveFpAndLr(); - __ Str(Register(FP), MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); + Register sp(SP); + __ PushFpAndLr(); + __ Mov(op, sp); + __ Str(op, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); __ Mov(op, Immediate(static_cast(type))); - __ Str(op, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + if (type == FrameType::BUILTIN_FRAME) { + // push stack args + __ Add(next, sp, Immediate(BuiltinFrame::GetStackArgsToFpDelta(false))); + // 16: type & next + __ Stp(next, op, MemoryOperand(sp, -16, AddrMode::PREINDEX)); + __ Add(Register(FP), sp, Immediate(16)); // 16: skip next and frame type + } else if (type == FrameType::BUILTIN_ENTRY_FRAME) { + // 16: type & next + __ Stp(next, op, MemoryOperand(sp, -16, AddrMode::PREINDEX)); + __ Add(Register(FP), sp, Immediate(16)); // 16: skip next and frame type + } else { + // 16: type & next + __ Stp(next, op, MemoryOperand(sp, -16, AddrMode::PREINDEX)); + } } -void AssemblerStubs::CallNativeInternal(ExtendedAssembler *assembler, Register glue, Register numArgs, - Register stackArgs, Register nativeCode) +void AssemblerStubs::CallNativeInternal(ExtendedAssembler *assembler, Register nativeCode) { - GlueToThread(assembler, glue, glue); - ConstructEcmaRuntimeCallInfo(assembler, glue, numArgs, stackArgs); - - // rsp is ecma callinfo base - __ Mov(Register(X0), Register(SP)); __ Blr(nativeCode); // resume rsp __ Mov(Register(SP), Register(FP)); @@ -1161,11 +1171,15 @@ void AssemblerStubs::ResumeRspAndDispatch(ExtendedAssembler *assembler) Register glueRegister = __ GlueRegister(); Register sp(FP); + Register rsp(SP); Register pc(X20); Register jumpSizeRegister(X25); + Register ret(X23); Register opcode(X6, W); + Register temp(X7); Register bcStub(X7); + Register fp(X8); int64_t fpOffset = static_cast(AsmInterpretedFrame::GetFpOffset(false)) - static_cast(AsmInterpretedFrame::GetSize(false)); @@ -1173,10 +1187,10 @@ void AssemblerStubs::ResumeRspAndDispatch(ExtendedAssembler *assembler) - static_cast(AsmInterpretedFrame::GetSize(false)); ASSERT(fpOffset < 0); ASSERT(spOffset < 0); - __ Ldur(Register(SP), MemoryOperand(sp, fpOffset)); // resume rsp Label newObjectDynRangeReturn; Label dispatch; + __ Ldur(fp, MemoryOperand(sp, fpOffset)); // store fp for temporary __ Cmp(jumpSizeRegister, Immediate(0)); __ B(Condition::EQ, &newObjectDynRangeReturn); __ Ldur(sp, MemoryOperand(sp, spOffset)); // update sp @@ -1185,46 +1199,93 @@ void AssemblerStubs::ResumeRspAndDispatch(ExtendedAssembler *assembler) __ Ldrb(opcode, MemoryOperand(pc, 0)); __ Bind(&dispatch); { - __ Add(bcStub, glueRegister, Operand(opcode, UXTW, 3)); // 3: bc * 8 + __ Mov(rsp, fp); // resume rsp + __ Add(bcStub, glueRegister, Operand(opcode, UXTW, SHIFT_OF_FRAMESLOT)); __ Ldr(bcStub, MemoryOperand(bcStub, JSThread::GlueData::GetBCStubEntriesOffset(false))); __ Br(bcStub); } auto jumpSize = kungfu::AssemblerModule::GetJumpSizeFromJSCallMode(JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV); + Label getHiddenThis; Label notUndefined; __ Bind(&newObjectDynRangeReturn); { - Register ret(X0); __ Cmp(ret, Immediate(JSTaggedValue::VALUE_UNDEFINED)); __ B(Condition::NE, ¬Undefined); auto index = AsmInterpretedFrame::ReverseIndex::THIS_OBJECT_REVERSE_INDEX; auto thisOffset = index * 8; // 8: byte size ASSERT(thisOffset < 0); - __ Ldur(ret, MemoryOperand(sp, thisOffset)); // update acc + __ Bind(&getHiddenThis); + __ Ldur(sp, MemoryOperand(sp, spOffset)); // update sp + __ Mov(rsp, fp); // resume rsp + __ Ldur(ret, MemoryOperand(rsp, thisOffset)); // update acc + __ Add(pc, pc, Immediate(jumpSize)); + __ Ldrb(opcode, MemoryOperand(pc, 0)); + __ Add(bcStub, glueRegister, Operand(opcode, UXTW, SHIFT_OF_FRAMESLOT)); + __ Ldr(bcStub, MemoryOperand(bcStub, JSThread::GlueData::GetBCStubEntriesOffset(false))); + __ Br(bcStub); + } + __ Bind(¬Undefined); + { + Label notEcmaObject; + __ Mov(temp, Immediate(JSTaggedValue::TAG_HEAPOBJECT_MARK)); + __ And(temp, temp, ret); + __ Cmp(temp, Immediate(0)); + __ B(Condition::NE, ¬EcmaObject); + // acc is heap object + __ Ldr(temp, MemoryOperand(ret, 0)); // hclass + __ Ldr(temp, MemoryOperand(temp, JSHClass::BIT_FIELD_OFFSET)); + __ And(temp.W(), temp.W(), LogicalImmediate::Create(0xFF, RegWSize)); + __ Cmp(temp.W(), Immediate(static_cast(JSType::ECMA_OBJECT_END))); + __ B(Condition::HI, ¬EcmaObject); + __ Cmp(temp.W(), Immediate(static_cast(JSType::ECMA_OBJECT_BEGIN))); + __ B(Condition::LO, ¬EcmaObject); + // acc is ecma object __ Ldur(sp, MemoryOperand(sp, spOffset)); // update sp __ Add(pc, pc, Immediate(jumpSize)); __ Ldrb(opcode, MemoryOperand(pc, 0)); __ B(&dispatch); - __ Bind(¬Undefined); - __ Mov(opcode, kungfu::BytecodeStubCSigns::ID_NewObjectDynRangeReturn); - __ B(&dispatch); + __ Bind(¬EcmaObject); + { + int64_t constructorOffset = static_cast(AsmInterpretedFrame::GetFunctionOffset(false)) + - static_cast(AsmInterpretedFrame::GetSize(false)); + ASSERT(constructorOffset < 0); + __ Ldur(temp, MemoryOperand(sp, constructorOffset)); // load constructor + __ Ldr(temp, MemoryOperand(temp, JSFunction::BIT_FIELD_OFFSET)); + __ Lsr(temp.W(), temp.W(), JSFunction::FunctionKindBits::START_BIT); + __ And(temp.W(), temp.W(), + LogicalImmediate::Create((1LU << JSFunction::FunctionKindBits::SIZE) - 1, RegWSize)); + __ Cmp(temp.W(), Immediate(static_cast(FunctionKind::CLASS_CONSTRUCTOR))); + __ B(Condition::LS, &getHiddenThis); // constructor is base + // exception branch + { + __ Mov(opcode, kungfu::BytecodeStubCSigns::ID_NewObjectDynRangeThrowException); + __ Ldur(sp, MemoryOperand(sp, spOffset)); // update sp + __ B(&dispatch); + } + } } } +// ResumeRspAndReturn(uintptr_t acc) +// GHC calling convention +// X19 - acc +// FP - prevSp +// X20 - sp void AssemblerStubs::ResumeRspAndReturn(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(ResumeRspAndReturn)); - Register sp(SP); - Register lr(X30); + Register rsp(SP); + Register currentSp(X20); [[maybe_unused]] TempRegister1Scope scope1(assembler); Register fpRegister = __ TempRegister1(); int64_t offset = static_cast(AsmInterpretedFrame::GetFpOffset(false)) - static_cast(AsmInterpretedFrame::GetSize(false)); ASSERT(offset < 0); - __ Ldur(fpRegister, MemoryOperand(Register(FP), offset)); - __ Mov(sp, fpRegister); + __ Ldur(fpRegister, MemoryOperand(currentSp, offset)); + __ Mov(rsp, fpRegister); // return { @@ -1257,11 +1318,14 @@ void AssemblerStubs::ResumeCaughtFrameAndDispatch(ExtendedAssembler *assembler) Label dispatch; __ Ldr(fp, MemoryOperand(glue, JSThread::GlueData::GetLastFpOffset(false))); __ Cmp(fp, Immediate(0)); - __ CMov(Register(SP), Register(SP), fp, Condition::EQ); + __ B(Condition::EQ, &dispatch); + // up frame + __ Mov(Register(SP), fp); + // fall through __ Bind(&dispatch); { __ Ldrb(opcode, MemoryOperand(pc, 0)); - __ Add(bcStub, glue, Operand(opcode, UXTW, 3)); // 3: bc * 8 + __ Add(bcStub, glue, Operand(opcode, UXTW, SHIFT_OF_FRAMESLOT)); __ Ldr(bcStub, MemoryOperand(bcStub, JSThread::GlueData::GetBCStubEntriesOffset(false))); __ Br(bcStub); } @@ -1270,15 +1334,21 @@ void AssemblerStubs::ResumeCaughtFrameAndDispatch(ExtendedAssembler *assembler) // ResumeUncaughtFrameAndReturn(uintptr_t glue) // GHC calling convention // X19 - glue +// FP - sp +// X20 - acc void AssemblerStubs::ResumeUncaughtFrameAndReturn(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(ResumeUncaughtFrameAndReturn)); Register glue(X19); Register fp(X5); + Register acc(X20); + Register cppRet(X0); __ Ldr(fp, MemoryOperand(glue, JSThread::GlueData::GetLastFpOffset(false))); __ Mov(Register(SP), fp); + // this method will return to Execute(cpp calling convention), and the return value should be put into X0. + __ Mov(cppRet, acc); __ RestoreFpAndLr(); __ Ret(); } @@ -1295,9 +1365,9 @@ void AssemblerStubs::CallGetter(ExtendedAssembler *assembler) __ BindAssemblerStub(RTSTUB_ID(CallGetter)); Label target; - PushAsmInterpEntryFrame(assembler, false); + PushAsmInterpBridgeFrame(assembler); __ Bl(&target); - PopAsmInterpEntryFrame(assembler, false); + PopAsmInterpBridgeFrame(assembler); __ Ret(); __ Bind(&target); { @@ -1310,9 +1380,9 @@ void AssemblerStubs::CallSetter(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(CallSetter)); Label target; - PushAsmInterpEntryFrame(assembler, false); + PushAsmInterpBridgeFrame(assembler); __ Bl(&target); - PopAsmInterpEntryFrame(assembler, false); + PopAsmInterpBridgeFrame(assembler); __ Ret(); __ Bind(&target); { @@ -1329,9 +1399,9 @@ void AssemblerStubs::GeneratorReEnterAsmInterp(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(GeneratorReEnterAsmInterp)); Label target; - PushAsmInterpEntryFrame(assembler, true); + PushAsmInterpEntryFrame(assembler); __ Bl(&target); - PopAsmInterpEntryFrame(assembler, true); + PopAsmInterpEntryFrame(assembler); __ Ret(); __ Bind(&target); { @@ -1362,13 +1432,14 @@ void AssemblerStubs::GeneratorReEnterAsmInterpDispatch(ExtendedAssembler *assemb __ Ldr(nRegsRegister, MemoryOperand(contextRegister, GeneratorContext::GENERATOR_NREGS_OFFSET)); __ Ldr(regsArrayRegister, MemoryOperand(contextRegister, GeneratorContext::GENERATOR_REGS_ARRAY_OFFSET)); __ Add(regsArrayRegister, regsArrayRegister, Immediate(TaggedArray::DATA_OFFSET)); - __ PushArgsWithArgv(nRegsRegister, regsArrayRegister, temp, &pushFrameState); + __ PushArgsWithArgv(nRegsRegister, regsArrayRegister, temp, fpRegister, &pushFrameState); __ Bind(&pushFrameState); - __ Mov(newSp, spRegister); + __ Mov(newSp, fpRegister); // push frame state PushGeneratorFrameState(assembler, prevSpRegister, fpRegister, callTarget, method, contextRegister, pc, temp); - + __ Align16(fpRegister); + __ Mov(Register(SP), fpRegister); // call bc stub CallBCStub(assembler, newSp, glue, callTarget, method, pc, temp); } @@ -1377,13 +1448,13 @@ void AssemblerStubs::PushCallThis(ExtendedAssembler *assembler, JSCallMode mode) { Register callFieldRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::CALL_FIELD); Register callTargetRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::CALL_TARGET); - Register sp(SP); + Register fpRegister = __ AvailableRegister1(); Label pushVregs; Label pushNewTarget; Label pushCallTarget; bool haveThis = kungfu::AssemblerModule::JSModeHaveThisArg(mode); - bool haveNewTarget = kungfu::AssemblerModule::JSModeHaveThisArg(mode); + bool haveNewTarget = kungfu::AssemblerModule::JSModeHaveNewTargetArg(mode); if (!haveThis) { __ Tst(callFieldRegister, LogicalImmediate::Create(CALL_TYPE_MASK, RegXSize)); __ B(Condition::EQ, &pushVregs); @@ -1393,10 +1464,10 @@ void AssemblerStubs::PushCallThis(ExtendedAssembler *assembler, JSCallMode mode) [[maybe_unused]] TempRegister1Scope scope1(assembler); Register tempRegister = __ TempRegister1(); __ Mov(tempRegister, Immediate(JSTaggedValue::VALUE_UNDEFINED)); - __ Str(tempRegister, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(tempRegister, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } else { Register thisRegister = GetThisRegsiter(assembler, mode); - __ Str(thisRegister, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(thisRegister, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } __ Bind(&pushNewTarget); { @@ -1405,15 +1476,16 @@ void AssemblerStubs::PushCallThis(ExtendedAssembler *assembler, JSCallMode mode) [[maybe_unused]] TempRegister1Scope scope1(assembler); Register newTarget = __ TempRegister1(); __ Mov(newTarget, Immediate(JSTaggedValue::VALUE_UNDEFINED)); - __ Str(newTarget, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(newTarget, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } else { - __ Str(callTargetRegister, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + Register newTargetRegister = GetNewTargetRegsiter(assembler, mode); + __ Str(newTargetRegister, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } } __ Bind(&pushCallTarget); { __ Tbz(callFieldRegister, JSMethod::HaveFuncBit::START_BIT, &pushVregs); - __ Str(callTargetRegister, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(callTargetRegister, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } __ Bind(&pushVregs); { @@ -1435,12 +1507,13 @@ void AssemblerStubs::PushVregs(ExtendedAssembler *assembler) // args register can be reused now. Register numVregsRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG0); GetNumVregsFromCallField(assembler, callFieldRegister, numVregsRegister); - PushUndefinedWithArgc(assembler, numVregsRegister, tempRegister, &pushFrameStateAndCall); + PushUndefinedWithArgc(assembler, numVregsRegister, + tempRegister, fpRegister, &pushFrameStateAndCall); // fall through __ Bind(&pushFrameStateAndCall); { Register newSpRegister = __ AvailableRegister2(); - __ Mov(newSpRegister, Register(SP)); + __ Mov(newSpRegister, fpRegister); StackOverflowCheck(assembler); @@ -1449,6 +1522,8 @@ void AssemblerStubs::PushVregs(ExtendedAssembler *assembler) PushFrameState(assembler, prevSpRegister, fpRegister, callTargetRegister, methodRegister, pcRegister, tempRegister); + __ Align16(fpRegister); + __ Mov(Register(SP), fpRegister); DispatchCall(assembler, pcRegister, newSpRegister); } } @@ -1476,7 +1551,7 @@ void AssemblerStubs::DispatchCall(ExtendedAssembler *assembler, Register pcRegis Register bcIndexRegister = __ AvailableRegister1(); Register tempRegister = __ AvailableRegister2(); __ Ldrb(bcIndexRegister.W(), MemoryOperand(pcRegister, 0)); - __ Add(tempRegister, glueRegister, Operand(bcIndexRegister.W(), UXTW, 3)); // 3: bc * 8 + __ Add(tempRegister, glueRegister, Operand(bcIndexRegister.W(), UXTW, SHIFT_OF_FRAMESLOT)); __ Ldr(tempRegister, MemoryOperand(tempRegister, JSThread::GlueData::GetBCStubEntriesOffset(false))); __ Br(tempRegister); } @@ -1484,15 +1559,15 @@ void AssemblerStubs::DispatchCall(ExtendedAssembler *assembler, Register pcRegis void AssemblerStubs::PushFrameState(ExtendedAssembler *assembler, Register prevSp, Register fp, Register callTarget, Register method, Register pc, Register op) { - Register sp(SP); __ Mov(op, Immediate(static_cast(FrameType::ASM_INTERPRETER_FRAME))); - __ Stp(prevSp, op, MemoryOperand(sp, -16, AddrMode::PREINDEX)); // -16: frame type & prevSp + __ Stp(prevSp, op, MemoryOperand(fp, -16, AddrMode::PREINDEX)); // -16: frame type & prevSp __ Ldr(pc, MemoryOperand(method, JSMethod::GetBytecodeArrayOffset(false))); - __ Stp(fp, pc, MemoryOperand(sp, -16, AddrMode::PREINDEX)); // -16: pc & fp + __ Mov(op, Register(SP)); + __ Stp(op, pc, MemoryOperand(fp, -16, AddrMode::PREINDEX)); // -16: pc & fp __ Ldr(op, MemoryOperand(callTarget, JSFunction::LEXICAL_ENV_OFFSET)); - __ Stp(op, Register(Zero), MemoryOperand(sp, -16, AddrMode::PREINDEX)); // -16: jumpSizeAfterCall & env + __ Stp(op, Register(Zero), MemoryOperand(fp, -16, AddrMode::PREINDEX)); // -16: jumpSizeAfterCall & env __ Mov(op, Immediate(JSTaggedValue::VALUE_HOLE)); - __ Stp(callTarget, op, MemoryOperand(sp, -16, AddrMode::PREINDEX)); // -16: acc & callTarget + __ Stp(callTarget, op, MemoryOperand(fp, -16, AddrMode::PREINDEX)); // -16: acc & callTarget } void AssemblerStubs::GetNumVregsFromCallField(ExtendedAssembler *assembler, Register callField, Register numVregs) @@ -1513,7 +1588,7 @@ void AssemblerStubs::GetDeclaredNumArgsFromCallField(ExtendedAssembler *assemble } void AssemblerStubs::PushUndefinedWithArgc(ExtendedAssembler *assembler, Register argc, Register temp, - panda::ecmascript::Label *next) + Register fp, panda::ecmascript::Label *next) { if (next != nullptr) { __ Cmp(argc.W(), Immediate(0)); @@ -1522,34 +1597,19 @@ void AssemblerStubs::PushUndefinedWithArgc(ExtendedAssembler *assembler, Registe Label loopBeginning; __ Mov(temp, Immediate(JSTaggedValue::VALUE_UNDEFINED)); __ Bind(&loopBeginning); - __ Str(temp, MemoryOperand(Register(SP), -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(temp, MemoryOperand(fp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); __ Sub(argc.W(), argc.W(), Immediate(1)); __ Cbnz(argc.W(), &loopBeginning); } -void AssemblerStubs::GlueToThread(ExtendedAssembler *assembler, Register glue, Register thread) -{ - __ Sub(thread, glue, Immediate(JSThread::GetGlueDataOffset())); -} - -void AssemblerStubs::ConstructEcmaRuntimeCallInfo(ExtendedAssembler *assembler, Register thread, Register numArgs, - Register stackArgs) -{ - Register sp(SP); - __ Sub(sp, sp, Immediate(sizeof(EcmaRuntimeCallInfo))); - __ Str(thread, MemoryOperand(sp, EcmaRuntimeCallInfo::GetThreadOffset())); - __ And(numArgs, numArgs, LogicalImmediate::Create(0x00000000FFFFFFFF, RegXSize)); - __ Str(numArgs, MemoryOperand(sp, EcmaRuntimeCallInfo::GetNumArgsOffset())); - __ Str(stackArgs, MemoryOperand(sp, EcmaRuntimeCallInfo::GetStackArgsOffset())); -} - void AssemblerStubs::StackOverflowCheck([[maybe_unused]] ExtendedAssembler *assembler) { } -void AssemblerStubs::PushAsmInterpEntryFrame(ExtendedAssembler *assembler, bool saveLeave) +void AssemblerStubs::PushAsmInterpEntryFrame(ExtendedAssembler *assembler) { Register glue = __ GlueRegister(); + Register fp(X29); Register sp(SP); if (!assembler->FromInterpreterHandler()) { @@ -1561,24 +1621,19 @@ void AssemblerStubs::PushAsmInterpEntryFrame(ExtendedAssembler *assembler, bool [[maybe_unused]] TempRegister2Scope scope2(assembler); Register frameTypeRegister = __ TempRegister2(); - if (saveLeave) { - __ Str(glue, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - // prev managed fp is leave frame or nullptr(the first frame) - __ Ldr(prevFrameRegister, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); - __ Mov(frameTypeRegister, Immediate(static_cast(FrameType::ASM_INTERPRETER_ENTRY_FRAME))); - __ SaveFpAndLr(); - } else { - __ Mov(prevFrameRegister, Register(FP)); - __ Mov(frameTypeRegister, Immediate(static_cast(FrameType::ASM_INTERPRETER_BRIDGE_FRAME))); - __ SaveLrAndFp(); - } + __ PushFpAndLr(); - // 2 : 2 means pair + // prev managed fp is leave frame or nullptr(the first frame) + __ Ldr(prevFrameRegister, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); + __ Mov(frameTypeRegister, Immediate(static_cast(FrameType::ASM_INTERPRETER_ENTRY_FRAME))); + // 2 : prevSp & frame type __ Stp(prevFrameRegister, frameTypeRegister, MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - __ Str(Register(Zero), MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // pc + // 2 : pc & glue + __ Stp(glue, Register(Zero), MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // pc + __ Add(fp, sp, Immediate(32)); // 32: skip frame type, prevSp, pc and glue } -void AssemblerStubs::PopAsmInterpEntryFrame(ExtendedAssembler *assembler, bool saveLeave) +void AssemblerStubs::PopAsmInterpEntryFrame(ExtendedAssembler *assembler) { Register sp(SP); @@ -1586,32 +1641,58 @@ void AssemblerStubs::PopAsmInterpEntryFrame(ExtendedAssembler *assembler, bool s Register prevFrameRegister = __ TempRegister1(); [[maybe_unused]] TempRegister2Scope scope2(assembler); Register glue = __ TempRegister2(); - // skip pc - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); - __ Ldr(prevFrameRegister, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - // skip frame type - __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); + // 2: glue & pc + __ Ldp(glue, Register(Zero), MemoryOperand(sp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + // 2: skip frame type & prev + __ Ldp(prevFrameRegister, Register(Zero), MemoryOperand(sp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - if (saveLeave) { - __ RestoreFpAndLr(); - __ Ldr(glue, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); - __ Str(prevFrameRegister, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); - } else { - __ RestoreLrAndFp(); + __ RestoreFpAndLr(); + __ Str(prevFrameRegister, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); + if (!assembler->FromInterpreterHandler()) { + __ CalleeRestore(); + } +} + +void AssemblerStubs::PushAsmInterpBridgeFrame(ExtendedAssembler *assembler) +{ + Register fp(X29); + Register sp(SP); + + [[maybe_unused]] TempRegister1Scope scope1(assembler); + Register frameTypeRegister = __ TempRegister1(); + + __ Mov(frameTypeRegister, Immediate(static_cast(FrameType::ASM_INTERPRETER_BRIDGE_FRAME))); + // 2 : return addr & frame type + __ Stp(frameTypeRegister, Register(X30), MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + // 2 : prevSp & pc + __ Stp(Register(Zero), Register(FP), MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Add(fp, sp, Immediate(24)); // 24: skip frame type, prevSp, pc + + if (!assembler->FromInterpreterHandler()) { + __ CalleeSave(); } +} + +void AssemblerStubs::PopAsmInterpBridgeFrame(ExtendedAssembler *assembler) +{ + Register sp(SP); + if (!assembler->FromInterpreterHandler()) { __ CalleeRestore(); } + // 2: prevSp & pc + __ Ldp(Register(Zero), Register(FP), MemoryOperand(sp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + // 2: return addr & frame type + __ Ldp(Register(Zero), Register(X30), MemoryOperand(sp, 2 * FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); } void AssemblerStubs::PushGeneratorFrameState(ExtendedAssembler *assembler, Register &prevSpRegister, Register &fpRegister, Register &callTargetRegister, Register &methodRegister, Register &contextRegister, Register &pcRegister, Register &operatorRegister) { - Register sp(SP); __ Mov(operatorRegister, Immediate(static_cast(FrameType::ASM_INTERPRETER_FRAME))); // 2 : frameType and prevSp - __ Stp(prevSpRegister, operatorRegister, MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Stp(prevSpRegister, operatorRegister, MemoryOperand(fpRegister, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); __ Ldr(pcRegister, MemoryOperand(methodRegister, JSMethod::GetBytecodeArrayOffset(false))); // offset need 8 align, GENERATOR_NREGS_OFFSET instead of GENERATOR_BC_OFFSET_OFFSET __ Ldr(operatorRegister, MemoryOperand(contextRegister, GeneratorContext::GENERATOR_NREGS_OFFSET)); @@ -1620,23 +1701,22 @@ void AssemblerStubs::PushGeneratorFrameState(ExtendedAssembler *assembler, Regis __ Add(pcRegister, operatorRegister, pcRegister); __ Add(pcRegister, pcRegister, Immediate(BytecodeInstruction::Size(BytecodeInstruction::Format::PREF_V8_V8))); // pc and fp - __ Stp(fpRegister, pcRegister, MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // 2 : 2 means pair + __ Mov(operatorRegister, Register(SP)); + // 2 : 2 means pair + __ Stp(operatorRegister, pcRegister, MemoryOperand(fpRegister, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // jumpSizeAfterCall - __ Str(Register(Zero), MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(Register(Zero), MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); __ Ldr(operatorRegister, MemoryOperand(contextRegister, GeneratorContext::GENERATOR_LEXICALENV_OFFSET)); // env - __ Str(operatorRegister, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(operatorRegister, MemoryOperand(fpRegister, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); __ Ldr(operatorRegister, MemoryOperand(contextRegister, GeneratorContext::GENERATOR_ACC_OFFSET)); // 2 : acc and callTarget - __ Stp(callTargetRegister, operatorRegister, MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Stp(callTargetRegister, operatorRegister, MemoryOperand(fpRegister, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); } void AssemblerStubs::CallBCStub(ExtendedAssembler *assembler, Register &newSp, Register &glue, Register &callTarget, Register &method, Register &pc, Register &temp) { - Register sp(SP); - // caller save newSp register to restore rsp after call - __ Str(newSp, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); // prepare call entry __ Mov(Register(X19), glue); // X19 - glue __ Mov(Register(FP), newSp); // FP - sp @@ -1649,7 +1729,7 @@ void AssemblerStubs::CallBCStub(ExtendedAssembler *assembler, Register &newSp, R // call the first bytecode handler __ Ldrb(temp.W(), MemoryOperand(pc, 0)); // 3 : 3 means *8 - __ Add(temp, glue, Operand(temp.W(), UXTW, 3)); + __ Add(temp, glue, Operand(temp.W(), UXTW, SHIFT_OF_FRAMESLOT)); __ Ldr(temp, MemoryOperand(temp, JSThread::GlueData::GetBCStubEntriesOffset(false))); __ Br(temp); } @@ -1657,134 +1737,219 @@ void AssemblerStubs::CallBCStub(ExtendedAssembler *assembler, Register &newSp, R void AssemblerStubs::CallNativeEntry(ExtendedAssembler *assembler) { Register glue(X0); - Register argc(X1); - Register argv(X2); - Register method(X4); - Register function(X3); + Register argv(X5); + Register method(X2); + Register function(X1); Register nativeCode(X7); Register temp(X9); Register sp(SP); - __ Str(function, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); - // 16: skip nativeCode & argc - __ Sub(sp, sp, Immediate(16)); - PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_ENTRY_FRAME, temp); + // 2: function & align + __ Stp(function, Register(Zero), MemoryOperand(sp, -2 * FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + // 2: skip argc & thread + __ Sub(sp, sp, Immediate(2 * FRAME_SLOT_SIZE)); + PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_ENTRY_FRAME, temp, argv); // get native pointer __ Ldr(nativeCode, MemoryOperand(method, JSMethod::GetBytecodeArrayOffset(false))); - CallNativeInternal(assembler, glue, argc, argv, nativeCode); + __ Mov(temp, argv); + __ Sub(Register(X0), temp, Immediate(2 * FRAME_SLOT_SIZE)); // 2: skip argc & thread + CallNativeInternal(assembler, nativeCode); - // 24: skip function - __ Add(sp, sp, Immediate(24)); + // 4: skip function + __ Add(sp, sp, Immediate(4 * FRAME_SLOT_SIZE)); __ Ret(); } -// Input: glue - %X0 -// argc - %X1 -// argv - %X2( are at the beginning of argv) -// callTarget - %X3 -// method - %X4 -// prevSp - %X29 -// fp - %10 -// callField - %X7 -void AssemblerStubs::PushArgsFastPath(ExtendedAssembler *assembler, - Register &glue, Register &argc, Register &argv, Register &callTarget, - Register &method, Register &prevSp, Register &fp, Register &callField) +void AssemblerStubs::PushArgsWithArgV(ExtendedAssembler *assembler, Register jsfunc, + Register actualNumArgs, Register argV, Label *pushCallThis) { - Label pushCallThis; - Label pushNewTarget; - Label pushCallTarget; - Label pushVregs; - Label pushFrameState; - Register sp(SP); + Register expectedNumArgs(X19); // output + [[maybe_unused]] TempRegister1Scope scope1(assembler); + Register tmp = __ TempRegister1(); + Label copyArguments; - Register argvOnlyHaveArgs(X11); - __ Add(argvOnlyHaveArgs, argv, Immediate(BuiltinFrame::RESERVED_CALL_ARGCOUNT * JSTaggedValue::TaggedTypeSize())); - Register tempRegister(X12); - __ PushArgsWithArgv(argc, argvOnlyHaveArgs, tempRegister, &pushCallThis); + // get expected num Args + __ Ldr(tmp, MemoryOperand(jsfunc, JSFunction::METHOD_OFFSET)); + __ Ldr(tmp, MemoryOperand(tmp, JSMethod::GetCallFieldOffset(false))); + __ Lsr(tmp, tmp, JSMethod::NumArgsBits::START_BIT); + __ And(tmp.W(), tmp.W(), + LogicalImmediate::Create(JSMethod::NumArgsBits::Mask() >> JSMethod::NumArgsBits::START_BIT, RegWSize)); + __ Mov(expectedNumArgs.W(), tmp.W()); + __ Subs(tmp.W(), tmp.W(), actualNumArgs.W()); + __ B(Condition::LS, ©Arguments); + { + [[maybe_unused]] TempRegister2Scope scope2(assembler); + Register undefinedValue = __ TempRegister2(); + PushUndefinedWithArgc(assembler, tmp, undefinedValue, Register(SP), nullptr); + } - __ Bind(&pushCallThis); - __ Tst(callField, LogicalImmediate::Create(CALL_TYPE_MASK, RegXSize)); - __ B(Condition::EQ, &pushVregs); - __ Tst(callField, LogicalImmediate::Create(JSMethod::HaveThisBit::Mask(), RegXSize)); - __ B(Condition::EQ, &pushNewTarget); - __ Ldr(tempRegister, MemoryOperand(argv, 16)); // 16: skip callTarget, newTarget - __ Str(tempRegister, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Bind(©Arguments); + { + __ Mov(tmp, expectedNumArgs); + // expectedNumArgs <= actualNumArgs + __ Cmp(tmp.W(), actualNumArgs.W()); + __ CMov(tmp, tmp.W(), actualNumArgs.W(), Condition::LO); + __ Cbz(tmp, pushCallThis); + CopyArgumentWithArgV(assembler, tmp, argV); + } +} - __ Bind(&pushNewTarget); - __ Tst(callField, LogicalImmediate::Create(JSMethod::HaveNewTargetBit::Mask(), RegXSize)); - __ B(Condition::EQ, &pushCallTarget); - __ Ldr(tempRegister, MemoryOperand(argv, 8)); // 8: skip callTarget - __ Str(tempRegister, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); +void AssemblerStubs::CopyArgumentWithArgV(ExtendedAssembler *assembler, Register argc, Register argV) +{ + [[maybe_unused]] TempRegister2Scope scope2(assembler); + Register argVEnd = __ AvailableRegister1(); + Register sp(SP); + Label copyArgLoop; + Register arg = __ TempRegister2(); + __ Sub(argVEnd.W(), argc, Immediate(1)); + __ Add(argVEnd, argV, Operand(argVEnd.W(), UXTW, SHIFT_OF_FRAMESLOT)); + __ Bind(©ArgLoop); + __ Ldr(arg, MemoryOperand(argVEnd, -FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + __ Subs(argc, argc, Immediate(1)); + __ Str(arg, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ B(Condition::NE, ©ArgLoop); +} - __ Bind(&pushCallTarget); - __ Tst(callField, LogicalImmediate::Create(JSMethod::HaveFuncBit::Mask(), RegXSize)); - __ B(Condition::EQ, &pushVregs); - __ Str(callTarget, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); +void AssemblerStubs::PushMandatoryJSArgs(ExtendedAssembler *assembler, Register jsfunc, + Register thisObj, Register newTarget) +{ + Register sp(SP); + __ Str(thisObj, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(newTarget, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Str(jsfunc, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); +} - __ Bind(&pushVregs); - { - Register numVregsRegister(X13); - GetNumVregsFromCallField(assembler, callField, numVregsRegister); - __ Cbz(numVregsRegister.W(), &pushFrameState); - PushUndefinedWithArgc(assembler, numVregsRegister, tempRegister, &pushFrameState); +void AssemblerStubs::PopJSFunctionArgs(ExtendedAssembler *assembler, Register expectedNumArgs, Register actualNumArgs) +{ + Register sp(SP); + Register fp(X6); + Label aligned; + const int64_t argoffsetSlot = static_cast(CommonArgIdx::FUNC) - 1; + if (expectedNumArgs != actualNumArgs) { + TempRegister1Scope scop1(assembler); + Register tmp = __ TempRegister1(); + __ Cmp(expectedNumArgs, actualNumArgs); + __ CMov(tmp, expectedNumArgs, actualNumArgs, Condition::HI); + __ Add(sp, sp, Operand(tmp, UXTW, SHIFT_OF_FRAMESLOT)); + } else { + __ Add(sp, sp, Operand(expectedNumArgs, UXTW, SHIFT_OF_FRAMESLOT)); } + __ Add(sp, sp, Immediate(argoffsetSlot * FRAME_SLOT_SIZE)); + __ Mov(fp, sp); + __ Tst(fp, LogicalImmediate::Create(0xf, RegXSize)); // 0xf: 0x1111 + __ B(Condition::EQ, &aligned); + __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); + __ Bind(&aligned); +} - __ Bind(&pushFrameState); - Register newSpRegister(X14); - __ Mov(newSpRegister, sp); +void AssemblerStubs::PushJSFunctionEntryFrame (ExtendedAssembler *assembler, Register prevFp) +{ + Register fp(X29); + Register sp(SP); + TempRegister2Scope temp2Scope(assembler); + __ SaveFpAndLr(); + Register frameType = __ TempRegister2(); + // construct frame + __ Mov(frameType, Immediate(static_cast(FrameType::OPTIMIZED_ENTRY_FRAME))); + // 2 : 2 means pairs + __ Stp(prevFp, frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); + __ CalleeSave(); +} - StackOverflowCheck(assembler); +void AssemblerStubs::PopJSFunctionEntryFrame(ExtendedAssembler *assembler, Register glue) +{ + Register fp(X29); + Register sp(SP); + Register prevFp(X1); + __ CalleeRestore(); - Register pcRegister(X11); - PushFrameState(assembler, prevSp, fp, callTarget, method, pcRegister, tempRegister); - CallBCStub(assembler, newSpRegister, glue, callTarget, method, pcRegister, tempRegister); -} - -// Input: glueRegister - %X0 -// declaredNumArgsRegister - %X9 -// argcRegister - %X1 -// argvRegister - %X2( are at the beginning of argv) -// callTargetRegister - %X3 -// methodRegister - %X4 -// prevSpRegister - %X29 -// callFieldRegister - %X7 -void AssemblerStubs::PushArgsSlowPath(ExtendedAssembler *assembler, Register &glueRegister, - Register &declaredNumArgsRegister, Register &argcRegister, Register &argvRegister, Register &callTargetRegister, - Register &methodRegister, Register &prevSpRegister, Register &callFieldRegister) -{ - Label jumpToFastPath; - Label haveExtra; - Label pushUndefined; - Register fpRegister(X10); - Register tempRegister(X12); + // pop prevLeaveFrameFp to restore thread->currentFrame_ + __ Ldr(prevFp, MemoryOperand(sp, FRAME_SLOT_SIZE, AddrMode::POSTINDEX)); + __ Str(prevFp, MemoryOperand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); - __ PushFpAndLr(); - __ Mov(fpRegister, Register(SP)); - __ Tst(callFieldRegister, LogicalImmediate::Create(JSMethod::HaveExtraBit::Mask(), RegXSize)); - __ B(Condition::NE, &haveExtra); - __ Mov(tempRegister.W(), declaredNumArgsRegister.W()); - __ Sub(declaredNumArgsRegister.W(), declaredNumArgsRegister.W(), argcRegister.W()); - __ Cmp(declaredNumArgsRegister.W(), Immediate(0)); - __ B(Condition::GT, &pushUndefined); - __ Mov(argcRegister.W(), tempRegister.W()); // actual = std::min(declare, actual) - __ B(&jumpToFastPath); - // fall through - __ Bind(&haveExtra); - { - Register tempArgcRegister(X13); - __ PushArgc(argcRegister, tempArgcRegister); - __ Sub(declaredNumArgsRegister.W(), declaredNumArgsRegister.W(), argcRegister.W()); - __ Cmp(declaredNumArgsRegister.W(), Immediate(0)); - __ B(Condition::LE, &jumpToFastPath); - // fall through - } - __ Bind(&pushUndefined); + // pop entry frame type + __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); + // restore return address + __ RestoreFpAndLr(); +} + +void AssemblerStubs::PushOptimizedJSFunctionFrame(ExtendedAssembler *assembler) +{ + Register sp(SP); + TempRegister2Scope temp2Scope(assembler); + Register frameType = __ TempRegister2(); + __ SaveFpAndLr(); + // construct frame + __ Mov(frameType, Immediate(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME))); + // 2 : 2 means pairs. X19 means calleesave and 16bytes align + __ Stp(Register(X19), frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); +} + +void AssemblerStubs::PopOptimizedJSFunctionFrame(ExtendedAssembler *assembler) +{ + TempRegister2Scope temp2Scope(assembler); + Register sp(SP); + Register frameType = __ TempRegister2(); + // 2 : 2 means pop call site sp and type + __ Ldp(Register(X19), frameType, MemoryOperand(sp, FRAME_SLOT_SIZE * 2, AddrMode::POSTINDEX)); + __ RestoreFpAndLr(); +} + +void AssemblerStubs::PushOptimizedFrame(ExtendedAssembler *assembler, Register callSiteSp) +{ + Register sp(SP); + TempRegister2Scope temp2Scope(assembler); + Register frameType = __ TempRegister2(); + __ SaveFpAndLr(); + // construct frame + __ Mov(frameType, Immediate(static_cast(FrameType::OPTIMIZED_FRAME))); + // 2 : 2 means pairs + __ Stp(callSiteSp, frameType, MemoryOperand(sp, -FRAME_SLOT_SIZE * 2, AddrMode::PREINDEX)); +} + +void AssemblerStubs::PopOptimizedFrame(ExtendedAssembler *assembler) +{ + Register sp(SP); + // 2 : 2 means pop call site sp and type + __ Add(sp, sp, Immediate(2 * FRAME_SLOT_SIZE)); + __ RestoreFpAndLr(); +} + +void AssemblerStubs::JSCallWithArgV(ExtendedAssembler *assembler) +{ + __ BindAssemblerStub(RTSTUB_ID(JSCallWithArgV)); + Register sp(SP); + Register glue(X0); + Register actualNumArgs(X1); + Register jsfunc(X2); + Register newTarget(X3); + Register thisObj(X4); + Register argV(X5); + Register env(X6); + Register callsiteSp = __ AvailableRegister2(); + Label pushCallThis; + + __ Mov(callsiteSp, sp); + PushOptimizedFrame(assembler, callsiteSp); + __ Cbz(actualNumArgs, &pushCallThis); { - PushUndefinedWithArgc(assembler, declaredNumArgsRegister, tempRegister, &jumpToFastPath); - // fall through + TempRegister1Scope scope1(assembler); + Register tmp = __ TempRegister1(); + __ Mov(tmp, actualNumArgs); + CopyArgumentWithArgV(assembler, tmp, argV); } - __ Bind(&jumpToFastPath); - PushArgsFastPath(assembler, glueRegister, argcRegister, argvRegister, callTargetRegister, methodRegister, - prevSpRegister, fpRegister, callFieldRegister); + __ Bind(&pushCallThis); + PushMandatoryJSArgs(assembler, jsfunc, thisObj, newTarget); + __ Add(actualNumArgs, actualNumArgs, Immediate(NUM_MANDATORY_JSFUNC_ARGS)); + __ Str(actualNumArgs, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + __ Ldr(env, MemoryOperand(jsfunc, JSFunction::LEXICAL_ENV_OFFSET)); + __ Str(env, MemoryOperand(sp, -FRAME_SLOT_SIZE, AddrMode::PREINDEX)); + + __ CallAssemblerStub(RTSTUB_ID(JSCall), false); + __ Add(sp, sp, Immediate(FRAME_SLOT_SIZE)); + __ Ldr(actualNumArgs, MemoryOperand(sp, 0)); + PopJSFunctionArgs(assembler, actualNumArgs, actualNumArgs); + PopOptimizedFrame(assembler); + __ Ret(); } } // panda::ecmascript::aarch64 \ No newline at end of file diff --git a/ecmascript/compiler/trampoline/aarch64/assembler_stubs.h b/ecmascript/compiler/trampoline/aarch64/assembler_stubs.h index 07a4126fb192cdf0eb1f66a8255edc68c0237de9..4c21adacfd38f47a0c97089b8c0ae39bb823b708 100644 --- a/ecmascript/compiler/trampoline/aarch64/assembler_stubs.h +++ b/ecmascript/compiler/trampoline/aarch64/assembler_stubs.h @@ -24,7 +24,10 @@ namespace panda::ecmascript::aarch64 { using Label = panda::ecmascript::Label; class AssemblerStubs { public: - static const int FRAME_SLOT_SIZE = 8; + static constexpr int FRAME_SLOT_SIZE = 8; + static constexpr int DOUBLE_SLOT_SIZE = 16; + static constexpr int SHIFT_OF_FRAMESLOT = 3; + enum BuiltinsLeaveFrameArgId : unsigned {CODE_ADDRESS = 0, ENV, ARGC, ARGV}; static inline int64_t GetStackArgOffSetToFp(unsigned argId) { // +--------------------------+ @@ -32,10 +35,12 @@ public: // +--------------------------+ --- // | argc | ^ // |--------------------------| arguments + // | env | | + // |--------------------------| | // | codeAddress | | // |--------------------------| | // | returnAddr | | - // |--------------------------| Fixed OptimizedLeaveFrame + // |--------------------------| Fixed OptimizedBuiltinLeaveFrame // | callsiteFp | | // |--------------------------| | // | frameType | v @@ -52,7 +57,7 @@ public: static void CallBuiltinTrampoline(ExtendedAssembler *assembler); - static void JSCallWithArgV(ExtendedAssembler *assembler); + static void JSProxyCallInternalWithArgV(ExtendedAssembler *assembler); static void JSCall(ExtendedAssembler *assembler); @@ -100,21 +105,24 @@ public: static void CallSetter(ExtendedAssembler *assembler); + static void JSCallWithArgV(ExtendedAssembler *assembler); + private: static void JSCallBody(ExtendedAssembler *assembler, Register jsfunc); static void PushCallThis(ExtendedAssembler *assembler, JSCallMode mode); static Register GetThisRegsiter(ExtendedAssembler *assembler, JSCallMode mode); + static Register GetNewTargetRegsiter(ExtendedAssembler *assembler, JSCallMode mode); static void PushVregs(ExtendedAssembler *assembler); static void DispatchCall(ExtendedAssembler *assembler, Register pc, Register newSp); - static void CallNativeInternal(ExtendedAssembler *assembler, Register glue, Register numArgs, Register stackArgs, - Register nativeCode); + static void CallNativeInternal(ExtendedAssembler *assembler, Register nativeCode); - static void PushBuiltinFrame(ExtendedAssembler *assembler, Register glue, FrameType type, Register op); + static void PushBuiltinFrame(ExtendedAssembler *assembler, Register glue, + FrameType type, Register op, Register next); static void PushFrameState(ExtendedAssembler *assembler, Register prevSp, Register fp, Register callTarget, Register method, Register pc, Register op); @@ -130,20 +138,19 @@ private: Register declaredNumArgs); static void PushUndefinedWithArgc(ExtendedAssembler *assembler, Register argc, Register temp, - panda::ecmascript::Label *next); + Register fp, panda::ecmascript::Label *next); static void SaveFpAndJumpSize(ExtendedAssembler *assembler, Immediate jumpSize); - static void GlueToThread(ExtendedAssembler *assembler, Register glue, Register thread); + static void StackOverflowCheck([[maybe_unused]] ExtendedAssembler *assembler); - static void ConstructEcmaRuntimeCallInfo(ExtendedAssembler *assembler, Register thread, Register numArgs, - Register stackArgs); + static void PushAsmInterpEntryFrame(ExtendedAssembler *assembler); - static void StackOverflowCheck([[maybe_unused]] ExtendedAssembler *assembler); + static void PopAsmInterpEntryFrame(ExtendedAssembler *assembler); - static void PushAsmInterpEntryFrame(ExtendedAssembler *assembler, bool saveLeave); + static void PushAsmInterpBridgeFrame(ExtendedAssembler *assembler); - static void PopAsmInterpEntryFrame(ExtendedAssembler *assembler, bool saveLeave); + static void PopAsmInterpBridgeFrame(ExtendedAssembler *assembler); static void PushGeneratorFrameState(ExtendedAssembler *assembler, Register &prevSpRegister, Register &fpRegister, Register &callTargetRegister, Register &methodRegister, Register &contextRegister, Register &pcRegister, @@ -155,15 +162,22 @@ private: static void CallNativeEntry(ExtendedAssembler *assembler); static void CallNativeWithArgv(ExtendedAssembler *assembler, bool callNew); - - static void PushArgsFastPath(ExtendedAssembler *assembler, - Register &glue, Register &argc, Register &argv, Register &callTarget, - Register &method, Register &prevSp, Register &fp, Register &callField); - - static void PushArgsSlowPath(ExtendedAssembler *assembler, Register &glueRegister, - Register &declaredNumArgsRegister, Register &argcRegister, Register &argvRegister, Register &callTargetRegister, - Register &methodRegister, Register &prevSpRegister, Register &callFieldRegister); static void OptimizedCallAsmInterpreter(ExtendedAssembler *assembler); + static void PushArgsWithArgV(ExtendedAssembler *assembler, Register jsfunc, + Register actualNumArgs, Register argV, Label *pushCallThis); + static void CopyArgumentWithArgV(ExtendedAssembler *assembler, Register argc, Register argV); + static void PushMandatoryJSArgs(ExtendedAssembler *assembler, Register jsfunc, + Register thisObj, Register newTarget); + static void PopJSFunctionArgs(ExtendedAssembler *assembler, Register expectedNumArgs, Register actualNumArgs); + static void PushJSFunctionEntryFrame (ExtendedAssembler *assembler, Register prevFp); + static void PopJSFunctionEntryFrame(ExtendedAssembler *assembler, Register glue); + static void PushOptimizedFrame(ExtendedAssembler *assembler, Register callSiteSp); + static void PopOptimizedFrame(ExtendedAssembler *assembler); + static void IncreaseStackForArguments(ExtendedAssembler *assembler, Register argC, Register fp); + static void PushOptimizedJSFunctionFrame(ExtendedAssembler *assembler); + static void PopOptimizedJSFunctionFrame(ExtendedAssembler *assembler); + static void PushLeaveFrame(ExtendedAssembler *assembler, Register glue, bool isBuiltin); + static void PopLeaveFrame(ExtendedAssembler *assembler, bool isBuiltin); }; } // namespace panda::ecmascript::x64 #endif // ECMASCRIPT_COMPILER_ASSEMBLER_MODULE_X64_H diff --git a/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.cpp b/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.cpp index 4681e17f193ae2d572f2c3c7dadbfb20bc25adbc..50c8d0ca6230dff323f44dad653719bb6e7e0af6 100644 --- a/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.cpp +++ b/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.cpp @@ -34,9 +34,9 @@ void AssemblerStubsX64::CallRuntime(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(CallRuntime)); __ Pushq(rbp); - __ Movq(rsp, rbp); __ Movq(rsp, Operand(rax, JSThread::GlueData::GetLeaveFrameOffset(false))); __ Pushq(static_cast(FrameType::LEAVE_FRAME)); + __ Leaq(Operand(rsp, 8), rbp); // 8: skip frame type __ Pushq(r10); __ Pushq(rdx); @@ -101,7 +101,7 @@ void AssemblerStubsX64::JSFunctionEntry(ExtendedAssembler *assembler) // 16 bytes align check __ Movl(expectedNumArgsReg, r14); __ Testb(1, r14); - __ Jne(&lAlign16Bytes); + __ Je(&lAlign16Bytes); __ Pushq(0); // push zero to align 16 bytes stack __ Bind(&lAlign16Bytes); @@ -137,13 +137,15 @@ void AssemblerStubsX64::JSFunctionEntry(ExtendedAssembler *assembler) __ Jne(&lCopyLoop); __ Pushq(r14); + __ Movq(Operand(argvReg, r14, Scale::Times8, 0), actualNumArgsReg); + __ Push(actualNumArgsReg); // env __ Movq(glueReg, rax); // mov glue to rax __ Callq(codeAddrReg); // then call jsFunction __ Leaq(Operand(r14, Scale::Times8, 0), actualNumArgsReg); // Note: fixed for 3 extra arguments __ Addq(actualNumArgsReg, rsp); - __ Addq(8, rsp); // 8: skip r14 + __ Addq(16, rsp); // 16: skip r14 and env __ Testb(1, r14); // stack 16bytes align check - __ Jne(&lPopFrame); + __ Je(&lPopFrame); __ Addq(8, rsp); // 8: align byte } @@ -159,13 +161,14 @@ void AssemblerStubsX64::JSFunctionEntry(ExtendedAssembler *assembler) } } -// uint64_t OptimizedCallOptimized(uintptr_t glue, uintptr_t codeAddr, uint32_t actualNumArgs, -// uint32_t expectedNumArgs, uintptr_t argv) +// uint64_t OptimizedCallOptimized(uintptr_t glue, uint32_t expectedNumArgs, +// uint32_t actualNumArgs, uintptr_t codeAddr, uintptr_t argv, uintptr_t lexEnv) // Input: %rdi - glue // %rsi - codeAddr // %rdx - actualNumArgs // %rcx - expectedNumArgs // %r8 - argv +// %r9 - lexEnv // sp[0 * 8] - argc // sp[1 * 8] - argv[0] @@ -185,6 +188,7 @@ void AssemblerStubsX64::OptimizedCallOptimized(ExtendedAssembler *assembler) Register actualNumArgsReg = rdx; Register codeAddrReg = rsi; Register argvReg = r8; + Register envReg = r9; Label lAlign16Bytes1; Label lCopyExtraAument1; @@ -194,6 +198,7 @@ void AssemblerStubsX64::OptimizedCallOptimized(ExtendedAssembler *assembler) __ Pushq(rbp); __ Movq(rsp, rbp); __ Pushq(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME)); + __ Pushq(envReg); // callee save __ Pushq(r14); __ Pushq(rbx); @@ -230,11 +235,13 @@ void AssemblerStubsX64::OptimizedCallOptimized(ExtendedAssembler *assembler) __ Addq(-1, rax); __ Jne(&lCopyLoop1); __ Pushq(actualNumArgsReg); // actual argc + __ Pushq(envReg); + __ Movq(glueReg, rax); // mov glue to rax __ Callq(codeAddrReg); // then call jsFunction __ Leaq(Operand(r14, Scale::Times8, 0), codeAddrReg); __ Addq(codeAddrReg, rsp); - __ Addq(8, rsp); // 8: skip actualNumArgsReg + __ Addq(DOUBLE_SLOT_SIZE, rsp); // skip actualNumArgsReg and envReg __ Testb(1, r14); // stack 16bytes align check __ Jne(&lPopFrame1); __ Addq(8, rsp); // 8: align byte @@ -243,7 +250,7 @@ void AssemblerStubsX64::OptimizedCallOptimized(ExtendedAssembler *assembler) __ Addq(8, rsp); // 8: skip rax __ Popq(rbx); __ Popq(r14); - __ Addq(8, rsp); // 8: skip frame type + __ Addq(DOUBLE_SLOT_SIZE, rsp); // skip frame type, env reg __ Pop(rbp); __ Ret(); } @@ -265,17 +272,19 @@ void AssemblerStubsX64::OptimizedCallAsmInterpreter(ExtendedAssembler *assembler // stack layout: // sp + N*8 argvN // ........ -// sp + 24: argv1 -// sp + 16: argv0 -// sp + 8: actualArgc -// sp: codeAddress +// sp + 24: argv0 +// sp + 16: actualArgc +// sp + 8: env +// sp: codeAddress // construct Native Leave Frame // +--------------------------+ // | argv0 | calltarget , newTarget, this, .... // +--------------------------+ --- // | argc | ^ -// |--------------------------| Fixed -// | codeAddress | OptimizedLeaveFrame +// |--------------------------| | +// | env | thread | | +// |--------------------------| Fixed +// | codeAddress | OptimizedBuiltinLeaveFrame // |--------------------------| | // | returnAddr | | // |--------------------------| | @@ -289,12 +298,11 @@ void AssemblerStubsX64::OptimizedCallAsmInterpreter(ExtendedAssembler *assembler // current sp - 8: type void AssemblerStubsX64::CallBuiltinTrampoline(ExtendedAssembler *assembler) { - __ BindAssemblerStub(RTSTUB_ID(CallBuiltinTrampoline)); Register glueReg = rax; __ Pushq(rbp); __ Movq(rsp, rbp); __ Movq(rbp, Operand(glueReg, JSThread::GlueData::GetLeaveFrameOffset(false))); // save to thread->leaveFrame_ - __ Pushq(static_cast(FrameType::LEAVE_FRAME)); + __ Pushq(static_cast(FrameType::BUILTIN_CALL_LEAVE_FRAME)); // callee save __ Pushq(r10); @@ -303,29 +311,12 @@ void AssemblerStubsX64::CallBuiltinTrampoline(ExtendedAssembler *assembler) __ Movq(rbp, rdx); __ Addq(16, rdx); // 16 : for rbp & return address // load native pointer address - __ Movq(Operand(rdx, 0), r10); // r10 -> argv[0] - __ Subq(8, rsp); // 8: align 16 bytes - __ Subq(sizeof(EcmaRuntimeCallInfo), rsp); - - // construct ecma_runtime_call_info - // get thread - Register threadReg = rax; - __ Subq(JSThread::GetGlueDataOffset(), threadReg); - __ Movq(threadReg, Operand(rsp, EcmaRuntimeCallInfo::GetThreadOffset())); // thread_ - // get numArgs - __ Movq(0, rax); - __ Movl(Operand(rdx, 8), rax); // 8: sp + 8 actualArgc - __ Subl(3, rax); // 3: size - __ Movq(rax, Operand(rsp, EcmaRuntimeCallInfo::GetNumArgsOffset())); // actualArgc - // get gpr data - __ Movq(rdx, rbx); - __ Addq(16, rbx); // 16: argv[0] - __ Movq(rbx, Operand(rsp, EcmaRuntimeCallInfo::GetStackArgsOffset())); // argv0 - - __ Movq(rsp, rdi); + __ Movq(Operand(rdx, 0), r10); + __ Movq(glueReg, Operand(rdx, FRAME_SLOT_SIZE)); // thread (instead of env) + // EcmaRuntimeCallInfo + __ Leaq(Operand(rdx, FRAME_SLOT_SIZE), rdi); __ Callq(r10); - __ Addq(8, rsp); // 8: sp + 8 align 16bytes - __ Addq(sizeof(EcmaRuntimeCallInfo), rsp); + __ Popq(rbx); __ Pop(r10); __ Addq(8, rsp); // 8: sp + 8 @@ -337,15 +328,15 @@ void AssemblerStubsX64::CallBuiltinTrampoline(ExtendedAssembler *assembler) __ Ret(); } -// uint64_t JSCallWithArgV(uintptr_t glue, uint32_t argc, JSTaggedType calltarget, uintptr_t argv[]) +// uint64_t JSProxyCallInternalWithArgV(uintptr_t glue, uint32_t argc, JSTaggedType calltarget, uintptr_t argv[]) // c++ calling convention call js function // Input: %rdi - glue // %rsi - argc // %rdx - calltarget // %rcx - argV (calltarget, newtarget, thisObj, ...) -void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) +void AssemblerStubsX64::JSProxyCallInternalWithArgV(ExtendedAssembler *assembler) { - __ BindAssemblerStub(RTSTUB_ID(JSCallWithArgV)); + __ BindAssemblerStub(RTSTUB_ID(JSProxyCallInternalWithArgV)); Label jsCall; Label lJSCallStart; Label lNotJSFunction; @@ -372,7 +363,7 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) { __ Movq(glueReg, rdi); glueReg = rdi; - __ Movq(Operand(rsp, 16), rax); // 16: get jsFunc + __ Movq(Operand(rsp, TRIPLE_SLOT_SIZE), rax); // get jsFunc } __ Bind(&lJSCallStart); Register jsFuncReg = rax; @@ -383,7 +374,7 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Jne(&lNonCallable); __ Cmp(0x0, jsFuncReg); // IsHole __ Je(&lNonCallable); - __ Movabs(JSTaggedValue::TAG_SPECIAL_VALUE, rdx); + __ Movabs(JSTaggedValue::TAG_SPECIAL, rdx); __ And(jsFuncReg, rdx); // IsSpecial __ Cmp(0x0, rdx); __ Jne(&lNonCallable); @@ -415,10 +406,12 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Movq(rsp, rbp); // set frame pointer __ Pushq(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME)); // set frame type __ Movq(MessageString::Message_NonCallable, rax); + __ Movabs(JSTaggedValue::TAG_INT, r10); + __ Orq(r10, rax); __ Pushq(rax); // message id __ Pushq(1); // argc - __ Pushq(EcmaRuntimeCallerId::RUNTIME_ID_ThrowTypeError); // runtime id - __ Movq(rcx, rax); // glue + __ Pushq(RTSTUB_ID(ThrowTypeError)); // runtime id + __ Movq(glueReg, rax); // glue __ Movq(kungfu::RuntimeStubCSigns::ID_CallRuntime, r10); __ Movq(Operand(rax, r10, Times8, JSThread::GlueData::GetRTStubEntriesOffset(false)), r10); __ Callq(r10); // call CallRuntime @@ -436,14 +429,14 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) Register argV = r9; { __ Mov(Operand(jsFuncReg, JSFunctionBase::METHOD_OFFSET), jsMethod); // get method - __ Movl(Operand(rsp, 8), argc); // 8: sp + 8 actual argc + __ Movl(Operand(rsp, DOUBLE_SLOT_SIZE), argc); // sp + 16 actual argc __ Mov(Operand(jsMethod, JSMethod::GetCallFieldOffset(false)), methodCallField); // get call field __ Btq(JSMethod::IsNativeBit::START_BIT, methodCallField); // is native __ Jb(&lCallNativeMethod); __ Btq(JSMethod::IsAotCodeBit::START_BIT, methodCallField); // is aot __ Jb(&lCallOptimziedMethod); __ Movq(rsp, argV); - __ Addq(16, argV); // 16: sp + 16 argv + __ Addq(TRIPLE_SLOT_SIZE, argV); // sp + 24 argv OptimizedCallAsmInterpreter(assembler); } @@ -457,9 +450,11 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Addl(NUM_MANDATORY_JSFUNC_ARGS, methodCallField); // add mandatory argument __ Mov(Operand(jsFuncReg, JSFunctionBase::CODE_ENTRY_OFFSET), codeAddrReg); // get codeAddress __ Movq(rsp, r8); + Register envReg = r9; + __ Movq(Operand(r8, DOUBLE_SLOT_SIZE), envReg); // get env argvReg = r8; - __ Addq(16, argvReg); // 16: sp + 8 argv - __ Cmpl(expectedNumArgsReg, argc); // expectedNumArgs <= actualNumArgs + __ Addq(TRIPLE_SLOT_SIZE, argvReg); // get argv + __ Cmpl(expectedNumArgsReg, rdx); // expectedNumArgs <= actualNumArgs __ Jg(&lDirectCallCodeEntry); __ CallAssemblerStub(RTSTUB_ID(OptimizedCallOptimized), true); } @@ -479,7 +474,7 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Push(nativePointer); // native code address __ Push(rax); // pc __ Movq(glueReg, rax); - __ CallAssemblerStub(RTSTUB_ID(CallBuiltinTrampoline), true); + CallBuiltinTrampoline(assembler); } __ Bind(&lJSBoundFunction); @@ -489,8 +484,10 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Pushq(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME)); __ Pushq(r10); // callee save __ Movq(rsp, rdx); - __ Addq(32, rdx); // 32: sp + 32 argv + __ Addq(QUINTUPLE_SLOT_SIZE, rdx); // sp + 40 argv __ Mov(Operand(rdx, 0), rax); // get origin argc + Register envReg = r9; + __ Mov(Operand(rdx, -FRAME_SLOT_SIZE), envReg); // get env __ Movq(rax, r10); // get bound target __ Mov(Operand(jsFuncReg, JSBoundFunction::BOUND_ARGUMENTS_OFFSET), rcx); @@ -500,7 +497,7 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) // 16 bytes align check __ Testb(1, r10); - __ Jne(&lAlign16Bytes2); + __ Je(&lAlign16Bytes2); __ PushAlignBytes(); // push zero to align 16 bytes stack } @@ -544,17 +541,20 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Mov(Operand(jsFuncReg, JSBoundFunction::BOUND_TARGET_OFFSET), rax); // callTarget __ Pushq(rax); __ Pushq(r10); // push actual arguments + Register envReg = r9; + __ Pushq(envReg); __ Movq(rdi, rax); __ Callq(&jsCall); // call JSCall __ Leaq(Operand(r10, Scale::Times8, 8), rcx); // 8: offset __ Addq(rcx, rsp); __ Testb(1, r10); // stack 16bytes align check - __ Jne(&lPopFrame2); + __ Je(&lPopFrame2); __ Addq(8, rsp); // 8: sp + 8 } __ Bind(&lPopFrame2); { + __ Addq(FRAME_SLOT_SIZE, rsp); // skip r9 __ Pop(r10); __ Addq(8, rsp); // 8: sp + 8 __ Pop(rbp); @@ -572,35 +572,39 @@ void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) __ Ret(); } -// uint64_t JSCall(uintptr_t glue, uint32_t argc, JSTaggedType calltarget, JSTaggedType new, JSTaggedType this, ...) +// uint64_t JSCall(uintptr_t glue, JSTaggedType env, uint32_t argc, JSTaggedType calltarget, JSTaggedType new, +// JSTaggedType this, ...) // webkit_jscc calling convention call js function() -// Input: %rax - glue -// stack layout: -// sp + N*8 argvN -// ........ -// sp + 24: argc -// sp + 16: this -// sp + 8: new -// sp: jsfunc -// +--------------------------+ -// | ... | -// +--------------------------+ -// | arg0 | -// +--------------------------+ -// | this | -// +--------------------------+ -// | new | -// +--------------------------+ --- -// | jsfunction | ^ -// |--------------------------| Fixed -// | argc | OptimizedFrame -// |--------------------------| | -// | returnAddr | | -// |--------------------------| | -// | callsiteFp | | -// |--------------------------| | -// | frameType | v -// +--------------------------+ --- +// Input: %rax - glue +// stack layout: sp + N*8 argvN +// ........ +// sp + 24: argc +// sp + 16: this +// sp + 8: new +// sp: jsfunc +// +--------------------------+ +// | ... | +// +--------------------------+ +// | arg0 | +// +--------------------------+ +// | this | +// +--------------------------+ +// | new | +// +--------------------------+ --- +// | jsfunction | ^ +// |--------------------------| Fixed +// | argc | OptimizedJSFunctionFrame +// |--------------------------| | +// | lexEnv | | +// |--------------------------| | +// | returnAddr | | +// |--------------------------| | +// | callsiteFp | | +// |--------------------------| | +// | frameType | | +// |--------------------------| | +// | lexEnv | v +// +--------------------------+ --- void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(JSCall)); @@ -625,7 +629,7 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) { __ Movq(glueReg, rdi); glueReg = rdi; - __ Movq(Operand(rsp, 16), rax); // 16: sp + 16 get jsFunc + __ Movq(Operand(rsp, TRIPLE_SLOT_SIZE), rax); // sp + 24 get jsFunc } __ Bind(&lJSCallStart); Register jsFuncReg = rax; @@ -636,7 +640,7 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Jne(&lNonCallable); __ Cmp(0x0, jsFuncReg); // IsHole __ Je(&lNonCallable); - __ Movabs(JSTaggedValue::TAG_SPECIAL_VALUE, rdx); + __ Movabs(JSTaggedValue::TAG_SPECIAL, rdx); __ And(jsFuncReg, rdx); // IsSpecial __ Cmp(0x0, rdx); __ Jne(&lNonCallable); @@ -668,10 +672,12 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Movq(rsp, rbp); // set frame pointer __ Pushq(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME)); // set frame type __ Movq(MessageString::Message_NonCallable, rax); + __ Movabs(JSTaggedValue::TAG_INT, r10); + __ Orq(r10, rax); __ Pushq(rax); // message id __ Pushq(1); // argc - __ Pushq(EcmaRuntimeCallerId::RUNTIME_ID_ThrowTypeError); // runtime id - __ Movq(rcx, rax); // glue + __ Pushq(RTSTUB_ID(ThrowTypeError)); // runtime id + __ Movq(glueReg, rax); // glue __ Movq(kungfu::RuntimeStubCSigns::ID_CallRuntime, r10); __ Movq(Operand(rax, r10, Times8, JSThread::GlueData::GetRTStubEntriesOffset(false)), r10); __ Callq(r10); // call CallRuntime @@ -689,14 +695,14 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) Register argV = r9; { __ Mov(Operand(jsFuncReg, JSFunctionBase::METHOD_OFFSET), jsMethod); // get method - __ Movl(Operand(rsp, 8), argc); // 8: sp + 8 actual argc + __ Movl(Operand(rsp, DOUBLE_SLOT_SIZE), argc); // sp + 16 actual argc __ Mov(Operand(jsMethod, JSMethod::GetCallFieldOffset(false)), methodCallField); // get call field __ Btq(JSMethod::IsNativeBit::START_BIT, methodCallField); // is native __ Jb(&lCallNativeMethod); __ Btq(JSMethod::IsAotCodeBit::START_BIT, methodCallField); // is aot __ Jb(&lCallOptimziedMethod); __ Movq(rsp, argV); - __ Addq(16, argV); // 16: sp + 16 argv + __ Addq(TRIPLE_SLOT_SIZE, argV); // sp + 24 argv OptimizedCallAsmInterpreter(assembler); } @@ -710,8 +716,10 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Addl(NUM_MANDATORY_JSFUNC_ARGS, methodCallField); // add mandatory argumentr __ Mov(Operand(jsFuncReg, JSFunctionBase::CODE_ENTRY_OFFSET), codeAddrReg); // get codeAddress __ Movq(rsp, r8); + Register envReg = r9; + __ Movq(Operand(r8, 16), envReg); // 16: get env Register argvReg = r8; - __ Addq(16, argvReg); // 16: sp + 16 argv + __ Addq(24, argvReg); // 24: sp + 24 argv __ Cmpl(expectedNumArgsReg, rdx); // expectedNumArgs <= actualNumArgs __ Jge(&lDirectCallCodeEntry); __ CallAssemblerStub(RTSTUB_ID(OptimizedCallOptimized), true); @@ -732,7 +740,7 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Push(nativePointer); // native code address __ Push(rax); // pc __ Movq(glueReg, rax); - __ CallAssemblerStub(RTSTUB_ID(CallBuiltinTrampoline), true); + CallBuiltinTrampoline(assembler); } __ Bind(&lJSBoundFunction); @@ -742,8 +750,10 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Pushq(static_cast(FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME)); __ Pushq(r10); // callee save __ Movq(rsp, rdx); - __ Addq(32, rdx); // 32: sp + 32 argv + __ Addq(QUINTUPLE_SLOT_SIZE, rdx); // sp + 40 argv __ Mov(Operand(rdx, 0), rax); // get origin argc + Register envReg = r9; + __ Mov(Operand(rdx, -FRAME_SLOT_SIZE), envReg); // get env __ Movq(rax, r10); // get bound target __ Mov(Operand(jsFuncReg, JSBoundFunction::BOUND_ARGUMENTS_OFFSET), rcx); @@ -753,7 +763,7 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) // 16 bytes align check __ Testb(1, r10); - __ Jne(&lAlign16Bytes2); + __ Je(&lAlign16Bytes2); __ PushAlignBytes(); // push zero to align 16 bytes stack } @@ -797,17 +807,20 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Mov(Operand(jsFuncReg, JSBoundFunction::BOUND_TARGET_OFFSET), rax); // callTarget __ Pushq(rax); __ Pushq(r10); // push actual arguments + Register envReg = r9; + __ Pushq(envReg); __ Movq(rdi, rax); __ Callq(&jsCall); // call JSCall __ Leaq(Operand(r10, Scale::Times8, 8), rcx); // 8: disp __ Addq(rcx, rsp); __ Testb(1, r10); // stack 16bytes align check - __ Jne(&lPopFrame2); + __ Je(&lPopFrame2); __ Addq(8, rsp); // 8: align byte } __ Bind(&lPopFrame2); { + __ Addq(8, rsp); // 8: sp + 8 __ Pop(r10); __ Addq(8, rsp); // 8: sp + 8 __ Pop(rbp); @@ -816,7 +829,7 @@ void AssemblerStubsX64::JSCall(ExtendedAssembler *assembler) __ Bind(&lJSProxy); __ Movq(jsFuncReg, rdx); // calltarget __ Movq(rsp, rcx); - __ Addq(8, rcx); // 8: sp + 8 skip returnAddr + __ Addq(DOUBLE_SLOT_SIZE, rcx); // sp + 16 skip returnAddr __ Mov(Operand(rcx, 0), rsi); // get origin argc __ Addq(8, rcx); // 8: sp + 8 argv __ Movq(kungfu::CommonStubCSigns::JsProxyCallInternal, r9); @@ -892,10 +905,12 @@ void AssemblerStubsX64::CallRuntimeWithArgv(ExtendedAssembler *assembler) } // Generate code for Entering asm interpreter -// c++ calling convention -// Input: %rdi - glue -// %rsi - argc -// %rdx - argv( are at the beginning of argv) +// Input: glue - %rdi +// callTarget - %rsi +// method - %rdx +// callField - %rcx +// argc - %r8 +// argv - %r9( are at the beginning of argv) void AssemblerStubsX64::AsmInterpreterEntry(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(AsmInterpreterEntry)); @@ -962,28 +977,24 @@ void AssemblerStubsX64::GeneratorReEnterAsmInterpDispatch(ExtendedAssembler *ass CallBCStub(assembler, newSpRegister, glueRegister, callTargetRegister, methodRegister, pcRegister); } -// Input: glueRegister - %rdi -// argcRegister - %rsi -// argvRegister - %rdx( are at the beginning of argv) -// prevSpRegister - %rbp +// Input: glue - %rdi +// callTarget - %rsi +// method - %rdx +// callField - %rcx +// argc - %r8 +// argv - %r9( are at the beginning of argv) +// prevSp - %rbp void AssemblerStubsX64::JSCallDispatch(ExtendedAssembler *assembler) { Label notJSFunction; Label callNativeEntry; Label callJSFunctionEntry; - Label pushArgsSlowPath; - Label callJSProxyEntry; Label notCallable; Register glueRegister = rdi; - Register argcRegister = rsi; - Register argvRegister = rdx; - Register prevSpRegister = rbp; - - Register callTargetRegister = r9; - Register methodRegister = rcx; + Register callTargetRegister = rsi; + Register argvRegister = r9; Register bitFieldRegister = r12; Register tempRegister = r11; // can not be used to store any variable - __ Movq(Operand(rdx, 0), callTargetRegister); __ Movq(Operand(callTargetRegister, 0), tempRegister); // hclass __ Movq(Operand(tempRegister, JSHClass::BIT_FIELD_OFFSET), bitFieldRegister); __ Cmpb(static_cast(JSType::JS_FUNCTION_BEGIN), bitFieldRegister); @@ -994,38 +1005,19 @@ void AssemblerStubsX64::JSCallDispatch(ExtendedAssembler *assembler) { __ Testq(static_cast(1ULL << JSHClass::CallableBit::START_BIT), bitFieldRegister); __ Jz(¬Callable); - __ Cmpb(static_cast(JSType::JS_PROXY), bitFieldRegister); - __ Je(&callJSProxyEntry); - // bound function branch, default native - __ Movq(Operand(callTargetRegister, JSFunctionBase::METHOD_OFFSET), methodRegister); // fall through } __ Bind(&callNativeEntry); CallNativeEntry(assembler); - __ Bind(&callJSProxyEntry); - { - __ Movq(Operand(callTargetRegister, JSProxy::METHOD_OFFSET), methodRegister); - __ Jmp(&callNativeEntry); - } __ Bind(&callJSFunctionEntry); { - __ Movq(Operand(callTargetRegister, JSFunctionBase::METHOD_OFFSET), methodRegister); - Register callFieldRegister = r14; - __ Movq(Operand(methodRegister, JSMethod::GetCallFieldOffset(false)), callFieldRegister); + Register callFieldRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::CALL_FIELD); __ Btq(JSMethod::IsNativeBit::START_BIT, callFieldRegister); __ Jb(&callNativeEntry); - Register declaredNumArgsRegister = r11; - GetDeclaredNumArgsFromCallField(assembler, callFieldRegister, declaredNumArgsRegister); - __ Cmpq(declaredNumArgsRegister, argcRegister); - __ Jne(&pushArgsSlowPath); - // fast path - Register fpRegister = r10; - __ Movq(rsp, fpRegister); - PushArgsFastPath(assembler, glueRegister, argcRegister, argvRegister, callTargetRegister, methodRegister, - prevSpRegister, fpRegister, callFieldRegister); - __ Bind(&pushArgsSlowPath); - PushArgsSlowPath(assembler, glueRegister, declaredNumArgsRegister, argcRegister, argvRegister, - callTargetRegister, methodRegister, prevSpRegister, callFieldRegister); + + __ Leaq(Operand(argvRegister, NUM_MANDATORY_JSFUNC_ARGS * JSTaggedValue::TaggedTypeSize()), + argvRegister); + JSCallCommonEntry(assembler, JSCallMode::CALL_ENTRY); } __ Bind(¬Callable); { @@ -1045,117 +1037,6 @@ void AssemblerStubsX64::JSCallDispatch(ExtendedAssembler *assembler) } } -// Input: glueRegister - %rdi -// argcRegister - %rsi -// argvRegister - %rdx( are at the beginning of argv) -// callTargetRegister - %r9 -// methodRegister - %rcx -// prevSpRegister - %rbp -// fpRegister - %r10 -// callFieldRegister - %r14 -void AssemblerStubsX64::PushArgsFastPath(ExtendedAssembler *assembler, Register glueRegister, - Register argcRegister, Register argvRegister, Register callTargetRegister, Register methodRegister, - Register prevSpRegister, Register fpRegister, Register callFieldRegister) -{ - Label pushCallThis; - Label pushNewTarget; - Label pushCallTarget; - Label pushVregs; - Label pushFrameState; - - __ Cmpq(0, argcRegister); - __ Jbe(&pushCallThis); // skip push args - Register argvOnlyHaveArgsRegister = r12; - __ Leaq(Operand(argvRegister, BuiltinFrame::RESERVED_CALL_ARGCOUNT * JSTaggedValue::TaggedTypeSize()), - argvOnlyHaveArgsRegister); - Register tempRegister = r11; - __ PushArgsWithArgv(argcRegister, argvOnlyHaveArgsRegister, tempRegister); // args - - __ Bind(&pushCallThis); - __ Testb(CALL_TYPE_MASK, callFieldRegister); - __ Jz(&pushVregs); - __ Testq(JSMethod::HaveThisBit::Mask(), callFieldRegister); - __ Jz(&pushNewTarget); - __ Movq(Operand(argvRegister, 16), tempRegister); // 16: skip callTarget, newTarget - __ Pushq(tempRegister); // this - - __ Bind(&pushNewTarget); - __ Testq(JSMethod::HaveNewTargetBit::Mask(), callFieldRegister); - __ Jz(&pushCallTarget); - __ Movq(Operand(argvRegister, 8), tempRegister); // 8: skip callTarget - __ Pushq(tempRegister); // newTarget - - __ Bind(&pushCallTarget); - __ Testq(JSMethod::HaveFuncBit::Mask(), callFieldRegister); - __ Jz(&pushVregs); - __ Pushq(callTargetRegister); // callTarget - - __ Bind(&pushVregs); - { - Register numVregsRegister = r11; - GetNumVregsFromCallField(assembler, callFieldRegister, numVregsRegister); - __ Cmpq(0, numVregsRegister); - __ Jz(&pushFrameState); - PushUndefinedWithArgc(assembler, numVregsRegister); - } - - __ Bind(&pushFrameState); - Register newSpRegister = r8; - __ Movq(rsp, newSpRegister); - - StackOverflowCheck(assembler); - - Register pcRegister = r12; // reuse r12 - PushFrameState(assembler, prevSpRegister, fpRegister, callTargetRegister, methodRegister, pcRegister, tempRegister); - CallBCStub(assembler, newSpRegister, glueRegister, callTargetRegister, methodRegister, pcRegister); -} - -// Input: glueRegister - %rdi -// declaredNumArgsRegister - %r11 -// argcRegister - %rsi -// argvRegister - %rdx( are at the beginning of argv) -// callTargetRegister - %r9 -// methodRegister - %rcx -// prevSpRegister - %rbp -// callFieldRegister - %r14 -void AssemblerStubsX64::PushArgsSlowPath(ExtendedAssembler *assembler, Register glueRegister, - Register declaredNumArgsRegister, Register argcRegister, Register argvRegister, Register callTargetRegister, - Register methodRegister, Register prevSpRegister, Register callFieldRegister) -{ - Label jumpToFastPath; - Label haveExtra; - Label pushUndefined; - Register fpRegister = r10; - Register tempRegister = r12; - __ Movq(rsp, fpRegister); - __ Testq(JSMethod::HaveExtraBit::Mask(), callFieldRegister); - __ Jnz(&haveExtra); - __ Movq(declaredNumArgsRegister, tempRegister); - __ Subq(argcRegister, declaredNumArgsRegister); - __ Cmpq(0, declaredNumArgsRegister); - __ Jg(&pushUndefined); - __ Movq(tempRegister, argcRegister); // std::min(declare, actual) - __ Jmp(&jumpToFastPath); - // fall through - __ Bind(&haveExtra); - { - Register tempArgcRegister = r15; - __ PushArgc(argcRegister, tempArgcRegister); - __ Subq(argcRegister, declaredNumArgsRegister); - __ Cmpq(0, declaredNumArgsRegister); - __ Jle(&jumpToFastPath); - // fall through - } - __ Bind(&pushUndefined); - { - PushUndefinedWithArgc(assembler, declaredNumArgsRegister); - // fall through - } - __ Bind(&jumpToFastPath); - PushArgsFastPath(assembler, glueRegister, argcRegister, argvRegister, callTargetRegister, methodRegister, - prevSpRegister, fpRegister, callFieldRegister); -} - void AssemblerStubsX64::PushFrameState(ExtendedAssembler *assembler, Register prevSpRegister, Register fpRegister, Register callTargetRegister, Register methodRegister, Register pcRegister, Register operatorRegister) { @@ -1202,10 +1083,10 @@ void AssemblerStubsX64::PushAsmInterpEntryFrame(ExtendedAssembler *assembler) __ Movq(Operand(rdi, JSThread::GlueData::GetLeaveFrameOffset(false)), fpRegister); // construct asm interpreter entry frame __ Pushq(rbp); - __ Movq(rsp, rbp); __ Pushq(static_cast(FrameType::ASM_INTERPRETER_ENTRY_FRAME)); __ Pushq(fpRegister); __ Pushq(0); // pc + __ Leaq(Operand(rsp, 24), rbp); // 24: skip frame type, prevSp and pc } void AssemblerStubsX64::PopAsmInterpEntryFrame(ExtendedAssembler *assembler) @@ -1228,8 +1109,8 @@ void AssemblerStubsX64::PushAsmInterpBridgeFrame(ExtendedAssembler *assembler) // construct asm interpreter bridge frame __ Pushq(static_cast(FrameType::ASM_INTERPRETER_BRIDGE_FRAME)); __ Pushq(rbp); - __ Leaq(Operand(rsp, 16), rbp); // 16: skip prevSp and frame type __ Pushq(0); // pc + __ Leaq(Operand(rsp, 24), rbp); // 24: skip pc, prevSp and frame type __ PushAlignBytes(); if (!assembler->FromInterpreterHandler()) { __ PushCppCalleeSaveRegisters(); @@ -1274,23 +1155,6 @@ void AssemblerStubsX64::CallBCStub(ExtendedAssembler *assembler, Register newSpR } } -void AssemblerStubsX64::GlueToThread(ExtendedAssembler *assembler, Register glueRegister, Register threadRegister) -{ - if (glueRegister != threadRegister) { - __ Movq(glueRegister, threadRegister); - } - __ Subq(JSThread::GetGlueDataOffset(), threadRegister); -} - -void AssemblerStubsX64::ConstructEcmaRuntimeCallInfo(ExtendedAssembler *assembler, Register threadRegister, - Register numArgsRegister, Register stackArgsRegister) -{ - __ Subq(sizeof(EcmaRuntimeCallInfo), rsp); - __ Movq(threadRegister, Operand(rsp, EcmaRuntimeCallInfo::GetThreadOffset())); - __ Movq(numArgsRegister, Operand(rsp, EcmaRuntimeCallInfo::GetNumArgsOffset())); - __ Movq(stackArgsRegister, Operand(rsp, EcmaRuntimeCallInfo::GetStackArgsOffset())); -} - void AssemblerStubsX64::GetDeclaredNumArgsFromCallField(ExtendedAssembler *assembler, Register callFieldRegister, Register declaredNumArgsRegister) { @@ -1527,6 +1391,7 @@ Register AssemblerStubsX64::GetThisRegsiter(ExtendedAssembler *assembler, JSCall case JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV: case JSCallMode::CALL_THIS_WITH_ARGV: return __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG2); + case JSCallMode::CALL_ENTRY: case JSCallMode::CALL_FROM_AOT: { Register argvRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); Register thisRegister = __ AvailableRegister2(); @@ -1539,6 +1404,26 @@ Register AssemblerStubsX64::GetThisRegsiter(ExtendedAssembler *assembler, JSCall return rInvalid; } +Register AssemblerStubsX64::GetNewTargetRegsiter(ExtendedAssembler *assembler, JSCallMode mode) +{ + switch (mode) { + case JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV: + case JSCallMode::CALL_THIS_WITH_ARGV: + return __ CallDispatcherArgument(kungfu::CallDispatchInputs::CALL_TARGET); + case JSCallMode::CALL_FROM_AOT: + case JSCallMode::CALL_ENTRY: { + Register argvRegister = __ CallDispatcherArgument(kungfu::CallDispatchInputs::ARG1); + Register newTargetRegister = __ AvailableRegister2(); + // 16: new Target offset + __ Movq(Operand(argvRegister, -16), newTargetRegister); + return newTargetRegister; + } + default: + UNREACHABLE(); + } + return rInvalid; +} + // Input: %r14 - callField // %rdi - argv void AssemblerStubsX64::PushCallThis(ExtendedAssembler *assembler, @@ -1551,7 +1436,7 @@ void AssemblerStubsX64::PushCallThis(ExtendedAssembler *assembler, Label pushNewTarget; Label pushCallTarget; bool haveThis = kungfu::AssemblerModule::JSModeHaveThisArg(mode); - bool haveNewTarget = kungfu::AssemblerModule::JSModeHaveThisArg(mode); + bool haveNewTarget = kungfu::AssemblerModule::JSModeHaveNewTargetArg(mode); if (!haveThis) { __ Testb(CALL_TYPE_MASK, callFieldRegister); __ Jz(&pushVregs); @@ -1574,7 +1459,8 @@ void AssemblerStubsX64::PushCallThis(ExtendedAssembler *assembler, if (!haveNewTarget) { __ Pushq(JSTaggedValue::Undefined().GetRawData()); } else { - __ Pushq(callTargetRegister); + Register newTargetRegister = GetNewTargetRegsiter(assembler, mode); + __ Pushq(newTargetRegister); } } // fall through @@ -1624,7 +1510,6 @@ void AssemblerStubsX64::PushVregs(ExtendedAssembler *assembler) StackOverflowCheck(assembler); - __ Movq(prevSpRegister, tempRegister); PushFrameState(assembler, prevSpRegister, fpRegister, callTargetRegister, methodRegister, pcRegister, tempRegister); // align 16 bytes @@ -1666,8 +1551,7 @@ void AssemblerStubsX64::DispatchCall(ExtendedAssembler *assembler, Register pcRe __ Movzbq(Operand(pcRegister, 0), bcIndexRegister); // callTargetRegister may rsi __ Movq(JSTaggedValue::Hole().GetRawData(), rsi); // acc: rsi - __ Movq(Operand(r13, bcIndexRegister, Times8, - JSThread::GlueData::GetBCStubEntriesOffset(false)), tempRegister); + __ Movq(Operand(r13, bcIndexRegister, Times8, JSThread::GlueData::GetBCStubEntriesOffset(false)), tempRegister); __ Jmp(tempRegister); } @@ -1701,7 +1585,7 @@ void AssemblerStubsX64::CallNativeWithArgv(ExtendedAssembler *assembler, bool ca Register stackArgs = r9; Register temporary = rax; Register opNumArgs = r10; - Label notAligned; + Label aligned; Label pushThis; PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_FRAME_WITH_ARGV); @@ -1722,56 +1606,72 @@ void AssemblerStubsX64::CallNativeWithArgv(ExtendedAssembler *assembler, bool ca __ Pushq(JSTaggedValue::Undefined().GetRawData()); } __ Pushq(func); + // 40: skip frame type, numArgs, func, newTarget and this + __ Leaq(Operand(rsp, numArgs, Times8, 40), rbp); __ Movq(rsp, stackArgs); + // push argc + __ Addl(NUM_MANDATORY_JSFUNC_ARGS, numArgs); + __ Pushq(numArgs); + // push thread + __ Pushq(glue); + // EcmaRuntimeCallInfo + __ Movq(rsp, rdi); + __ Testq(0xf, rsp); // 0xf: 0x1111 - __ Jnz(¬Aligned, Distance::Near); + __ Jz(&aligned, Distance::Near); __ PushAlignBytes(); - __ Bind(¬Aligned); - CallNativeInternal(assembler, glue, numArgs, stackArgs, nativeCode); + __ Bind(&aligned); + CallNativeInternal(assembler, nativeCode); __ Ret(); } void AssemblerStubsX64::CallNativeEntry(ExtendedAssembler *assembler) { Register glue = rdi; - Register argc = rsi; - Register argv = rdx; - Register method = rcx; - Register function = r9; + Register argv = r9; + Register method = rdx; + Register function = rsi; Register nativeCode = r10; + __ PushAlignBytes(); __ Push(function); - // 24: skip nativeCode & argc & returnAddr + // 24: skip thread & argc & returnAddr __ Subq(24, rsp); PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_ENTRY_FRAME); __ Movq(Operand(method, JSMethod::GetBytecodeArrayOffset(false)), nativeCode); // get native pointer - CallNativeInternal(assembler, glue, argc, argv, nativeCode); + __ Movq(argv, r11); + // 16: skip numArgs & thread + __ Subq(16, r11); + // EcmaRuntimeCallInfo + __ Movq(r11, rdi); + + CallNativeInternal(assembler, nativeCode); - // 32: skip function - __ Addq(32, rsp); + // 40: skip function + __ Addq(40, rsp); __ Ret(); } -// uint64_t PushCallArgsAndDispatchNative(uintptr_t glue, uintptr_t codeAddress, uint32_t argc, ...) +// uint64_t PushCallArgsAndDispatchNative(uintptr_t codeAddress, uintptr_t glue, uint32_t argc, ...) // webkit_jscc calling convention call runtime_id's runtion function(c-abi) -// Input: %rax - glue +// Input: %rax - codeAddress // stack layout: sp + N*8 argvN // ........ // sp + 24: argv1 // sp + 16: argv0 -// sp + 8: actualArgc -// sp: codeAddress +// sp + 8: actualArgc +// sp: thread // construct Native Leave Frame // +--------------------------+ // | argv0 | calltarget , newTarget, this, .... // +--------------------------+ --- // | argc | ^ -// |--------------------------| Fixed -// | codeAddress | BuiltinFrame // |--------------------------| | -// | returnAddr | | +// | thread | | +// |--------------------------| Fixed +// | returnAddr | BuiltinFrame // |--------------------------| | // | callsiteFp | | // |--------------------------| | @@ -1780,19 +1680,14 @@ void AssemblerStubsX64::CallNativeEntry(ExtendedAssembler *assembler) void AssemblerStubsX64::PushCallArgsAndDispatchNative(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(PushCallArgsAndDispatchNative)); - Register glue = rax; - Register numArgs = rdx; - Register stackArgs = rcx; - Register nativeCode = r10; + Register nativeCode = rax; + Register glue = rdi; + __ Movq(Operand(rsp, 8), glue); // 8: glue PushBuiltinFrame(assembler, glue, FrameType::BUILTIN_FRAME); - __ Movq(Operand(rbp, BuiltinFrame::GetNativeCodeToFpDelta(false)), nativeCode); - // 8: offset of numArgs - __ Movq(Operand(rbp, BuiltinFrame::GetNumArgsToFpDelta(false)), numArgs); - // 8: offset of &argv[0] - __ Leaq(Operand(rbp, BuiltinFrame::GetStackArgsToFpDelta(false)), stackArgs); - - CallNativeInternal(assembler, glue, numArgs, stackArgs, nativeCode); + __ Leaq(Operand(rbp, 16), rdi); // 16: skip argc & thread + __ PushAlignBytes(); + CallNativeInternal(assembler, nativeCode); __ Ret(); } @@ -1800,19 +1695,15 @@ void AssemblerStubsX64::PushBuiltinFrame(ExtendedAssembler *assembler, Register glue, FrameType type) { __ Pushq(rbp); - __ Movq(rsp, rbp); - __ Movq(rbp, Operand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); + __ Movq(rsp, Operand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); __ Pushq(static_cast(type)); + if (type != FrameType::BUILTIN_FRAME_WITH_ARGV) { + __ Leaq(Operand(rsp, 8), rbp); // 8: skip frame type + } } -void AssemblerStubsX64::CallNativeInternal(ExtendedAssembler *assembler, - Register glue, Register numArgs, Register stackArgs, Register nativeCode) +void AssemblerStubsX64::CallNativeInternal(ExtendedAssembler *assembler, Register nativeCode) { - GlueToThread(assembler, glue, glue); - ConstructEcmaRuntimeCallInfo(assembler, glue, numArgs, stackArgs); - - // rsp is ecma callinfo base - __ Movq(rsp, rdi); __ Callq(nativeCode); // resume rsp __ Movq(rbp, rsp); @@ -1836,47 +1727,93 @@ void AssemblerStubsX64::ResumeRspAndDispatch(ExtendedAssembler *assembler) Register glueRegister = __ GlueRegister(); Register spRegister = rbp; Register pcRegister = r12; + Register ret = rsi; Register jumpSizeRegister = r8; Register frameStateBaseRegister = r11; __ Movq(spRegister, frameStateBaseRegister); __ Subq(AsmInterpretedFrame::GetSize(false), frameStateBaseRegister); - __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetFpOffset(false)), rsp); // resume rsp + Label dispatch; Label newObjectDynRangeReturn; __ Cmpq(0, jumpSizeRegister); __ Je(&newObjectDynRangeReturn); __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetBaseOffset(false)), spRegister); // update sp __ Addq(jumpSizeRegister, pcRegister); // newPc + Register temp = rax; Register opcodeRegister = rax; __ Movzbq(Operand(pcRegister, 0), opcodeRegister); - Register bcStubRegister = r11; - __ Movq(Operand(glueRegister, opcodeRegister, Times8, JSThread::GlueData::GetBCStubEntriesOffset(false)), - bcStubRegister); - __ Jmp(bcStubRegister); + + __ Bind(&dispatch); + { + __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetFpOffset(false)), rsp); // resume rsp + Register bcStubRegister = r11; + __ Movq(Operand(glueRegister, opcodeRegister, Times8, JSThread::GlueData::GetBCStubEntriesOffset(false)), + bcStubRegister); + __ Jmp(bcStubRegister); + } auto jumpSize = kungfu::AssemblerModule::GetJumpSizeFromJSCallMode( JSCallMode::CALL_CONSTRUCTOR_WITH_ARGV); + Label getHiddenThis; Label notUndefined; __ Bind(&newObjectDynRangeReturn); - __ Cmpq(JSTaggedValue::Undefined().GetRawData(), rsi); + __ Cmpq(JSTaggedValue::Undefined().GetRawData(), ret); __ Jne(¬Undefined); auto index = AsmInterpretedFrame::ReverseIndex::THIS_OBJECT_REVERSE_INDEX; - __ Movq(Operand(rsp, index * 8), rsi); // 8: byte size, update acc + __ Bind(&getHiddenThis); __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetBaseOffset(false)), spRegister); // update sp __ Addq(jumpSize, pcRegister); // newPc __ Movzbq(Operand(pcRegister, 0), opcodeRegister); - __ Movq(Operand(glueRegister, opcodeRegister, Times8, JSThread::GlueData::GetBCStubEntriesOffset(false)), - bcStubRegister); - __ Jmp(bcStubRegister); + { + __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetFpOffset(false)), rsp); // resume rsp + __ Movq(Operand(rsp, index * 8), ret); // 8: byte size, update acc + Register bcStubRegister = r11; + __ Movq(Operand(glueRegister, opcodeRegister, Times8, JSThread::GlueData::GetBCStubEntriesOffset(false)), + bcStubRegister); + __ Jmp(bcStubRegister); + } __ Bind(¬Undefined); - __ Movq(kungfu::BytecodeStubCSigns::ID_NewObjectDynRangeReturn, opcodeRegister); - __ Movq(Operand(glueRegister, opcodeRegister, Times8, JSThread::GlueData::GetBCStubEntriesOffset(false)), - bcStubRegister); - __ Jmp(bcStubRegister); + { + Label notEcmaObject; + __ Movabs(JSTaggedValue::TAG_HEAPOBJECT_MARK, temp); + __ And(ret, temp); + __ Cmpq(0, temp); + __ Jne(¬EcmaObject); + // acc is heap object + __ Movq(Operand(ret, 0), temp); // hclass + __ Movl(Operand(temp, JSHClass::BIT_FIELD_OFFSET), temp); + __ Cmpb(static_cast(JSType::ECMA_OBJECT_END), temp); + __ Ja(¬EcmaObject); + __ Cmpb(static_cast(JSType::ECMA_OBJECT_BEGIN), temp); + __ Jb(¬EcmaObject); + // acc is ecma object + __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetBaseOffset(false)), spRegister); // update sp + __ Addq(jumpSize, pcRegister); // newPc + __ Movzbq(Operand(pcRegister, 0), opcodeRegister); + __ Jmp(&dispatch); + + __ Bind(¬EcmaObject); + { + // load constructor + __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetFunctionOffset(false)), temp); + __ Movl(Operand(temp, JSFunction::BIT_FIELD_OFFSET), temp); + __ Shr(JSFunction::FunctionKindBits::START_BIT, temp); + __ Andl((1LU << JSFunction::FunctionKindBits::SIZE) - 1, temp); + __ Cmpl(static_cast(FunctionKind::CLASS_CONSTRUCTOR), temp); + __ Jbe(&getHiddenThis); // constructor is base + // fall through + } + // exception branch + { + __ Movq(Operand(frameStateBaseRegister, AsmInterpretedFrame::GetBaseOffset(false)), spRegister); + __ Movq(kungfu::BytecodeStubCSigns::ID_NewObjectDynRangeThrowException, opcodeRegister); + __ Jmp(&dispatch); + } + } } // c++ calling convention @@ -1913,13 +1850,16 @@ void AssemblerStubsX64::CallSetter(ExtendedAssembler *assembler) // ResumeRspAndReturn(uintptr_t acc) // GHC calling convention -// %r13 - glue +// %r13 - acc +// %rbp - prevSp +// %r12 - sp void AssemblerStubsX64::ResumeRspAndReturn([[maybe_unused]] ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(ResumeRspAndReturn)); + Register currentSp = r12; Register fpRegister = r10; intptr_t offset = AsmInterpretedFrame::GetFpOffset(false) - AsmInterpretedFrame::GetSize(false); - __ Movq(Operand(rbp, static_cast(offset)), fpRegister); + __ Movq(Operand(currentSp, static_cast(offset)), fpRegister); __ Movq(fpRegister, rsp); // return { @@ -1964,10 +1904,14 @@ void AssemblerStubsX64::ResumeCaughtFrameAndDispatch(ExtendedAssembler *assemble // ResumeUncaughtFrameAndReturn(uintptr_t glue) // GHC calling convention // %r13 - glue +// %rbp - sp +// %r12 - acc void AssemblerStubsX64::ResumeUncaughtFrameAndReturn(ExtendedAssembler *assembler) { __ BindAssemblerStub(RTSTUB_ID(ResumeUncaughtFrameAndReturn)); Register glueRegister = __ GlueRegister(); + Register acc(r12); + Register cppRet(rax); Label ret; Register fpRegister = r11; @@ -1976,6 +1920,8 @@ void AssemblerStubsX64::ResumeUncaughtFrameAndReturn(ExtendedAssembler *assemble __ Jz(&ret); __ Movq(fpRegister, rsp); // resume rsp __ Bind(&ret); + // this method will return to Execute(cpp calling convention), and the return value should be put into rax. + __ Movq(acc, cppRet); __ Ret(); } @@ -1988,6 +1934,17 @@ void AssemblerStubsX64::PushUndefinedWithArgc(ExtendedAssembler *assembler, Regi __ Ja(&loopBeginning); } +void AssemblerStubsX64::CopyArgumentWithArgV(ExtendedAssembler *assembler, Register argc, Register argV) +{ + Label loopBeginning; + Register arg = __ AvailableRegister1(); + __ Bind(&loopBeginning); + __ Movq(Operand(argV, argc, Scale::Times8, -8), arg); // -8: stack index + __ Pushq(arg); + __ Subq(1, argc); + __ Ja(&loopBeginning); +} + void AssemblerStubsX64::HasPendingException([[maybe_unused]] ExtendedAssembler *assembler, [[maybe_unused]] Register threadRegister) { @@ -1996,5 +1953,140 @@ void AssemblerStubsX64::HasPendingException([[maybe_unused]] ExtendedAssembler * void AssemblerStubsX64::StackOverflowCheck([[maybe_unused]] ExtendedAssembler *assembler) { } + +void AssemblerStubsX64::PushMandatoryJSArgs(ExtendedAssembler *assembler, Register jsfunc, + Register thisObj, Register newTarget) +{ + __ Pushq(thisObj); + __ Pushq(newTarget); + __ Pushq(jsfunc); +} + +// output expectedNumArgs (r14) +void AssemblerStubsX64::PushArgsWithArgV(ExtendedAssembler *assembler, Register jsfunc, + Register actualNumArgs, Register argV, Label *pushCallThis) +{ + Register expectedNumArgs(r14); // output + Register tmp(rax); + Label align16Bytes; + Label copyArguments; + // get expected num Args + __ Movq(Operand(jsfunc, JSFunctionBase::METHOD_OFFSET), tmp); + __ Movq(Operand(tmp, JSMethod::GetCallFieldOffset(false)), tmp); + __ Shr(JSMethod::NumArgsBits::START_BIT, tmp); + __ Andl(((1LU << JSMethod::NumArgsBits::SIZE) - 1), tmp); + + __ Mov(tmp, expectedNumArgs); + __ Testb(1, expectedNumArgs); + __ Jne(&align16Bytes); + __ PushAlignBytes(); + + __ Bind(&align16Bytes); + { + __ Cmpq(actualNumArgs, expectedNumArgs); + __ Jbe(©Arguments); + __ Subq(actualNumArgs, tmp); + PushUndefinedWithArgc(assembler, tmp); + } + __ Bind(©Arguments); + { + __ Cmpq(actualNumArgs, expectedNumArgs); + __ Movq(actualNumArgs, tmp); // rax -> actualNumArgsReg + __ CMovbe(expectedNumArgs, tmp); + __ Cmpq(0, tmp); + __ Je(pushCallThis); + CopyArgumentWithArgV(assembler, tmp, argV); + } +} + +void AssemblerStubsX64::PopJSFunctionArgs(ExtendedAssembler *assembler, Register expectedNumArgs) +{ + __ Addq(1, expectedNumArgs); + __ Andq(~1, expectedNumArgs); + __ Leaq(Operand(expectedNumArgs, Scale::Times8, 0), expectedNumArgs); + __ Addq(expectedNumArgs, rsp); + __ Addq(8, rsp); // 8: skip expectedNumArgs +} + +void AssemblerStubsX64::PushJSFunctionEntryFrame (ExtendedAssembler *assembler, Register prevFp) +{ + __ PushCppCalleeSaveRegisters(); + __ Pushq(rdi); + + // construct optimized entry frame + __ Pushq(rbp); + __ Movq(rsp, rbp); + __ Pushq(static_cast(FrameType::OPTIMIZED_ENTRY_FRAME)); + __ Pushq(prevFp); +} + +void AssemblerStubsX64::PopJSFunctionEntryFrame(ExtendedAssembler *assembler, Register glue) +{ + Register prevFp(rsi); + __ Popq(prevFp); + __ Addq(8, rsp); // 8: frame type + __ Popq(rbp); + __ Popq(glue); // caller restore + __ PopCppCalleeSaveRegisters(); // callee restore + __ Movq(prevFp, Operand(glue, JSThread::GlueData::GetLeaveFrameOffset(false))); +} + +void AssemblerStubsX64::PushOptimizedFrame(ExtendedAssembler *assembler, Register callSiteSp) +{ + __ Pushq(rbp); + __ Movq(rsp, rbp); + // construct frame + __ Pushq(static_cast(FrameType::OPTIMIZED_FRAME)); + __ Pushq(callSiteSp); +} + +void AssemblerStubsX64::PopOptimizedFrame(ExtendedAssembler *assembler) +{ + Register sp(rsp); + // 16 : 16 means pop call site sp and type + __ Addq(Immediate(16), sp); + __ Popq(rbp); +} + +void AssemblerStubsX64::JSCallWithArgV(ExtendedAssembler *assembler) +{ + __ BindAssemblerStub(RTSTUB_ID(JSCallWithArgV)); + Register sp(rsp); + Register glue(rdi); + Register actualNumArgs(rsi); + Register jsfunc(rdx); + Register newTarget(rcx); + Register thisObj(r8); + Register argV(r9); + Register callsiteSp = __ AvailableRegister2(); + Label align16Bytes; + Label pushCallThis; + + __ Movq(sp, callsiteSp); + __ Addq(Immediate(8), callsiteSp); // 8 : 8 means skip pc to get last callsitesp + PushOptimizedFrame(assembler, callsiteSp); + __ Testb(1, actualNumArgs); + __ Jne(&align16Bytes); + __ PushAlignBytes(); + __ Bind(&align16Bytes); + __ Cmp(Immediate(0), actualNumArgs); + __ Jz(&pushCallThis); + __ Mov(actualNumArgs, rax); + CopyArgumentWithArgV(assembler, rax, argV); + __ Bind(&pushCallThis); + PushMandatoryJSArgs(assembler, jsfunc, thisObj, newTarget); + __ Addq(Immediate(NUM_MANDATORY_JSFUNC_ARGS), actualNumArgs); + __ Pushq(actualNumArgs); + __ Movq(Operand(jsfunc, JSFunction::LEXICAL_ENV_OFFSET), rax); + __ Pushq(rax); + __ Movq(glue, rax); + __ CallAssemblerStub(RTSTUB_ID(JSCall), false); + __ Addq(FRAME_SLOT_SIZE, rsp); + __ Mov(Operand(sp, 0), actualNumArgs); + PopJSFunctionArgs(assembler, actualNumArgs); + PopOptimizedFrame(assembler); + __ Ret(); +} + #undef __ } // namespace panda::ecmascript::x64 diff --git a/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.h b/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.h index 874cf7217a899eb628f6e43d9725a15246ba3537..d42dcf93f58aa2fc55100789f6cc3ec8fee449c9 100644 --- a/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.h +++ b/ecmascript/compiler/trampoline/x64/assembler_stubs_x64.h @@ -23,6 +23,11 @@ namespace panda::ecmascript::x64 { class AssemblerStubsX64 { public: + static constexpr int FRAME_SLOT_SIZE = 8; + static constexpr int DOUBLE_SLOT_SIZE = 16; + static constexpr int TRIPLE_SLOT_SIZE = 24; + static constexpr int QUADRUPLE_SLOT_SIZE = 32; + static constexpr int QUINTUPLE_SLOT_SIZE = 40; static void CallRuntime(ExtendedAssembler *assembler); static void JSFunctionEntry(ExtendedAssembler *assembler); @@ -31,7 +36,7 @@ public: static void CallBuiltinTrampoline(ExtendedAssembler *assembler); - static void JSCallWithArgV(ExtendedAssembler *assembler); + static void JSProxyCallInternalWithArgV(ExtendedAssembler *assembler); static void JSCall(ExtendedAssembler *assembler); @@ -77,13 +82,9 @@ public: static void ResumeUncaughtFrameAndReturn(ExtendedAssembler *assembler); + static void JSCallWithArgV(ExtendedAssembler *assembler); + private: - static void PushArgsFastPath(ExtendedAssembler *assembler, Register glueRegister, Register argcRegister, - Register argvRegister, Register callTargetRegister, Register methodRegister, Register prevSpRegister, - Register fpRegister, Register callFieldRegister); - static void PushArgsSlowPath(ExtendedAssembler *assembler, Register glueRegister, - Register declaredNumArgsRegister, Register argcRegister, Register argvRegister, Register callTargetRegister, - Register methodRegister, Register prevSpRegister, Register callFieldRegister); static void PushFrameState(ExtendedAssembler *assembler, Register prevSpRegister, Register fpRegister, Register callTargetRegister, Register methodRegister, Register pcRegister, Register operatorRegister); static void PushGeneratorFrameState(ExtendedAssembler *assembler, Register prevSpRegister, @@ -95,9 +96,6 @@ private: static void PopAsmInterpBridgeFrame(ExtendedAssembler *assembler); static void CallBCStub(ExtendedAssembler *assembler, Register newSpRegister, Register glueRegister, Register callTargetRegister, Register methodRegister, Register pcRegister); - static void GlueToThread(ExtendedAssembler *assembler, Register glueRegister, Register threadRegister); - static void ConstructEcmaRuntimeCallInfo(ExtendedAssembler *assembler, Register threadRegister, - Register numArgsRegister, Register stackArgsRegister); static void GetDeclaredNumArgsFromCallField(ExtendedAssembler *assembler, Register callFieldRegister, Register declaredNumArgsRegister); static void GetNumVregsFromCallField(ExtendedAssembler *assembler, Register callFieldRegister, @@ -107,18 +105,28 @@ private: static void StackOverflowCheck(ExtendedAssembler *assembler); static void PushCallThis(ExtendedAssembler *assembler, JSCallMode mode); static Register GetThisRegsiter(ExtendedAssembler *assembler, JSCallMode mode); + static Register GetNewTargetRegsiter(ExtendedAssembler *assembler, JSCallMode mode); static void PushVregs(ExtendedAssembler *assembler); static void DispatchCall(ExtendedAssembler *assembler, Register pcRegister, Register newSpRegister); static void CallNativeEntry(ExtendedAssembler *assemblSer); static void CallNativeWithArgv(ExtendedAssembler *assembler, bool callNew); - static void CallNativeInternal(ExtendedAssembler *assembler, - Register glue, Register numArgs, Register stackArgs, Register nativeCode); + static void CallNativeInternal(ExtendedAssembler *assembler, Register nativeCode); static void PushBuiltinFrame(ExtendedAssembler *assembler, Register glue, FrameType type); static void JSCallCommonEntry(ExtendedAssembler *assembler, JSCallMode mode); static void JSCallCommonFastPath(ExtendedAssembler *assembler, JSCallMode mode); static void JSCallCommonSlowPath(ExtendedAssembler *assembler, JSCallMode mode, Label *fastPathEntry, Label *pushCallThis); static void OptimizedCallAsmInterpreter(ExtendedAssembler *assembler); + static void PushArgsWithArgV(ExtendedAssembler *assembler, Register jsfunc, + Register actualNumArgs, Register argV, Label *pushCallThis); + static void CopyArgumentWithArgV(ExtendedAssembler *assembler, Register argc, Register argV); + static void PushMandatoryJSArgs(ExtendedAssembler *assembler, Register jsfunc, + Register thisObj, Register newTarget); + static void PopJSFunctionArgs(ExtendedAssembler *assembler, Register expectedNumArgs); + static void PushJSFunctionEntryFrame (ExtendedAssembler *assembler, Register prevFp); + static void PopJSFunctionEntryFrame(ExtendedAssembler *assembler, Register glue); + static void PushOptimizedFrame(ExtendedAssembler *assembler, Register callSiteSp); + static void PopOptimizedFrame(ExtendedAssembler *assembler); }; } // namespace panda::ecmascript::x64 #endif // ECMASCRIPT_COMPILER_ASSEMBLER_MODULE_X64_H diff --git a/ecmascript/compiler/type_inference/type_infer.cpp b/ecmascript/compiler/type_inference/type_infer.cpp index a7c2226680c99d64358f17df3ecc78ae0276506e..72e08ff1774e6344ab83527e01ce0f6b1b7eb89c 100644 --- a/ecmascript/compiler/type_inference/type_infer.cpp +++ b/ecmascript/compiler/type_inference/type_infer.cpp @@ -51,7 +51,7 @@ void TypeInfer::TraverseCircuit() } if (IsLogEnabled()) { - COMPILER_LOG(INFO) << "TypeInfer:======================================================"; + LOG_COMPILER(INFO) << "TypeInfer:======================================================"; circuit_->PrintAllGates(*builder_); } @@ -76,7 +76,7 @@ void TypeInfer::TypeInferPrint() const log += type.GetTypeStr(); } } - COMPILER_LOG(INFO) << std::dec << log; + LOG_COMPILER(INFO) << std::dec << log; } bool TypeInfer::UpdateType(GateRef gate, const GateType type) @@ -486,7 +486,8 @@ bool TypeInfer::InferNewObjSpread(GateRef gate) bool TypeInfer::InferSuperCall(GateRef gate) { - auto newTarget = builder_->GetCommonArgByIndex(CommonArgIdx::NEW_TARGET); + ArgumentAccessor argAcc(circuit_); + auto newTarget = argAcc.GetCommonArgGate(CommonArgIdx::NEW_TARGET); auto funcType = gateAccessor_.GetGateType(newTarget); if (!funcType.IsUndefinedType()) { return UpdateType(gate, funcType); diff --git a/ecmascript/compiler/type_inference/type_infer.h b/ecmascript/compiler/type_inference/type_infer.h index d998ce37eeabbbd516936021c6229b946ce45180..79d97aab7160c088c4720ade67b9e2d8de334a15 100644 --- a/ecmascript/compiler/type_inference/type_infer.h +++ b/ecmascript/compiler/type_inference/type_infer.h @@ -16,6 +16,7 @@ #ifndef ECMASCRIPT_COMPILER_TYPE_INFERENCE_TYPE_INFER_H #define ECMASCRIPT_COMPILER_TYPE_INFERENCE_TYPE_INFER_H +#include "ecmascript/compiler/argument_accessor.h" #include "ecmascript/compiler/bytecode_circuit_builder.h" #include "ecmascript/compiler/circuit.h" #include "ecmascript/compiler/gate_accessor.h" diff --git a/ecmascript/compiler/type_lowering.cpp b/ecmascript/compiler/type_lowering.cpp new file mode 100644 index 0000000000000000000000000000000000000000..238a9c66bfa6030df81b1f5a35f326cbbce3070d --- /dev/null +++ b/ecmascript/compiler/type_lowering.cpp @@ -0,0 +1,129 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/compiler/type_lowering.h" + +namespace panda::ecmascript::kungfu { +void TypeLowering::RunTypeLowering() +{ + const auto &gateList = circuit_->GetAllGates(); + for (const auto &gate : gateList) { + auto op = circuit_->GetOpCode(gate); + if (op == OpCode::JS_BYTECODE) { + Lower(gate); + } + } + + if (IsLogEnabled()) { + LOG_COMPILER(INFO) << "================== type lowering print all gates =================="; + circuit_->PrintAllGates(*bcBuilder_); + } +} + +void TypeLowering::Lower(GateRef gate) +{ + ArgumentAccessor argAcc(circuit_); + auto glue = argAcc.GetCommonArgGate(CommonArgIdx::GLUE); + + auto pc = bcBuilder_->GetJSBytecode(gate); + EcmaOpcode op = static_cast(*pc); + // initialize label manager + Environment env(gate, circuit_, &builder_); + switch (op) { + case NEWOBJDYNRANGE_PREF_IMM16_V8: + LowerTypeNewObjDynRange(gate, glue); + break; + default: + break; + } +} + +void TypeLowering::ReplaceHirToCall(GateRef hirGate, GateRef callGate, bool noThrow) +{ + GateRef stateInGate = acc_.GetState(hirGate); + // copy depend-wire of hirGate to callGate + GateRef dependInGate = acc_.GetDep(hirGate); + acc_.SetDep(callGate, dependInGate); + + GateRef ifBranch; + if (!noThrow) { + // exception value + GateRef exceptionVal = builder_.ExceptionConstant(GateType::TaggedNPointer()); + // compare with trampolines result + GateRef equal = builder_.BinaryLogic(OpCode(OpCode::EQ), callGate, exceptionVal); + ifBranch = builder_.Branch(stateInGate, equal); + } else { + ifBranch = builder_.Branch(stateInGate, builder_.Boolean(false)); + } + + auto uses = acc_.Uses(hirGate); + for (auto it = uses.begin(); it != uses.end(); it++) { + if (acc_.GetOpCode(*it) == OpCode::IF_SUCCESS) { + acc_.SetOpCode(*it, OpCode::IF_FALSE); + acc_.ReplaceIn(it, ifBranch); + } else { + if (acc_.GetOpCode(*it) == OpCode::IF_EXCEPTION) { + acc_.SetOpCode(*it, OpCode::IF_TRUE); + acc_.ReplaceIn(it, ifBranch); + } else { + acc_.ReplaceIn(it, callGate); + } + } + } + + // delete old gate + circuit_->DeleteGate(hirGate); +} + +GateRef TypeLowering::LowerCallRuntime(GateRef glue, int index, const std::vector &args, bool useLabel) +{ + if (useLabel) { + GateRef result = builder_.CallRuntime(glue, index, Gate::InvalidGateRef, args); + return result; + } else { + const CallSignature *cs = RuntimeStubCSigns::Get(RTSTUB_ID(CallRuntime)); + GateRef target = builder_.IntPtr(index); + GateRef result = builder_.Call(cs, glue, target, dependEntry_, args); + return result; + } +} + +void TypeLowering::LowerTypeNewObjDynRange(GateRef gate, GateRef glue) +{ + GateRef ctor = acc_.GetValueIn(gate, 0); + GateType ctorType = acc_.GetGateType(ctor); + ASSERT(ctorType.IsTSType()); + if (!ctorType.IsClassTypeKind()) { + return; + } + + GlobalTSTypeRef gt = GlobalTSTypeRef(ctorType.GetType()); + std::map gtHClassIndexMap = tsLoader_->GetGtHClassIndexMap(); + int64_t index = gtHClassIndexMap[gt]; + GateRef ihcIndex = builder_.TaggedTypeNGC(builder_.Int64(index)); + + size_t range = acc_.GetNumValueIn(gate); + std::vector args(range + 1); + + for (size_t i = 0; i < range; ++i) { + args[i] = acc_.GetValueIn(gate, i); + } + args[range] = ihcIndex; + + const int id = RTSTUB_ID(AotNewObjWithIHClass); + GateRef newGate = LowerCallRuntime(glue, id, args); + ReplaceHirToCall(gate, newGate); +} +} // namespace panda::ecmascript diff --git a/ecmascript/compiler/type_lowering.h b/ecmascript/compiler/type_lowering.h new file mode 100644 index 0000000000000000000000000000000000000000..390171a09a8740463da6548d2c54e213aea7660e --- /dev/null +++ b/ecmascript/compiler/type_lowering.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_COMPILER_TYPE_LOWERING_H +#define ECMASCRIPT_COMPILER_TYPE_LOWERING_H + +#include "ecmascript/compiler/argument_accessor.h" +#include "ecmascript/compiler/circuit.h" +#include "ecmascript/compiler/bytecode_circuit_builder.h" +#include "ecmascript/compiler/circuit_builder.h" +#include "ecmascript/compiler/circuit_builder-inl.h" +#include "ecmascript/compiler/gate_accessor.h" +#include "ecmascript/ts_types/ts_loader.h" + +namespace panda::ecmascript::kungfu { +class TypeLowering { +public: + TypeLowering(BytecodeCircuitBuilder *bcBuilder, Circuit *circuit, CompilationConfig *cmpCfg, TSLoader *tsLoader, + bool enableLog) + : bcBuilder_(bcBuilder), circuit_(circuit), acc_(circuit), builder_(circuit, cmpCfg), + dependEntry_(Circuit::GetCircuitRoot(OpCode(OpCode::DEPEND_ENTRY))), tsLoader_(tsLoader), + enableLog_(enableLog) {} + ~TypeLowering() = default; + + void RunTypeLowering(); + +private: + bool IsLogEnabled() const + { + return enableLog_; + } + + void Lower(GateRef gate); + + void ReplaceHirToCall(GateRef hirGate, GateRef callGate, bool noThrow = false); + + GateRef LowerCallRuntime(GateRef glue, int index, const std::vector &args, bool useLabel = false); + + void LowerTypeNewObjDynRange(GateRef gate, GateRef glue); + + BytecodeCircuitBuilder *bcBuilder_; + Circuit *circuit_; + GateAccessor acc_; + CircuitBuilder builder_; + GateRef dependEntry_; + TSLoader *tsLoader_ {nullptr}; + bool enableLog_ {false}; +}; +} // panda::ecmascript::kungfu +#endif // ECMASCRIPT_COMPILER_TYPE_LOWERING_H diff --git a/ecmascript/compiler/verifier.cpp b/ecmascript/compiler/verifier.cpp index b4c5a4abd4f37b8b46589942d3e717a18c0e4f19..367b2a321454b56eea52adcc6876fdcbbd143478 100644 --- a/ecmascript/compiler/verifier.cpp +++ b/ecmascript/compiler/verifier.cpp @@ -37,8 +37,8 @@ bool Verifier::RunDataIntegrityCheck(const Circuit *circuit) reinterpret_cast(circuit->LoadGatePtrConst(GateRef(out)))->GetGateConst()); if (gate < prevGate + static_cast(sizeof(Gate)) || gate >= static_cast(circuit->GetCircuitDataSize())) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (bad next gate)"; - COMPILER_LOG(ERROR) << "at: " << std::dec << gate; + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (bad next gate)"; + LOG_COMPILER(ERROR) << "at: " << std::dec << gate; return false; } gatesList.push_back(gate); @@ -51,8 +51,8 @@ bool Verifier::RunDataIntegrityCheck(const Circuit *circuit) break; } if (out > circuit->GetCircuitDataSize() || out < 0) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (out of bound access)"; - COMPILER_LOG(ERROR) << "at: " << std::dec << out; + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (out of bound access)"; + LOG_COMPILER(ERROR) << "at: " << std::dec << out; return false; } } @@ -60,13 +60,13 @@ bool Verifier::RunDataIntegrityCheck(const Circuit *circuit) for (size_t idx = 0; idx < circuit->LoadGatePtrConst(gate)->GetNumIns(); idx++) { const In *curIn = circuit->LoadGatePtrConst(gate)->GetInConst(idx); if (!(circuit->GetSpaceDataStartPtrConst() < curIn && curIn < circuit->GetSpaceDataEndPtrConst())) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (corrupted in list)"; - COMPILER_LOG(ERROR) << "id: " << std::dec << circuit->GetId(gate); + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (corrupted in list)"; + LOG_COMPILER(ERROR) << "id: " << std::dec << circuit->GetId(gate); return false; } if (gatesSet.count(circuit->SaveGatePtr(curIn->GetGateConst())) == 0) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (invalid in address)"; - COMPILER_LOG(ERROR) << "id: " << std::dec << circuit->GetId(gate); + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (invalid in address)"; + LOG_COMPILER(ERROR) << "id: " << std::dec << circuit->GetId(gate); return false; } } @@ -75,26 +75,26 @@ bool Verifier::RunDataIntegrityCheck(const Circuit *circuit) if (!curGate->IsFirstOutNull()) { const Out *curOut = curGate->GetFirstOutConst(); if (!(circuit->GetSpaceDataStartPtrConst() < curOut && curOut < circuit->GetSpaceDataEndPtrConst())) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (corrupted out list)"; - COMPILER_LOG(ERROR) << "id: " << std::dec << circuit->GetId(gate); + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (corrupted out list)"; + LOG_COMPILER(ERROR) << "id: " << std::dec << circuit->GetId(gate); return false; } if (gatesSet.count(circuit->SaveGatePtr(curOut->GetGateConst())) == 0) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (invalid out address)"; - COMPILER_LOG(ERROR) << "id: " << std::dec << circuit->GetId(gate); + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (invalid out address)"; + LOG_COMPILER(ERROR) << "id: " << std::dec << circuit->GetId(gate); return false; } while (!curOut->IsNextOutNull()) { curOut = curOut->GetNextOutConst(); if (!(circuit->GetSpaceDataStartPtrConst() < curOut && curOut < circuit->GetSpaceDataEndPtrConst())) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (corrupted out list)"; - COMPILER_LOG(ERROR) << "id: " << std::dec << circuit->GetId(gate); + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (corrupted out list)"; + LOG_COMPILER(ERROR) << "id: " << std::dec << circuit->GetId(gate); return false; } if (gatesSet.count(circuit->SaveGatePtr(curOut->GetGateConst())) == 0) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Circuit data is corrupted (invalid out address)"; - COMPILER_LOG(ERROR) << "id: " << std::dec << circuit->GetId(gate); + LOG_COMPILER(ERROR) << "[Verifier][Error] Circuit data is corrupted (invalid out address)"; + LOG_COMPILER(ERROR) << "id: " << std::dec << circuit->GetId(gate); return false; } } @@ -122,12 +122,12 @@ bool Verifier::RunCFGSoundnessCheck(const Circuit *circuit, const std::vectorGetOpCode(predGate).IsState() || circuit->GetOpCode(predGate) == OpCode::STATE_ENTRY) { if (bbGatesAddrToIdx.count(predGate) == 0) { - COMPILER_LOG(ERROR) << "[Verifier][Error] CFG is not sound"; - COMPILER_LOG(ERROR) << "Proof:"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(predGate) << ") is pred of " + LOG_COMPILER(ERROR) << "[Verifier][Error] CFG is not sound"; + LOG_COMPILER(ERROR) << "Proof:"; + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(predGate) << ") is pred of " << "(id=" << circuit->GetId(bbGate) << ")"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(bbGate) << ") is reachable from entry"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(predGate) << ") is unreachable from entry"; + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(bbGate) << ") is reachable from entry"; + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(predGate) << ") is unreachable from entry"; return false; } } @@ -150,12 +150,12 @@ bool Verifier::RunCFGIsDAGCheck(const Circuit *circuit) if (circuit->GetOpCode(*use).IsState() && use.GetIndex() < circuit->GetOpCode(*use).GetStateCount( circuit->LoadGatePtrConst(*use)->GetBitField())) { if (circuit->GetMark(*use) == MarkCode::VISITED) { - COMPILER_LOG(ERROR) << + LOG_COMPILER(ERROR) << "[Verifier][Error] CFG without loop back edges is not a directed acyclic graph"; - COMPILER_LOG(ERROR) << "Proof:"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(*use) << ") is succ of " + LOG_COMPILER(ERROR) << "Proof:"; + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(*use) << ") is succ of " << "(id=" << circuit->GetId(cur) << ")"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(cur) << ") is reachable from " + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(cur) << ") is reachable from " << "(id=" << circuit->GetId(*use) << ") without loop back edges"; return false; } @@ -192,11 +192,11 @@ bool Verifier::RunCFGReducibilityCheck(const Circuit *circuit, const std::vector ASSERT(circuit->LoadGatePtrConst(*use)->GetOpCode().IsState()); bool isDom = isAncestor(bbGatesAddrToIdx.at(*use), bbGatesAddrToIdx.at(curGate)); if (!isDom) { - COMPILER_LOG(ERROR) << "[Verifier][Error] CFG is not reducible"; - COMPILER_LOG(ERROR) << "Proof:"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(*use) << ") is loop back succ of " + LOG_COMPILER(ERROR) << "[Verifier][Error] CFG is not reducible"; + LOG_COMPILER(ERROR) << "Proof:"; + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(*use) << ") is loop back succ of " << "(id=" << circuit->GetId(curGate) << ")"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(*use) << ") does not dominate " + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(*use) << ") does not dominate " << "(id=" << circuit->GetId(curGate) << ")"; return false; } @@ -230,13 +230,13 @@ bool Verifier::RunFixedGatesRelationsCheck(const Circuit *circuit, const std::ve auto b = bbGatesAddrToIdx.at(circuit->GetIn(circuit->GetIn(fixedGate, 0), static_cast(cnt - 1))); if (!isAncestor(a, b)) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Fixed gates relationship is not consistent"; - COMPILER_LOG(ERROR) << "Proof:"; - COMPILER_LOG(ERROR) << "Fixed gate (id=" + LOG_COMPILER(ERROR) << "[Verifier][Error] Fixed gates relationship is not consistent"; + LOG_COMPILER(ERROR) << "Proof:"; + LOG_COMPILER(ERROR) << "Fixed gate (id=" << circuit->GetId(predGate) << ") is pred of fixed gate (id=" << circuit->GetId(fixedGate) << ")"; - COMPILER_LOG(ERROR) << "BB_" << bbGatesAddrToIdx.at(circuit->GetIn(predGate, 0)) + LOG_COMPILER(ERROR) << "BB_" << bbGatesAddrToIdx.at(circuit->GetIn(predGate, 0)) << " does not dominate BB_" << bbGatesAddrToIdx.at(circuit->GetIn(circuit->GetIn(fixedGate, 0), static_cast(cnt - 1))); @@ -285,12 +285,12 @@ bool Verifier::RunFlowCyclesFind(const Circuit *circuit, std::vector *s const auto prev = circuit->GetIn(cur, idx); if (circuit->GetOpCode(prev).IsSchedulable()) { if (circuit->GetMark(prev) == MarkCode::VISITED) { - COMPILER_LOG(ERROR) << + LOG_COMPILER(ERROR) << "[Verifier][Error] Found a data or depend flow cycle without passing selectors"; - COMPILER_LOG(ERROR) << "Proof:"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(prev) << ") is prev of " + LOG_COMPILER(ERROR) << "Proof:"; + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(prev) << ") is prev of " << "(id=" << circuit->GetId(cur) << ")"; - COMPILER_LOG(ERROR) << "(id=" << circuit->GetId(prev) << ") is reachable from " + LOG_COMPILER(ERROR) << "(id=" << circuit->GetId(prev) << ") is reachable from " << "(id=" << circuit->GetId(cur) << ") without passing selectors"; meet = prev; cycleGatesList.push_back(cur); @@ -315,7 +315,7 @@ bool Verifier::RunFlowCyclesFind(const Circuit *circuit, std::vector *s for (const auto &startGate : startGateList) { if (circuit->GetMark(startGate) == MarkCode::NO_MARK) { if (!dfs(startGate)) { - COMPILER_LOG(ERROR) << "Path:"; + LOG_COMPILER(ERROR) << "Path:"; for (const auto &cycleGate : cycleGatesList) { circuit->Print(cycleGate); } @@ -376,10 +376,10 @@ bool Verifier::RunSchedulingBoundsCheck(const Circuit *circuit, const std::vecto ASSERT(upperBound.size() == lowerBound.size()); for (const auto &item : lowerBound) { if (!isAncestor(upperBound.at(item.first), lowerBound.at(item.first))) { - COMPILER_LOG(ERROR) << "[Verifier][Error] Bounds of gate (id=" << item.first << ") is not consistent"; - COMPILER_LOG(ERROR) << "Proof:"; - COMPILER_LOG(ERROR) << "Upper bound is BB_" << upperBound.at(item.first); - COMPILER_LOG(ERROR) << "Lower bound is BB_" << lowerBound.at(item.first); + LOG_COMPILER(ERROR) << "[Verifier][Error] Bounds of gate (id=" << item.first << ") is not consistent"; + LOG_COMPILER(ERROR) << "Proof:"; + LOG_COMPILER(ERROR) << "Upper bound is BB_" << upperBound.at(item.first); + LOG_COMPILER(ERROR) << "Lower bound is BB_" << lowerBound.at(item.first); } } } @@ -403,7 +403,7 @@ bool Verifier::Run(const Circuit *circuit, bool enableLog) { if (!RunDataIntegrityCheck(circuit)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] Circuit data integrity verifier failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] Circuit data integrity verifier failed"; } return false; } @@ -413,19 +413,19 @@ bool Verifier::Run(const Circuit *circuit, bool enableLog) std::tie(bbGatesList, bbGatesAddrToIdx, immDom) = Scheduler::CalculateDominatorTree(circuit); if (!RunStateGatesCheck(circuit, bbGatesList)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunStateGatesCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunStateGatesCheck failed"; } return false; } if (!RunCFGSoundnessCheck(circuit, bbGatesList, bbGatesAddrToIdx)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunCFGSoundnessCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunCFGSoundnessCheck failed"; } return false; } if (!RunCFGIsDAGCheck(circuit)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunCFGIsDAGCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunCFGIsDAGCheck failed"; } return false; } @@ -473,51 +473,51 @@ bool Verifier::Run(const Circuit *circuit, bool enableLog) }; if (!RunCFGReducibilityCheck(circuit, bbGatesList, bbGatesAddrToIdx, isAncestor)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunCFGReducibilityCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunCFGReducibilityCheck failed"; } return false; } std::vector fixedGatesList = FindFixedGates(circuit, bbGatesList); if (!RunFixedGatesCheck(circuit, fixedGatesList)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunFixedGatesCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunFixedGatesCheck failed"; } return false; } if (!RunFixedGatesRelationsCheck(circuit, fixedGatesList, bbGatesAddrToIdx, isAncestor)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunFixedGatesRelationsCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunFixedGatesRelationsCheck failed"; } return false; } std::vector schedulableGatesList; if (!RunFlowCyclesFind(circuit, &schedulableGatesList, bbGatesList, fixedGatesList)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunFlowCyclesFind failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunFlowCyclesFind failed"; } return false; } if (!RunSchedulableGatesCheck(circuit, fixedGatesList)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunSchedulableGatesCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunSchedulableGatesCheck failed"; } return false; } if (!RunPrologGatesCheck(circuit, fixedGatesList)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunPrologGatesCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunPrologGatesCheck failed"; } return false; } if (!RunSchedulingBoundsCheck(circuit, schedulableGatesList, bbGatesAddrToIdx, isAncestor, lowestCommonAncestor)) { if (enableLog) { - COMPILER_LOG(ERROR) << "[Verifier][Fail] RunSchedulingBoundsCheck failed"; + LOG_COMPILER(ERROR) << "[Verifier][Fail] RunSchedulingBoundsCheck failed"; } return false; } if (enableLog) { - COMPILER_LOG(INFO) << "[Verifier][Pass] Verifier success"; + LOG_COMPILER(INFO) << "[Verifier][Pass] Verifier success"; } return true; diff --git a/ecmascript/containers/containers_deque.cpp b/ecmascript/containers/containers_deque.cpp index 6460dbb53a87ffb8a2c4dfcdadafaa75439e88c9..9b5058c111ba34d50d579cb3a700769c135742e6 100644 --- a/ecmascript/containers/containers_deque.cpp +++ b/ecmascript/containers/containers_deque.cpp @@ -173,6 +173,7 @@ JSTaggedValue ContainersDeque::PopLast(EcmaRuntimeCallInfo *argv) JSTaggedValue ContainersDeque::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); + BUILTINS_API_TRACE(argv->GetThread(), Deque, ForEach); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -197,10 +198,11 @@ JSTaggedValue ContainersDeque::ForEach(EcmaRuntimeCallInfo *argv) uint32_t index = 0; while (first != last) { JSTaggedValue kValue = deque->Get(index); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3:three args - info.SetCallArg(kValue, JSTaggedValue(index), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue, JSTaggedValue(index), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); ASSERT(capacity != 0); first = (first + 1) % capacity; diff --git a/ecmascript/containers/containers_lightweightmap.cpp b/ecmascript/containers/containers_lightweightmap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..da83806b4adaf7ab86ebc268bee505f9d68223e5 --- /dev/null +++ b/ecmascript/containers/containers_lightweightmap.cpp @@ -0,0 +1,471 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "containers_lightweightmap.h" +#include "ecmascript/base/array_helper.h" +#include "ecmascript/base/number_helper.h" +#include "ecmascript/base/typed_array_helper.h" +#include "ecmascript/base/typed_array_helper-inl.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/interpreter/interpreter.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_array.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tagged_array-inl.h" + +namespace panda::ecmascript::containers { +JSTaggedValue ContainersLightWeightMap::LightWeightMapConstructor(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Constructor); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle newTarget = GetNewTarget(argv); + if (newTarget->IsUndefined()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); + } + JSHandle constructor = GetConstructor(argv); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle lwMap = JSHandle::Cast(obj); + JSHandle hashArray = factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH); + JSHandle keyArray = factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH); + JSHandle valueArray = factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH); + lwMap->SetHashes(thread, hashArray.GetTaggedValue()); + lwMap->SetKeys(thread, keyArray.GetTaggedValue()); + lwMap->SetValues(thread, valueArray.GetTaggedValue()); + + return lwMap.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightMap::Length(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Length); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + return JSTaggedValue(JSHandle::Cast(self)->GetLength()); +} + +JSTaggedValue ContainersLightWeightMap::HasAll(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, HasAll); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle lightWeightMap(GetCallArg(argv, 0)); + if (!lightWeightMap->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "argv is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + return JSAPILightWeightMap::HasAll(thread, JSHandle::Cast(self), + JSHandle::Cast(lightWeightMap)); +} + +JSTaggedValue ContainersLightWeightMap::HasKey(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, HasKey); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + JSHandle key(GetCallArg(argv, 0)); + + return JSAPILightWeightMap::HasKey(thread, JSHandle::Cast(self), key); +} + +JSTaggedValue ContainersLightWeightMap::HasValue(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, HasValue); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle value(GetCallArg(argv, 0)); + return JSAPILightWeightMap::HasValue(thread, JSHandle::Cast(self), value); +} + +JSTaggedValue ContainersLightWeightMap::IncreaseCapacityTo(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, IncreaseCapacityTo); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle index(GetCallArg(argv, 0)); + + if (!index->IsInt()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the size is not integer", JSTaggedValue::Exception()); + } + JSAPILightWeightMap::IncreaseCapacityTo(thread, JSHandle::Cast(self), + index.GetTaggedValue().GetInt()); + + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + return JSTaggedValue::Undefined(); +} + +JSTaggedValue ContainersLightWeightMap::Entries(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Entries); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + JSHandle iter = + JSAPILightWeightMapIterator::CreateLightWeightMapIterator(thread, self, IterationKind::KEY_AND_VALUE); + return iter.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightMap::Get(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Get); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle key(GetCallArg(argv, 0)); + + return JSAPILightWeightMap::Get(thread, JSHandle::Cast(self), key); +} + +JSTaggedValue ContainersLightWeightMap::GetIndexOfKey(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, GetIndexOfKey); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle key(GetCallArg(argv, 0)); + + int32_t index = JSAPILightWeightMap::GetIndexOfKey(thread, JSHandle::Cast(self), key); + return JSTaggedValue(index); +} + +JSTaggedValue ContainersLightWeightMap::GetIndexOfValue(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, GetIndexOfValue); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle value(GetCallArg(argv, 0)); + + int32_t index = JSAPILightWeightMap::GetIndexOfValue(thread, JSHandle::Cast(self), value); + return JSTaggedValue(index); +} + +JSTaggedValue ContainersLightWeightMap::IsEmpty(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, IsEmpty); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + return JSHandle::Cast(self)->IsEmpty(); +} + +JSTaggedValue ContainersLightWeightMap::GetKeyAt(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, GetKeyAt); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle index(GetCallArg(argv, 0)); + + if (!index->IsInt()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the index is not integer", JSTaggedValue::Exception()); + } + + return JSAPILightWeightMap::GetKeyAt(thread, JSHandle::Cast(self), + index->GetInt()); +} + +JSTaggedValue ContainersLightWeightMap::Keys(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Keys); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + JSHandle iter = + JSAPILightWeightMapIterator::CreateLightWeightMapIterator(thread, self, IterationKind::KEY); + return iter.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightMap::SetAll(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, SetAll); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle lightWeightMap(GetCallArg(argv, 0)); + + if (!lightWeightMap->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "argv is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSAPILightWeightMap::SetAll(thread, JSHandle::Cast(self), + JSHandle::Cast(lightWeightMap)); + return JSTaggedValue::True(); +} + +JSTaggedValue ContainersLightWeightMap::Set(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Set); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle key(GetCallArg(argv, 0)); + JSHandle value(GetCallArg(argv, 1)); + + JSAPILightWeightMap::Set(thread, JSHandle::Cast(self), key, value); + return JSTaggedValue::True(); +} + +JSTaggedValue ContainersLightWeightMap::Remove(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Remove); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + JSHandle key(GetCallArg(argv, 0)); + + return JSAPILightWeightMap::Remove(thread, JSHandle::Cast(self), key); +} + +JSTaggedValue ContainersLightWeightMap::RemoveAt(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, RemoveAt); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle index(GetCallArg(argv, 0)); + if (!index->IsInt()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "index is not integer", JSTaggedValue::Exception()); + } + + return JSAPILightWeightMap::RemoveAt(thread, JSHandle::Cast(self), + index->GetInt()); +} + +JSTaggedValue ContainersLightWeightMap::Clear(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Clear); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSAPILightWeightMap::Clear(thread, JSHandle::Cast(self)); + return JSTaggedValue::True(); +} + +JSTaggedValue ContainersLightWeightMap::SetValueAt(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, SetValueAt); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + JSHandle index(GetCallArg(argv, 0)); + JSHandle value(GetCallArg(argv, 1)); + if (!index->IsInt()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "index is not Integer", JSTaggedValue::Exception()); + } + + return JSAPILightWeightMap::SetValueAt(thread, JSHandle::Cast(self), + index->GetInt(), value); +} + +JSTaggedValue ContainersLightWeightMap::ForEach(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, ForEach); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + // get and check lightweightmap object + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + // get and check callback function + JSHandle func(GetCallArg(argv, 0)); + if (!func->IsCallable()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "The first arg is not Callable", JSTaggedValue::Exception()); + } + // If thisArg was supplied, let T be thisArg; else let T be undefined. + JSHandle thisArg = GetCallArg(argv, 1); + JSHandle tmap = JSHandle::Cast(self); + JSMutableHandle keys(thread, tmap->GetKeys()); + JSMutableHandle values(thread, tmap->GetValues()); + int elements = tmap->GetSize(); + + int index = 0; + uint32_t length = keys->GetLength(); + const int32_t argsLength = 3; + JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + while (index < elements) { + // ignore the hash value is required to determine the true index + // Let funcResult be Call(callbackfn, T, «e, e, S»). + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(values->Get(index), keys->Get(index), self.GetTaggedValue()); + JSTaggedValue ret = JSFunction::Call(info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); + + // check entries should be update, size will be update in tmap set or remove. + if (tmap->GetLength() != length) { + keys.Update(tmap->GetKeys()); + values.Update(tmap->GetValues()); + elements = tmap->GetSize(); + length = keys->GetLength(); + } + index++; + } + return JSTaggedValue::Undefined(); +} + +JSTaggedValue ContainersLightWeightMap::ToString(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, ToString); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + + return JSAPILightWeightMap::ToString(thread, JSHandle::Cast(self)); +} + +JSTaggedValue ContainersLightWeightMap::GetValueAt(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, GetValueAt); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + + if (!self->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", JSTaggedValue::Exception()); + } + JSHandle index(GetCallArg(argv, 0)); + if (!index->IsInt()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the index is not integer", JSTaggedValue::Exception()); + } + + return JSAPILightWeightMap::GetValueAt(thread, JSHandle::Cast(self), + index->GetInt()); +} + +JSTaggedValue ContainersLightWeightMap::Values(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightMap, Keys); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + JSHandle iter = + JSAPILightWeightMapIterator::CreateLightWeightMapIterator(thread, self, IterationKind::VALUE); + return iter.GetTaggedValue(); +} +} // namespace panda::ecmascript::containers diff --git a/ecmascript/containers/containers_lightweightmap.h b/ecmascript/containers/containers_lightweightmap.h new file mode 100644 index 0000000000000000000000000000000000000000..5aa999ec4d15f90c991da86e92f03f845f372abe --- /dev/null +++ b/ecmascript/containers/containers_lightweightmap.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHTWEIGHTMAP_H +#define ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHTWEIGHTMAP_H + +#include "ecmascript/base/builtins_base.h" +#include "ecmascript/ecma_runtime_call_info.h" + +namespace panda::ecmascript::containers { +class ContainersLightWeightMap : public base::BuiltinsBase { +public: + static JSTaggedValue LightWeightMapConstructor(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Length(EcmaRuntimeCallInfo *argv); + static JSTaggedValue HasAll(EcmaRuntimeCallInfo *argv); + static JSTaggedValue HasKey(EcmaRuntimeCallInfo *argv); + static JSTaggedValue HasValue(EcmaRuntimeCallInfo *argv); + static JSTaggedValue IncreaseCapacityTo(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Get(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetIndexOfKey(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetIndexOfValue(EcmaRuntimeCallInfo *argv); + static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetKeyAt(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Keys(EcmaRuntimeCallInfo *argv); + static JSTaggedValue SetAll(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Set(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv); + static JSTaggedValue RemoveAt(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); + static JSTaggedValue SetValueAt(EcmaRuntimeCallInfo *argv); + static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); + static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetValueAt(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); +}; +} // namespace panda::ecmascript::containers +#endif // ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHTWEIGHTMAP_H diff --git a/ecmascript/containers/containers_lightweightset.cpp b/ecmascript/containers/containers_lightweightset.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f4123994e1f088632f74602b2fc026af7f6b0cc3 --- /dev/null +++ b/ecmascript/containers/containers_lightweightset.cpp @@ -0,0 +1,366 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "containers_lightweightset.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightset_iterator.h" +#include "ecmascript/js_array.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tagged_array-inl.h" + +namespace panda::ecmascript::containers { +JSTaggedValue ContainersLightWeightSet::LightWeightSetConstructor(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Constructor); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle newTarget = GetNewTarget(argv); + if (newTarget->IsUndefined()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "new target can't be undefined", JSTaggedValue::Exception()); + } + JSHandle constructor = GetConstructor(argv); + JSHandle obj = factory->NewJSObjectByConstructor(JSHandle(constructor), newTarget); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSHandle lightweightSet = JSHandle::Cast(obj); + + JSHandle hashes = + JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH); + JSHandle values = + JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH); + lightweightSet->SetHashes(thread, hashes); + lightweightSet->SetValues(thread, values); + return obj.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightSet::Add(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Add); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + bool flag = JSAPILightWeightSet::Add(thread, JSHandle::Cast(self), value); + return JSTaggedValue(flag); +} + +JSTaggedValue ContainersLightWeightSet::AddAll(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, AddAll); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + return JSTaggedValue(JSAPILightWeightSet::AddAll(thread, JSHandle::Cast(self), value)); +} + +JSTaggedValue ContainersLightWeightSet::IsEmpty(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, IsEmpty); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return JSTaggedValue(set->IsEmpty()); +} + +JSTaggedValue ContainersLightWeightSet::GetValueAt(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, GetValueAt); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Undefined()); + } + JSHandle value(GetCallArg(argv, 0)); + if (!value->IsInteger()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the index is not integer", JSTaggedValue::Undefined()); + } + int32_t index = value->GetInt(); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return set->GetValueAt(index); +} + +JSTaggedValue ContainersLightWeightSet::HasAll(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, HasAll); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return JSTaggedValue(set->HasAll(value)); +} + +JSTaggedValue ContainersLightWeightSet::Has(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Has); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return JSTaggedValue(set->Has(value)); +} + +JSTaggedValue ContainersLightWeightSet::HasHash(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, HasHash); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return JSTaggedValue(set->HasHash(value)); +} + +JSTaggedValue ContainersLightWeightSet::Equal(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Equal); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + return JSTaggedValue(JSAPILightWeightSet::Equal(thread, JSHandle::Cast(self), value)); +} + +JSTaggedValue ContainersLightWeightSet::IncreaseCapacityTo(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, IncreaseCapacityTo); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + if (!value->IsInteger()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the index is not integer", JSTaggedValue::Exception()); + } + int32_t minCapacity = value->GetInt(); + JSAPILightWeightSet::IncreaseCapacityTo(thread, JSHandle::Cast(self), minCapacity); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::False()); + return JSTaggedValue::Undefined(); +} + +JSTaggedValue ContainersLightWeightSet::GetIteratorObj(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, GetIteratorObj); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle iter = + JSAPILightWeightSet::GetIteratorObj(thread, JSHandle::Cast(self), IterationKind::VALUE); + return iter.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightSet::Values(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Values); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle iter = + JSAPILightWeightSet::GetIteratorObj(thread, JSHandle::Cast(self), IterationKind::VALUE); + return iter.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightSet::Entries(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Entries); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle iter = + JSAPILightWeightSet::GetIteratorObj(thread, JSHandle::Cast(self), + IterationKind::KEY_AND_VALUE); + return iter.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightSet::ForEach(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, ForEach); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle thisHandle = GetThis(argv); + JSHandle callbackFnHandle = GetCallArg(argv, 0); + if (!callbackFnHandle->IsCallable()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the callbackfun is not callable.", JSTaggedValue::Exception()); + } + JSHandle thisArgHandle = GetCallArg(argv, 1); + return JSAPILightWeightSet::ForEach(thread, thisHandle, callbackFnHandle, thisArgHandle); +} + +JSTaggedValue ContainersLightWeightSet::GetIndexOf(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, GetIndexOf); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + int32_t result = set->GetIndexOf(value); + return JSTaggedValue(result); +} + +JSTaggedValue ContainersLightWeightSet::Remove(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Remove); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle key(GetCallArg(argv, 0)); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return set->Remove(thread, key); +} + +JSTaggedValue ContainersLightWeightSet::RemoveAt(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, RemoveAt); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle value(GetCallArg(argv, 0)); + if (!value->IsInteger()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "the index is not integer", JSTaggedValue::Exception()); + } + int32_t index = value->GetInt(); + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + return JSTaggedValue(set->RemoveAt(thread, index)); +} + +JSTaggedValue ContainersLightWeightSet::Clear(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, Clear); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSAPILightWeightSet *set = JSAPILightWeightSet::Cast(self->GetTaggedObject()); + set->Clear(thread); + return JSTaggedValue::True(); +} + +JSTaggedValue ContainersLightWeightSet::ToString(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, ToString); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSTaggedValue value = JSAPILightWeightSet::ToString(thread, JSHandle::Cast(self)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + return value; +} + +JSTaggedValue ContainersLightWeightSet::ToArray(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, ToArray); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + JSHandle lightweightset = JSHandle::Cast(self); + uint32_t length = lightweightset->GetLength(); + JSHandle array = thread->GetEcmaVM()->GetFactory()->NewJSArray(); + array->SetArrayLength(thread, length); + JSHandle valueArray(thread, lightweightset->GetValues()); + uint32_t capacity = valueArray->GetLength(); + JSHandle newElements = + thread->GetEcmaVM()->GetFactory()->CopyArray(valueArray, capacity, capacity); + array->SetElements(thread, newElements); + return array.GetTaggedValue(); +} + +JSTaggedValue ContainersLightWeightSet::GetSize(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + BUILTINS_API_TRACE(thread, LightWeightSet, GetSize); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle self = GetThis(argv); + if (!self->IsJSAPILightWeightSet()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightSet", JSTaggedValue::Exception()); + } + return JSTaggedValue(JSHandle::Cast(self)->GetSize()); +} +} // namespace panda::ecmascript::containers \ No newline at end of file diff --git a/ecmascript/containers/containers_lightweightset.h b/ecmascript/containers/containers_lightweightset.h new file mode 100644 index 0000000000000000000000000000000000000000..bd65c223fc45c267734d5e3cc41f68afd8bd8dde --- /dev/null +++ b/ecmascript/containers/containers_lightweightset.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHT_WEIGHT_SET_H +#define ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHT_WEIGHT_SET_H + +#include "ecmascript/base/builtins_base.h" +#include "ecmascript/ecma_runtime_call_info.h" + +namespace panda::ecmascript::containers { +class ContainersLightWeightSet : public base::BuiltinsBase { +public: + static JSTaggedValue LightWeightSetConstructor(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Add(EcmaRuntimeCallInfo *argv); + static JSTaggedValue AddAll(EcmaRuntimeCallInfo *argv); + static JSTaggedValue IsEmpty(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetValueAt(EcmaRuntimeCallInfo *argv); + static JSTaggedValue HasAll(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Has(EcmaRuntimeCallInfo *argv); + static JSTaggedValue HasHash(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Equal(EcmaRuntimeCallInfo *argv); + static JSTaggedValue IncreaseCapacityTo(EcmaRuntimeCallInfo *argv); + static JSTaggedValue ForEach(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetIndexOf(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Remove(EcmaRuntimeCallInfo *argv); + static JSTaggedValue RemoveAt(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Clear(EcmaRuntimeCallInfo *argv); + static JSTaggedValue ToString(EcmaRuntimeCallInfo *argv); + static JSTaggedValue ToArray(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetSize(EcmaRuntimeCallInfo *argv); + static JSTaggedValue GetIteratorObj(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Values(EcmaRuntimeCallInfo *argv); + static JSTaggedValue Entries(EcmaRuntimeCallInfo *argv); +}; +} // namespace panda::ecmascript::containers +#endif // ECMASCRIPT_CONTAINERS_CONTAINERS_LIGHT_WEIGHT_SET_H \ No newline at end of file diff --git a/ecmascript/containers/containers_linked_list.cpp b/ecmascript/containers/containers_linked_list.cpp index 45b0fa9aa75e828090eba09c444acf9302b81dd2..c76f6e2ca42b57628c0d670e08601b0689d5e429 100644 --- a/ecmascript/containers/containers_linked_list.cpp +++ b/ecmascript/containers/containers_linked_list.cpp @@ -405,10 +405,11 @@ JSTaggedValue ContainersLinkedList::ForEach(EcmaRuntimeCallInfo *argv) JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); while (index < length) { JSTaggedValue value = doubleList->Get(index); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(value, JSTaggedValue(index), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(value, JSTaggedValue(index), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); index++; } diff --git a/ecmascript/containers/containers_list.cpp b/ecmascript/containers/containers_list.cpp index 5fdfbc0a7c0b9adcb7d360900601c0617e18d1e1..46e2bbf77d280366c8971dd3cf1c80dc8c1e4ff7 100644 --- a/ecmascript/containers/containers_list.cpp +++ b/ecmascript/containers/containers_list.cpp @@ -239,10 +239,11 @@ JSTaggedValue ContainersList::ForEach(EcmaRuntimeCallInfo *argv) const uint32_t argsLength = 3; // 3: «kValue, k, O» while (index < length) { JSTaggedValue value = singleList->Get(index); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(value, JSTaggedValue(index), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(value, JSTaggedValue(index), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); index++; } diff --git a/ecmascript/containers/containers_private.cpp b/ecmascript/containers/containers_private.cpp index f599f3479c99303cd85e31b68159676de6555d24..4c535a3b7525778191047eb1e33d10835644cbfc 100644 --- a/ecmascript/containers/containers_private.cpp +++ b/ecmascript/containers/containers_private.cpp @@ -17,6 +17,8 @@ #include "containers_arraylist.h" #include "containers_deque.h" +#include "containers_lightweightmap.h" +#include "containers_lightweightset.h" #include "containers_linked_list.h" #include "containers_list.h" #include "containers_plainarray.h" @@ -32,6 +34,10 @@ #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list.h" @@ -70,28 +76,36 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) res = InitializeContainer(thread, thisValue, InitializeArrayList, "ArrayListConstructor"); break; } - case ContainerTag::TreeMap: { - res = InitializeContainer(thread, thisValue, InitializeTreeMap, "TreeMapConstructor"); + case ContainerTag::Deque: { + res = InitializeContainer(thread, thisValue, InitializeDeque, "DequeConstructor"); break; } - case ContainerTag::TreeSet: { - res = InitializeContainer(thread, thisValue, InitializeTreeSet, "TreeSetConstructor"); + case ContainerTag::LightWeightMap: { + res = InitializeContainer(thread, thisValue, InitializeLightWeightMap, "LightWeightMapConstructor"); break; } - case ContainerTag::Stack: { - res = InitializeContainer(thread, thisValue, InitializeStack, "StackConstructor"); + case ContainerTag::LightWeightSet: { + res = InitializeContainer(thread, thisValue, InitializeLightWeightSet, "LightWeightSetConstructor"); + break; + } + case ContainerTag::PlainArray: { + res = InitializeContainer(thread, thisValue, InitializePlainArray, "PlainArrayConstructor"); break; } case ContainerTag::Queue: { res = InitializeContainer(thread, thisValue, InitializeQueue, "QueueConstructor"); break; } - case ContainerTag::Deque: { - res = InitializeContainer(thread, thisValue, InitializeDeque, "DequeConstructor"); + case ContainerTag::Stack: { + res = InitializeContainer(thread, thisValue, InitializeStack, "StackConstructor"); break; } - case ContainerTag::PlainArray: { - res = InitializeContainer(thread, thisValue, InitializePlainArray, "PlainArrayConstructor"); + case ContainerTag::TreeMap: { + res = InitializeContainer(thread, thisValue, InitializeTreeMap, "TreeMapConstructor"); + break; + } + case ContainerTag::TreeSet: { + res = InitializeContainer(thread, thisValue, InitializeTreeSet, "TreeSetConstructor"); break; } case ContainerTag::Vector: { @@ -108,8 +122,6 @@ JSTaggedValue ContainersPrivate::Load(EcmaRuntimeCallInfo *msg) } case ContainerTag::HashMap: case ContainerTag::HashSet: - case ContainerTag::LightWeightMap: - case ContainerTag::LightWeightSet: case ContainerTag::END: break; default: @@ -311,6 +323,141 @@ void ContainersPrivate::InitializeArrayListIterator(JSThread *thread, const JSHa arrayListIteratorPrototype.GetTaggedValue()); } +JSHandle ContainersPrivate::InitializeLightWeightMap(JSThread *thread) +{ + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle funcPrototype = factory->NewEmptyJSObject(); + JSHandle mapFuncPrototypeValue(funcPrototype); + JSHandle lightWeightMapInstanceDynclass = + factory->NewEcmaDynClass(JSAPILightWeightMap::SIZE, JSType::JS_API_LIGHT_WEIGHT_MAP, mapFuncPrototypeValue); + JSHandle lightWeightMapFunction(NewContainerConstructor( + thread, funcPrototype, ContainersLightWeightMap::LightWeightMapConstructor, "LightWeightMap", + FuncLength::ZERO)); + JSHandle::Cast(lightWeightMapFunction)-> + SetFunctionPrototype(thread, lightWeightMapInstanceDynclass.GetTaggedValue()); + + // "constructor" property on the prototype + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread, JSHandle(funcPrototype), constructorKey, lightWeightMapFunction); + + // LightWeightMap.prototype.add() + SetFrozenFunction(thread, funcPrototype, "hasAll", ContainersLightWeightMap::HasAll, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "hasKey", ContainersLightWeightMap::HasKey, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "hasValue", ContainersLightWeightMap::HasValue, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "increaseCapacityTo", ContainersLightWeightMap::IncreaseCapacityTo, + FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "entries", ContainersLightWeightMap::Entries, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "get", ContainersLightWeightMap::Get, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "getIndexOfKey", ContainersLightWeightMap::GetIndexOfKey, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "getIndexOfValue", ContainersLightWeightMap::GetIndexOfValue, + FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "isEmpty", ContainersLightWeightMap::IsEmpty, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "getKeyAt", ContainersLightWeightMap::GetKeyAt, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "keys", ContainersLightWeightMap::Keys, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "setAll", ContainersLightWeightMap::SetAll, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "set", ContainersLightWeightMap::Set, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "remove", ContainersLightWeightMap::Remove, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "removeAt", ContainersLightWeightMap::RemoveAt, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "clear", ContainersLightWeightMap::Clear, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "setValueAt", ContainersLightWeightMap::SetValueAt, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "forEach", ContainersLightWeightMap::ForEach, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "toString", ContainersLightWeightMap::ToString, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "getValueAt", ContainersLightWeightMap::GetValueAt, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "values", ContainersLightWeightMap::Values, FuncLength::ONE); + + JSHandle lengthGetter = CreateGetter(thread, ContainersLightWeightMap::Length, "length", + FuncLength::ZERO); + JSHandle lengthKey(factory->NewFromASCII("length")); + SetGetter(thread, funcPrototype, lengthKey, lengthGetter); + + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + SetFunctionAtSymbol(thread, env, funcPrototype, env->GetIteratorSymbol(), "[Symbol.iterator]", + ContainersLightWeightMap::Entries, FuncLength::ONE); + + ContainersPrivate::InitializeLightWeightMapIterator(thread); + return lightWeightMapFunction; +} + +void ContainersPrivate::InitializeLightWeightMapIterator(JSThread *thread) +{ + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle iteratorDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_ITERATOR, + env->GetIteratorPrototype()); + JSHandle lightWeightMapIteratorPrototype(factory->NewJSObject(iteratorDynclass)); + SetFrozenFunction(thread, lightWeightMapIteratorPrototype, "next", JSAPILightWeightMapIterator::Next, + FuncLength::ONE); + SetStringTagSymbol(thread, env, lightWeightMapIteratorPrototype, "LightWeightMap Iterator"); + auto globalConst = const_cast(thread->GlobalConstants()); + globalConst->SetConstant(ConstantIndex::LIGHTWEIGHTMAP_ITERATOR_PROTOTYPE_INDEX, + lightWeightMapIteratorPrototype.GetTaggedValue()); +} + +JSHandle ContainersPrivate::InitializeLightWeightSet(JSThread *thread) +{ + const GlobalEnvConstants *globalConst = thread->GlobalConstants(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + // LightWeightSet.prototype + JSHandle funcPrototype = factory->NewEmptyJSObject(); + JSHandle funcPrototypeValue(funcPrototype); + // LightWeightSet.prototype_or_dynclass + JSHandle lightweightSetInstanceDynclass = + factory->NewEcmaDynClass(JSAPILightWeightSet::SIZE, JSType::JS_API_LIGHT_WEIGHT_SET, funcPrototypeValue); + JSHandle lightweightSetFunction( + NewContainerConstructor(thread, funcPrototype, ContainersLightWeightSet::LightWeightSetConstructor, + "LightWeightSet", FuncLength::ZERO)); + JSHandle::Cast(lightweightSetFunction)->SetFunctionPrototype(thread, lightweightSetInstanceDynclass. + GetTaggedValue()); + // "constructor" property on the prototype + JSHandle constructorKey = globalConst->GetHandledConstructorString(); + JSObject::SetProperty(thread, JSHandle(funcPrototype), constructorKey, lightweightSetFunction); + SetFrozenFunction(thread, funcPrototype, "add", ContainersLightWeightSet::Add, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "addAll", ContainersLightWeightSet::AddAll, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "isEmpty", ContainersLightWeightSet::IsEmpty, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "getValueAt", ContainersLightWeightSet::GetValueAt, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "hasAll", ContainersLightWeightSet::HasAll, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "has", ContainersLightWeightSet::Has, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "equal", ContainersLightWeightSet::Equal, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "increaseCapacityTo", + ContainersLightWeightSet::IncreaseCapacityTo, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "forEach", ContainersLightWeightSet::ForEach, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "getIndexOf", ContainersLightWeightSet::GetIndexOf, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "remove", ContainersLightWeightSet::Remove, FuncLength::ZERO); + SetFrozenFunction(thread, funcPrototype, "removeAt", ContainersLightWeightSet::RemoveAt, FuncLength::ZERO); + SetFrozenFunction(thread, funcPrototype, "clear", ContainersLightWeightSet::Clear, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "toString", ContainersLightWeightSet::ToString, FuncLength::ZERO); + SetFrozenFunction(thread, funcPrototype, "toArray", ContainersLightWeightSet::ToArray, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "values", ContainersLightWeightSet::Values, FuncLength::ONE); + SetFrozenFunction(thread, funcPrototype, "entries", ContainersLightWeightSet::Entries, FuncLength::ZERO); + JSHandle lengthGetter = + CreateGetter(thread, ContainersLightWeightSet::GetSize, "length", FuncLength::ZERO); + + JSHandle lengthKey(factory->NewFromASCII("length")); + SetGetter(thread, funcPrototype, lengthKey, lengthGetter); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + SetFunctionAtSymbol(thread, env, funcPrototype, env->GetIteratorSymbol(), "[Symbol.iterator]", + ContainersLightWeightSet::GetIteratorObj, FuncLength::ONE); + + InitializeLightWeightSetIterator(thread); + return lightweightSetFunction; +} + +void ContainersPrivate::InitializeLightWeightSetIterator(JSThread *thread) +{ + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + auto globalConst = const_cast(thread->GlobalConstants()); + JSHandle iteratorDynclass = JSHandle(thread, globalConst->GetHandledJSAPIIteratorFuncDynClass(). + GetObject()); + JSHandle lightWeightSetIteratorPrototype(factory->NewJSObject(iteratorDynclass)); + SetFrozenFunction( + thread, lightWeightSetIteratorPrototype, "next", JSAPILightWeightSetIterator::Next, FuncLength::ONE); + SetStringTagSymbol(thread, env, lightWeightSetIteratorPrototype, "LightWeightSet Iterator"); + globalConst->SetConstant(ConstantIndex::LIGHTWEIGHTSET_ITERATOR_PROTOTYPE_INDEX, + lightWeightSetIteratorPrototype.GetTaggedValue()); +} + JSHandle ContainersPrivate::InitializeTreeMap(JSThread *thread) { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); diff --git a/ecmascript/containers/containers_private.h b/ecmascript/containers/containers_private.h index c3e27ef86c696031863be8df1ae8aa49dd2b6cd5..7f98e48b8e1c22698f930ae76bfa5dbdf1f3fe10 100644 --- a/ecmascript/containers/containers_private.h +++ b/ecmascript/containers/containers_private.h @@ -70,6 +70,10 @@ private: static JSHandle InitializeArrayList(JSThread *thread); static void InitializeArrayListIterator(JSThread *thread, const JSHandle &env, GlobalEnvConstants *globalConst); + static JSHandle InitializeLightWeightMap(JSThread *thread); + static void InitializeLightWeightMapIterator(JSThread *thread); + static JSHandle InitializeLightWeightSet(JSThread *thread); + static void InitializeLightWeightSetIterator(JSThread *thread); static JSHandle InitializeTreeMap(JSThread *thread); static void InitializeTreeMapIterator(JSThread *thread); static JSHandle InitializeTreeSet(JSThread *thread); diff --git a/ecmascript/containers/containers_queue.cpp b/ecmascript/containers/containers_queue.cpp index 0eed031e299cd350e406a5a53f293f5b30ac228d..30af66a586ec80fe49813e3fd9210f5e37b5968b 100644 --- a/ecmascript/containers/containers_queue.cpp +++ b/ecmascript/containers/containers_queue.cpp @@ -96,6 +96,7 @@ JSTaggedValue ContainersQueue::Pop(EcmaRuntimeCallInfo *argv) JSTaggedValue ContainersQueue::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv); + BUILTINS_API_TRACE(argv->GetThread(), Queue, ForEach); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -127,11 +128,12 @@ JSTaggedValue ContainersQueue::ForEach(EcmaRuntimeCallInfo *argv) JSHandle(thread, queue->Get(thread, index)); index = queue->GetNextPosition(index); key.Update(JSTaggedValue(k)); - const size_t argsLength = 3; - EcmaRuntimeCallInfo info = + const int32_t argsLength = 3; + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); k++; } diff --git a/ecmascript/containers/containers_stack.cpp b/ecmascript/containers/containers_stack.cpp index b011d2b34ba55bb6a6cec23e3f858d1dae45e07a..530cf19921d954ca6e3a379a944fa2c4cc54d545 100644 --- a/ecmascript/containers/containers_stack.cpp +++ b/ecmascript/containers/containers_stack.cpp @@ -135,6 +135,7 @@ JSTaggedValue ContainersStack::Pop(EcmaRuntimeCallInfo *argv) JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv) { ASSERT(argv != nullptr); + BUILTINS_API_TRACE(argv->GetThread(), Stack, ForEach); JSThread *thread = argv->GetThread(); [[maybe_unused]] EcmaHandleScope handleScope(thread); @@ -157,10 +158,11 @@ JSTaggedValue ContainersStack::ForEach(EcmaRuntimeCallInfo *argv) int k = 0; while (k < len + 1) { JSTaggedValue kValue = stack->Get(k); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFnHandle, thisArgHandle, undefined, 3); // 3:three args - info.SetCallArg(kValue, JSTaggedValue(k), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue, JSTaggedValue(k), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); k++; } diff --git a/ecmascript/containers/containers_treemap.cpp b/ecmascript/containers/containers_treemap.cpp index 50a9529610abed73fb8cb949b37b7bd117f67794..a065126a5a8b612ecb7857acecee4c8aa8ed6d3a 100644 --- a/ecmascript/containers/containers_treemap.cpp +++ b/ecmascript/containers/containers_treemap.cpp @@ -332,7 +332,7 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) int index = 0; size_t length = entries->GetLength(); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); @@ -342,9 +342,10 @@ JSTaggedValue ContainersTreeMap::ForEach(EcmaRuntimeCallInfo *argv) value.Update(iteratedMap->GetValue(entriesIndex)); // Let funcResult be Call(callbackfn, T, «e, e, S»). - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); - info.SetCallArg(value.GetTaggedValue(), key.GetTaggedValue(), self.GetTaggedValue()); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(value.GetTaggedValue(), key.GetTaggedValue(), self.GetTaggedValue()); + JSTaggedValue ret = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // check entries should be update, size will be update in tmap set or remove. diff --git a/ecmascript/containers/containers_treeset.cpp b/ecmascript/containers/containers_treeset.cpp index 49750d8e8229910a3a8c7344c68bf91d8f3f92d4..10d7dfaf83f2db5c40a988f85a40d06ad3cb329a 100644 --- a/ecmascript/containers/containers_treeset.cpp +++ b/ecmascript/containers/containers_treeset.cpp @@ -287,7 +287,7 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) int index = 0; size_t length = entries->GetLength(); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); JSMutableHandle key(thread, JSTaggedValue::Undefined()); while (index < elements) { @@ -295,9 +295,10 @@ JSTaggedValue ContainersTreeSet::ForEach(EcmaRuntimeCallInfo *argv) key.Update(iteratedSet->GetKey(entriesIndex)); // Let funcResult be Call(callbackfn, T, «e, e, S»). - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); - info.SetCallArg(key.GetTaggedValue(), key.GetTaggedValue(), self.GetTaggedValue()); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisArg, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(key.GetTaggedValue(), key.GetTaggedValue(), self.GetTaggedValue()); + JSTaggedValue ret = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ret); // check entries should be update, size will be update by set add and remove. diff --git a/ecmascript/containers/tests/BUILD.gn b/ecmascript/containers/tests/BUILD.gn index 54ff4c5e41716b74d29fa2417698b40acc0b0b14..8aea7bbe26153cb3e1ee791a5fa456de26508495 100644 --- a/ecmascript/containers/tests/BUILD.gn +++ b/ecmascript/containers/tests/BUILD.gn @@ -23,6 +23,8 @@ host_unittest_action("ContainersTest") { sources = [ # test file "containers_deque_test.cpp", + "containers_lightweightmap_test.cpp", + "containers_lightweightset_test.cpp", "containers_linked_list_test.cpp", "containers_list_test.cpp", "containers_plainarray_test.cpp", diff --git a/ecmascript/containers/tests/containers_deque_test.cpp b/ecmascript/containers/tests/containers_deque_test.cpp index b483b11eb6fa2b96daaec672235f0d782727e9e7..0ca1b23c2b69988de899776acfa5ad28f9e8d86d 100644 --- a/ecmascript/containers/tests/containers_deque_test.cpp +++ b/ecmascript/containers/tests/containers_deque_test.cpp @@ -88,8 +88,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::Deque))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -105,8 +105,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersDeque::DequeConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersDeque::DequeConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle deque(thread, result); return deque; @@ -123,8 +123,8 @@ HWTEST_F_L0(ContainersDequeTest, DequeConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersDeque::DequeConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersDeque::DequeConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIDeque()); @@ -144,11 +144,11 @@ HWTEST_F_L0(ContainersDequeTest, InsertFrontAndGetFirst) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersDeque::InsertFront(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersDeque::InsertFront(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(ContainersDeque::GetFirst(callInfo.get()), JSTaggedValue(i)); + EXPECT_EQ(ContainersDeque::GetFirst(callInfo), JSTaggedValue(i)); } } @@ -162,11 +162,11 @@ HWTEST_F_L0(ContainersDequeTest, InsertEndAndGetLast) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersDeque::InsertEnd(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersDeque::InsertEnd(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); - EXPECT_EQ(ContainersDeque::GetLast(callInfo.get()), JSTaggedValue(i)); + EXPECT_EQ(ContainersDeque::GetLast(callInfo), JSTaggedValue(i)); } } @@ -180,8 +180,8 @@ HWTEST_F_L0(ContainersDequeTest, Has) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersDeque::InsertEnd(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersDeque::InsertEnd(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -192,8 +192,8 @@ HWTEST_F_L0(ContainersDequeTest, Has) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersDeque::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersDeque::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); } @@ -204,8 +204,8 @@ HWTEST_F_L0(ContainersDequeTest, Has) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i + 8)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersDeque::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersDeque::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::False()); } @@ -221,10 +221,10 @@ HWTEST_F_L0(ContainersDequeTest, PopFirst) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersDeque::InsertFront(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersDeque::InsertFront(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(ContainersDeque::PopFirst(callInfo.get()), JSTaggedValue(i)); + EXPECT_EQ(ContainersDeque::PopFirst(callInfo), JSTaggedValue(i)); } } @@ -238,10 +238,10 @@ HWTEST_F_L0(ContainersDequeTest, PopLast) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersDeque::InsertEnd(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersDeque::InsertEnd(callInfo); TestHelper::TearDownFrame(thread, prev); - EXPECT_EQ(ContainersDeque::PopLast(callInfo.get()), JSTaggedValue(i)); + EXPECT_EQ(ContainersDeque::PopLast(callInfo), JSTaggedValue(i)); } } @@ -255,8 +255,8 @@ HWTEST_F_L0(ContainersDequeTest, ForEach) callInfo->SetThis(deque.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersDeque::InsertEnd(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersDeque::InsertEnd(callInfo); TestHelper::TearDownFrame(thread, prev); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -270,8 +270,8 @@ HWTEST_F_L0(ContainersDequeTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersDeque::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersDeque::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } } diff --git a/ecmascript/containers/tests/containers_lightweightmap_test.cpp b/ecmascript/containers/tests/containers_lightweightmap_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..419854fa9783581c193c932d2188036b2750c871 --- /dev/null +++ b/ecmascript/containers/tests/containers_lightweightmap_test.cpp @@ -0,0 +1,562 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/containers/containers_private.h" +#include "ecmascript/containers/containers_lightweightmap.h" +#include "ecmascript/ecma_runtime_call_info.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/js_tagged_value-inl.h" +#include "ecmascript/js_thread.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda::ecmascript; +using namespace panda::ecmascript::containers; + +namespace panda::test { +class ContainersLightWeightMapTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; + + class TestClass : public base::BuiltinsBase { + public: + static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) + { + JSThread *thread = argv->GetThread(); + JSHandle value = GetCallArg(argv, 0); + JSHandle key = GetCallArg(argv, 1); + [[maybe_unused]] JSHandle map = GetCallArg(argv, 2); // 2 means the secode arg + + JSHandle jsTreeMap(GetThis(argv)); + JSAPILightWeightMap::Set(thread, jsTreeMap, key, value); + return JSTaggedValue::Undefined(); + } + }; +protected: + JSTaggedValue InitializeLightWeightMapConstructor() + { + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle globalObject = env->GetJSGlobalObject(); + JSHandle key(factory->NewFromASCII("ArkPrivate")); + JSHandle value = + JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); + auto objCallInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(value.GetTaggedValue()); + objCallInfo->SetCallArg( + 0, JSTaggedValue(static_cast(ContainerTag::LightWeightMap))); // 0 means the argument + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); + TestHelper::TearDownFrame(thread, prev); + + return result; + } + + JSHandle CreateJSAPILightWeightMap() + { + JSHandle newTarget(thread, InitializeLightWeightMapConstructor()); + auto objCallInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + objCallInfo->SetFunction(newTarget.GetTaggedValue()); + objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersLightWeightMap::LightWeightMapConstructor(objCallInfo); + TestHelper::TearDownFrame(thread, prev); + JSHandle map(thread, result); + return map; + } +}; + +HWTEST_F_L0(ContainersLightWeightMapTest, LightWeightMapConstructor) +{ + InitializeLightWeightMapConstructor(); + JSHandle newTarget(thread, InitializeLightWeightMapConstructor()); + + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + objCallInfo->SetFunction(newTarget.GetTaggedValue()); + objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersLightWeightMap::LightWeightMapConstructor(objCallInfo); + TestHelper::TearDownFrame(thread, prev); + + ASSERT_TRUE(result.IsJSAPILightWeightMap()); + JSHandle mapHandle(thread, result); + JSTaggedValue resultProto = JSTaggedValue::GetPrototype(thread, JSHandle(mapHandle)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + ASSERT_EQ(resultProto, funcProto); +} + +HWTEST_F_L0(ContainersLightWeightMapTest, SetAndGet) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle lightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i + 1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = lightWeightMap->GetLength(); + EXPECT_EQ(length, i + 1); + } + + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSMutableHandle key(thread, JSTaggedValue::Undefined()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + std::string myKey("mykey"); + std::string myValue("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ikey = myKey + std::to_string(i); + std::string ivalue = myValue + std::to_string(i); + key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); + value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, key.GetTaggedValue()); + callInfo->SetCallArg(1, value.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = lightWeightMap->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, NODE_NUMBERS + 1 + i); + } + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Get(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(result, JSTaggedValue(i + 1)); + } + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ikey = myKey + std::to_string(i); + std::string ivalue = myValue + std::to_string(i); + key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); + value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, key.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Get(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(result, value.GetTaggedValue()); + } +} + +HWTEST_F_L0(ContainersLightWeightMapTest, Remove) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle lightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i + 1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + EXPECT_EQ(result, JSTaggedValue::True()); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = lightWeightMap->GetLength(); + EXPECT_EQ(length, i + 1); + } + + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(NODE_NUMBERS / 2)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLightWeightMap::Remove(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(rvalue, JSTaggedValue(NODE_NUMBERS / 2 + 1)); + uint32_t len = lightWeightMap->GetLength(); + EXPECT_EQ(len, NODE_NUMBERS - 1); + } + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue keyResult = ContainersLightWeightMap::HasKey(callInfo); + TestHelper::TearDownFrame(thread, prev); + if (NODE_NUMBERS / 2 == i) { + EXPECT_EQ(keyResult, JSTaggedValue::False()); + } else { + EXPECT_EQ(keyResult, JSTaggedValue::True()); + } + + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i + 1)); + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightMap::HasValue(callInfo); + TestHelper::TearDownFrame(thread, prev); + if (NODE_NUMBERS / 2 == i) { + EXPECT_EQ(valueResult, JSTaggedValue::False()); + } else { + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } + } +} + +HWTEST_F_L0(ContainersLightWeightMapTest, Clear) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle lightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = lightWeightMap->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, i + 1); + } + + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersLightWeightMap::Clear(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t len = lightWeightMap->GetLength(); + uint32_t empty = 0; + EXPECT_EQ(len, empty); + } +} + +HWTEST_F_L0(ContainersLightWeightMapTest, ToString) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle lightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = lightWeightMap->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, i + 1); + } + + { + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue res = ContainersLightWeightMap::ToString(callInfo); + JSHandle resHandle(thread, res); + TestHelper::TearDownFrame(thread, prev); + std::string myString("0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7"); + JSHandle expectResHandle(thread, factory->NewFromStdString(myString).GetTaggedValue()); + EXPECT_TRUE(JSTaggedValue::Equal(thread, resHandle, expectResHandle)); + } +} + +// LightWeightMap.setAll(map) +HWTEST_F_L0(ContainersLightWeightMapTest, SetAll) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle oldLightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(oldLightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = oldLightWeightMap->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, i + 1); + } + + JSHandle LightWeightMap = CreateJSAPILightWeightMap(); + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(LightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, oldLightWeightMap.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersLightWeightMap::SetAll(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = LightWeightMap->GetLength(); + EXPECT_EQ(length, NODE_NUMBERS); + } + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(LightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue keyResult = ContainersLightWeightMap::HasKey(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(keyResult, JSTaggedValue::True()); + + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightMap::HasValue(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } +} + +HWTEST_F_L0(ContainersLightWeightMapTest, KeysAndValuesAndEntries) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle lightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t length = lightWeightMap->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, i + 1); + } + + JSMutableHandle result(thread, JSTaggedValue::Undefined()); + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSHandle iterKeys(thread, ContainersLightWeightMap::Keys(callInfo)); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(iterKeys->IsJSAPILightWeightMapIterator()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(iterKeys.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPILightWeightMapIterator::Next(callInfo)); + TestHelper::TearDownFrame(thread, prev); + JSHandle keyHandle = JSIterator::IteratorValue(thread, result); + + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, keyHandle.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue keyResult = ContainersLightWeightMap::HasKey(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(keyResult, JSTaggedValue::True()); + } + + // test values + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread, callInfo); + JSHandle iterValues(thread, ContainersLightWeightMap::Values(callInfo)); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(iterValues->IsJSAPILightWeightMapIterator()); + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(iterValues.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPILightWeightMapIterator::Next(callInfo)); + TestHelper::TearDownFrame(thread, prev); + JSHandle ValueHandle = JSIterator::IteratorValue(thread, result); + + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, ValueHandle.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightMap::HasValue(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } + // test entries + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread, callInfo); + JSHandle iter(thread, ContainersLightWeightMap::Entries(callInfo)); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(iter->IsJSAPILightWeightMapIterator()); + + JSHandle first(thread, JSTaggedValue(0)); + JSHandle second(thread, JSTaggedValue(1)); + JSMutableHandle entries(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(iter.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPILightWeightMapIterator::Next(callInfo)); + TestHelper::TearDownFrame(thread, prev); + entries.Update(JSIterator::IteratorValue(thread, result).GetTaggedValue()); + + int entriesKey = JSObject::GetProperty(thread, entries, first).GetValue()->GetInt(); + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(entriesKey)); + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue keyResult = ContainersLightWeightMap::HasKey(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(keyResult, JSTaggedValue::True()); + + int entriesValue = JSObject::GetProperty(thread, entries, second).GetValue()->GetInt(); + callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(entriesValue)); + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightMap::HasValue(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } +} + +// LightWeightMap.ForEach(callbackfn, this) +HWTEST_F_L0(ContainersLightWeightMapTest, ForEach) +{ + constexpr uint32_t NODE_NUMBERS = 8; + JSHandle lightWeightMap = CreateJSAPILightWeightMap(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + callInfo->SetCallArg(1, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::Set(callInfo); + TestHelper::TearDownFrame(thread, prev); + uint32_t len = lightWeightMap->GetLength(); + EXPECT_EQ(result, JSTaggedValue::True()); + EXPECT_EQ(len, i + 1); + } + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle newLightWeightMap = CreateJSAPILightWeightMap(); + { + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForEachFunc)); + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, func.GetTaggedValue()); + callInfo->SetCallArg(1, newLightWeightMap.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersLightWeightMap::ForEach(callInfo); + TestHelper::TearDownFrame(thread, prev); + } + EXPECT_EQ(newLightWeightMap->GetLength(), NODE_NUMBERS); + EXPECT_EQ(lightWeightMap->GetLength(), NODE_NUMBERS); + + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(newLightWeightMap.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightMap::HasKey(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(result, JSTaggedValue::True()); + } +} +} // namespace panda::test diff --git a/ecmascript/containers/tests/containers_lightweightset_test.cpp b/ecmascript/containers/tests/containers_lightweightset_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..195f62d8d873137471e9f17a1e8958ba5680c83d --- /dev/null +++ b/ecmascript/containers/tests/containers_lightweightset_test.cpp @@ -0,0 +1,538 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/containers/containers_lightweightset.h" +#include "ecmascript/containers/containers_private.h" +#include "ecmascript/ecma_runtime_call_info.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_api_lightweightset_iterator.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/js_tagged_value-inl.h" +#include "ecmascript/js_thread.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda::ecmascript; +using namespace panda::ecmascript::containers; + +namespace panda::test { +class ContainersLightWeightSetTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; + + class TestClass : public base::BuiltinsBase { + public: + static JSTaggedValue TestForEachFunc(EcmaRuntimeCallInfo *argv) + { + JSThread *thread = argv->GetThread(); + JSHandle value = GetCallArg(argv, 0); // 0 means the first argument vector + JSHandle jSAPILightWeightSet(GetThis(argv)); + JSAPILightWeightSet::Add(thread, jSAPILightWeightSet, value); + return JSTaggedValue::Undefined(); + } + }; +protected: + JSTaggedValue InitializeLightWeightSetConstructor() + { + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle globalObject = env->GetJSGlobalObject(); + JSHandle key(factory->NewFromASCII("ArkPrivate")); + JSHandle value = + JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); + auto objCallInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(value.GetTaggedValue()); + objCallInfo->SetCallArg( + 0, JSTaggedValue(static_cast(ContainerTag::LightWeightSet))); // 0 means the argument + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); + TestHelper::TearDownFrame(thread, prev); + + return result; + } + + JSHandle CreateJSAPILightWeightSet() + { + JSHandle newTarget(thread, InitializeLightWeightSetConstructor()); + auto objCallInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); // 4 means the value + objCallInfo->SetFunction(newTarget.GetTaggedValue()); + objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersLightWeightSet::LightWeightSetConstructor(objCallInfo); + TestHelper::TearDownFrame(thread, prev); + JSHandle map(thread, result); + return map; + } +}; + +HWTEST_F_L0(ContainersLightWeightSetTest, LightWeightSetConstructor) +{ + InitializeLightWeightSetConstructor(); + JSHandle newTarget(thread, InitializeLightWeightSetConstructor()); + auto objCallInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); // 4 means the value + objCallInfo->SetFunction(newTarget.GetTaggedValue()); + objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); + objCallInfo->SetThis(JSTaggedValue::Undefined()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersLightWeightSet::LightWeightSetConstructor(objCallInfo); + TestHelper::TearDownFrame(thread, prev); + + ASSERT_TRUE(result.IsJSAPILightWeightSet()); + JSHandle mapHandle(thread, result); + JSTaggedValue resultProto = JSObject::GetPrototype(JSHandle::Cast(mapHandle)); + JSTaggedValue funcProto = newTarget->GetFunctionPrototype(); + ASSERT_EQ(resultProto, funcProto); + int length = mapHandle->GetLength(); + ASSERT_EQ(length, 0); // 0 means the value +} + +HWTEST_F_L0(ContainersLightWeightSetTest, AddAndGetValueAt) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lightWeightSet = CreateJSAPILightWeightSet(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i + 1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_EQ(length, static_cast(i + 1)); + } + + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + std::string myValue("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ivalue = myValue + std::to_string(i); + value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, value.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, static_cast(NODE_NUMBERS + 1 + i)); + } +} + +HWTEST_F_L0(ContainersLightWeightSetTest, AddAll) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lightWeightSet = CreateJSAPILightWeightSet(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i + 1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_EQ(length, static_cast(i + 1)); + } + + JSHandle lws = CreateJSAPILightWeightSet(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lws.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i + 1 + 10)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + TestHelper::TearDownFrame(thread, prev); + int length = lws->GetLength(); + EXPECT_EQ(length, static_cast(i + 1)); + } + // test AddAll + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, lws.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::AddAll(callInfo); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_EQ(length, static_cast(NODE_NUMBERS * 2)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + } +} + +HWTEST_F_L0(ContainersLightWeightSetTest, HasAllAndHas) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lightWeightSet = CreateJSAPILightWeightSet(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i + 1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_EQ(length, static_cast(i + 1)); + } + + JSHandle lws = CreateJSAPILightWeightSet(); + for (uint32_t i = 3; i < NODE_NUMBERS - 2; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lws.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i + 1)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + TestHelper::TearDownFrame(thread, prev); + } + // test HasAll true + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, lws.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::HasAll(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + } + // test HasAll fales + JSHandle lwsFalse = CreateJSAPILightWeightSet(); + for (uint32_t i = 1; i < NODE_NUMBERS - 2; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lwsFalse.GetTaggedValue()); + + if (i == 2) { + callInfo->SetCallArg(0, JSTaggedValue(i + 1 + 10)); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + } else { + callInfo->SetCallArg(0, JSTaggedValue(i + 1)); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + } + } + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, lwsFalse.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::HasAll(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::False()))); + } + // test Has Value + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(3)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Has(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + } +} + +HWTEST_F_L0(ContainersLightWeightSetTest, Equal) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lightWeightSet = CreateJSAPILightWeightSet(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + std::string myValue("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ivalue = myValue + std::to_string(i); + value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, value.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, static_cast(1 + i)); + } + + JSHandle lws = CreateJSAPILightWeightSet(); + JSMutableHandle value1(thread, JSTaggedValue::Undefined()); + myValue = "myvalue"; + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ivalue = myValue + std::to_string(i); + value1.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lws.GetTaggedValue()); + callInfo->SetCallArg(0, value1.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + TestHelper::TearDownFrame(thread, prev); + int length = lws->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, static_cast(1 + i)); + } + // test equal + { + auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, lws.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::HasAll(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + } +} + +HWTEST_F_L0(ContainersLightWeightSetTest, HasAndValuesAndEntries) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lightWeightSet = CreateJSAPILightWeightSet(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 4 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + TestHelper::TearDownFrame(thread, prev); + int length = lightWeightSet->GetLength(); + EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), + JSHandle(thread, JSTaggedValue::True()))); + EXPECT_EQ(length, static_cast(i + 1)); + } + + JSMutableHandle result(thread, JSTaggedValue::Undefined()); + // test values + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); // 4 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSHandle iterValues(thread, ContainersLightWeightSet::Values(callInfo)); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(iterValues->IsJSAPILightWeightSetIterator()); + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); // 4 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(iterValues.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPILightWeightSetIterator::Next(callInfo)); + TestHelper::TearDownFrame(thread, prev); + JSHandle ValueHandle = JSIterator::IteratorValue(thread, result); + + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, ValueHandle.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightSet::Has(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } + // test entries + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); // 4 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + prev = TestHelper::SetupFrame(thread, callInfo); + JSHandle iter(thread, ContainersLightWeightSet::Entries(callInfo)); + TestHelper::TearDownFrame(thread, prev); + EXPECT_TRUE(iter->IsJSAPILightWeightSetIterator()); + + JSHandle first(thread, JSTaggedValue(0)); // 0 means the value + JSHandle second(thread, JSTaggedValue(1)); // 1 means the value + JSMutableHandle entries(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); // 4 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(iter.GetTaggedValue()); + + prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPILightWeightSetIterator::Next(callInfo)); + TestHelper::TearDownFrame(thread, prev); + entries.Update(JSIterator::IteratorValue(thread, result).GetTaggedValue()); + + int entriesKey = JSObject::GetProperty(thread, entries, first).GetValue()->GetInt(); + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(entriesKey)); + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue keyResult = ContainersLightWeightSet::HasHash(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(keyResult, JSTaggedValue::True()); + + int entriesValue = JSObject::GetProperty(thread, entries, second).GetValue()->GetInt(); + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(entriesValue)); + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightSet::Has(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } +} + +HWTEST_F_L0(ContainersLightWeightSetTest, ForEach) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lightWeightSet = CreateJSAPILightWeightSet(); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); // 8 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::Add(callInfo); + TestHelper::TearDownFrame(thread, prev); + int len = lightWeightSet->GetLength(); + EXPECT_EQ(result, JSTaggedValue::True()); + EXPECT_EQ(len, static_cast(i + 1)); + } + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle newLightWeightSet = CreateJSAPILightWeightSet(); + { + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle func = factory->NewJSFunction(env, reinterpret_cast(TestClass::TestForEachFunc)); + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 8); // 8 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, func.GetTaggedValue()); + callInfo->SetCallArg(1, newLightWeightSet.GetTaggedValue()); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersLightWeightSet::ForEach(callInfo); + TestHelper::TearDownFrame(thread, prev); + } + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + auto callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, JSTaggedValue(i)); + + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLightWeightSet::GetValueAt(callInfo); + TestHelper::TearDownFrame(thread, prev); + + callInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 6 means the value + callInfo->SetFunction(JSTaggedValue::Undefined()); + callInfo->SetThis(lightWeightSet.GetTaggedValue()); + callInfo->SetCallArg(0, result); + + prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue valueResult = ContainersLightWeightSet::Has(callInfo); + TestHelper::TearDownFrame(thread, prev); + EXPECT_EQ(valueResult, JSTaggedValue::True()); + } +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/containers/tests/containers_linked_list_test.cpp b/ecmascript/containers/tests/containers_linked_list_test.cpp index 0bc05130b7439b0bce2f4296a2620b671c3cac5a..f412a9f65d93e703a1df4dd753a31d563269d8b8 100644 --- a/ecmascript/containers/tests/containers_linked_list_test.cpp +++ b/ecmascript/containers/tests/containers_linked_list_test.cpp @@ -87,8 +87,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::LinkedList))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -104,8 +104,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersLinkedList::LinkedListConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersLinkedList::LinkedListConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle linkedlist(thread, result); return linkedlist; @@ -122,8 +122,8 @@ HWTEST_F_L0(ContainersLinkedListTest, LinkedListConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersLinkedList::LinkedListConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersLinkedList::LinkedListConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPILinkedList()); @@ -146,8 +146,8 @@ HWTEST_F_L0(ContainersLinkedListTest, InsertAndGet) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -159,8 +159,8 @@ HWTEST_F_L0(ContainersLinkedListTest, InsertAndGet) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -177,8 +177,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Remove) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -190,8 +190,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Remove) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(NODE_NUMBERS / 2)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersLinkedList::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLinkedList::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); @@ -203,8 +203,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Remove) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(6)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersLinkedList::RemoveByIndex(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLinkedList::RemoveByIndex(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(6)); EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 2)); @@ -222,8 +222,8 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -234,8 +234,8 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(linkedlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersLinkedList::RemoveFirst(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLinkedList::RemoveFirst(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(0)); EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); @@ -247,8 +247,8 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveFirst) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(15)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersLinkedList::RemoveFirstFound(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLinkedList::RemoveFirstFound(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 2)); @@ -266,8 +266,8 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveLast) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -278,8 +278,8 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveLast) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(linkedlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersLinkedList::RemoveLast(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLinkedList::RemoveLast(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(19)); EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 1)); @@ -291,8 +291,8 @@ HWTEST_F_L0(ContainersLinkedListTest, RemoveLast) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(8)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersLinkedList::RemoveLastFound(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersLinkedList::RemoveLastFound(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(NODE_NUMBERS - 2)); @@ -309,8 +309,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Clear) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -321,8 +321,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Clear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(linkedlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersLinkedList::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersLinkedList::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(linkedlist->Length(), 0); } @@ -339,8 +339,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Clone) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedList->Length(), static_cast(i + 1)); @@ -351,15 +351,15 @@ HWTEST_F_L0(ContainersLinkedListTest, Clone) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(linkedList.GetTaggedValue()); - JSTaggedValue newlinkedList = ContainersLinkedList::Clone(callInfo1.get()); + JSTaggedValue newlinkedList = ContainersLinkedList::Clone(callInfo1); for (uint32_t i = 0; i < NODE_NUMBERS; i++) { auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(newlinkedList); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -376,8 +376,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Values) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -387,8 +387,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Values) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(linkedlist.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterValues(thread, ContainersLinkedList::GetIteratorObj(callInfo1.get())); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterValues(thread, ContainersLinkedList::GetIteratorObj(callInfo1)); TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(iterValues->IsJSAPILinkedListIterator()); @@ -398,8 +398,8 @@ HWTEST_F_L0(ContainersLinkedListTest, Values) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPILinkedListIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPILinkedListIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(static_cast(i), JSIterator::IteratorValue(thread, result)->GetInt()); } @@ -416,8 +416,8 @@ HWTEST_F_L0(ContainersLinkedListTest, ForEach) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(linkedlist->Length(), static_cast(i + 1)); @@ -433,8 +433,8 @@ HWTEST_F_L0(ContainersLinkedListTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, newLinkedlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersLinkedList::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersLinkedList::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -444,8 +444,8 @@ HWTEST_F_L0(ContainersLinkedListTest, ForEach) callInfo->SetThis(linkedlist.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersLinkedList::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersLinkedList::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i * 2)); } diff --git a/ecmascript/containers/tests/containers_list_test.cpp b/ecmascript/containers/tests/containers_list_test.cpp index e6ebce0211c701448493d9e47429c8d7cba0dda0..99bda9f1460c8864f0a94508d04232e027d7fda7 100644 --- a/ecmascript/containers/tests/containers_list_test.cpp +++ b/ecmascript/containers/tests/containers_list_test.cpp @@ -87,8 +87,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::List))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -104,8 +104,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersList::ListConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersList::ListConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle list(thread, result); return list; @@ -122,8 +122,8 @@ HWTEST_F_L0(ContainersListTest, ListConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersList::ListConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersList::ListConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIList()); @@ -146,8 +146,8 @@ HWTEST_F_L0(ContainersListTest, InsertAndGet) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -160,8 +160,8 @@ HWTEST_F_L0(ContainersListTest, InsertAndGet) callInfo->SetCallArg(0, JSTaggedValue(20)); callInfo->SetCallArg(1, JSTaggedValue(20)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::Exception()); } @@ -172,8 +172,8 @@ HWTEST_F_L0(ContainersListTest, InsertAndGet) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -190,8 +190,8 @@ HWTEST_F_L0(ContainersListTest, Remove) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -203,8 +203,8 @@ HWTEST_F_L0(ContainersListTest, Remove) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(NODE_NUMBERS / 2)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersList::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersList::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(NODE_NUMBERS - 1)); @@ -216,8 +216,8 @@ HWTEST_F_L0(ContainersListTest, Remove) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(6)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersList::RemoveByIndex(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersList::RemoveByIndex(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(6)); EXPECT_EQ(list->Length(), static_cast(NODE_NUMBERS - 2)); @@ -234,8 +234,8 @@ HWTEST_F_L0(ContainersListTest, Equal) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -248,8 +248,8 @@ HWTEST_F_L0(ContainersListTest, Equal) callInfo->SetThis(list1.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list1->Length(), static_cast(i + 1)); @@ -261,8 +261,8 @@ HWTEST_F_L0(ContainersListTest, Equal) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, list1.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue res = ContainersList::Equal(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue res = ContainersList::Equal(callInfo); EXPECT_EQ(res, JSTaggedValue::True()); TestHelper::TearDownFrame(thread, prev); } @@ -278,8 +278,8 @@ HWTEST_F_L0(ContainersListTest, GetSubList) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -291,8 +291,8 @@ HWTEST_F_L0(ContainersListTest, GetSubList) callInfo1->SetThis(list.GetTaggedValue()); callInfo1->SetCallArg(0, JSTaggedValue(2)); callInfo1->SetCallArg(1, JSTaggedValue(5)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSTaggedValue newList = ContainersList::GetSubList(callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSTaggedValue newList = ContainersList::GetSubList(callInfo1); TestHelper::TearDownFrame(thread, prev1); EXPECT_EQ(list->Length(), 10); for (uint32_t i = 0; i < 3; i++) { @@ -301,8 +301,8 @@ HWTEST_F_L0(ContainersListTest, GetSubList) callInfo->SetThis(newList); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i + 2)); } @@ -321,8 +321,8 @@ HWTEST_F_L0(ContainersListTest, ConvertToArray) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); oldArray->Set(thread, i, JSTaggedValue(i)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); @@ -333,8 +333,8 @@ HWTEST_F_L0(ContainersListTest, ConvertToArray) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(list.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue newArray = ContainersList::ConvertToArray(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue newArray = ContainersList::ConvertToArray(callInfo); TestHelper::TearDownFrame(thread, prev); JSTaggedValue newArrayValue = JSTaggedValue::ToObject(thread, JSHandle(thread, newArray))->GetElements(); @@ -355,8 +355,8 @@ HWTEST_F_L0(ContainersListTest, Clear) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -367,8 +367,8 @@ HWTEST_F_L0(ContainersListTest, Clear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(list.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersList::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersList::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(list->Length(), 0); } @@ -385,8 +385,8 @@ HWTEST_F_L0(ContainersListTest, Values) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -395,8 +395,8 @@ HWTEST_F_L0(ContainersListTest, Values) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(list.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterValues(thread, ContainersList::GetIteratorObj(callInfo1.get())); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterValues(thread, ContainersList::GetIteratorObj(callInfo1)); TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(iterValues->IsJSAPIListIterator()); @@ -406,8 +406,8 @@ HWTEST_F_L0(ContainersListTest, Values) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPIListIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPIListIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(i, JSIterator::IteratorValue(thread, result)->GetInt()); } @@ -424,8 +424,8 @@ HWTEST_F_L0(ContainersListTest, ForEach) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(list->Length(), static_cast(i + 1)); @@ -441,8 +441,8 @@ HWTEST_F_L0(ContainersListTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersList::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersList::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -452,8 +452,8 @@ HWTEST_F_L0(ContainersListTest, ForEach) callInfo->SetThis(list.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersList::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersList::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i * 2)); } diff --git a/ecmascript/containers/tests/containers_plainarray_test.cpp b/ecmascript/containers/tests/containers_plainarray_test.cpp index 7e7bfe9161b297dff1ebf054ad258543680d235d..bb46a7e31091605a0e2e38cff7666e621f431f70 100644 --- a/ecmascript/containers/tests/containers_plainarray_test.cpp +++ b/ecmascript/containers/tests/containers_plainarray_test.cpp @@ -87,8 +87,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::PlainArray))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -103,8 +103,8 @@ protected: objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPlainArray::PlainArrayConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPlainArray::PlainArrayConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle plain(thread, result); return plain; @@ -121,8 +121,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, PlainArrayConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPlainArray::PlainArrayConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPlainArray::PlainArrayConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIPlainArray()); @@ -147,8 +147,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, AddAndHas) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i + 1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tArray1->GetSize(), static_cast(i + 1)); @@ -162,8 +162,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, AddAndHas) callInfo->SetThis(tArray1.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -186,8 +186,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, AddAndHas) callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -204,8 +204,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, AddAndHas) callInfo->SetThis(tArray.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::Equal(thread, JSHandle(thread, result), value)); } @@ -223,8 +223,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, Iterator) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i + 1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(array->GetSize(), static_cast(i + 1)); @@ -234,8 +234,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, Iterator) auto callInf = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInf->SetFunction(JSTaggedValue::Undefined()); callInf->SetThis(array.GetTaggedValue()); - [[maybe_unused]] auto pre = TestHelper::SetupFrame(thread, callInf.get()); - JSHandle iter(thread, ContainersPlainArray::GetIteratorObj(callInf.get())); + [[maybe_unused]] auto pre = TestHelper::SetupFrame(thread, callInf); + JSHandle iter(thread, ContainersPlainArray::GetIteratorObj(callInf)); TestHelper::TearDownFrame(thread, pre); EXPECT_TRUE(iter->IsJSAPIPlainArrayIterator()); @@ -248,8 +248,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, Iterator) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPIPlainArrayIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPIPlainArrayIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); entries.Update(JSIterator::IteratorValue(thread, result).GetTaggedValue()); EXPECT_EQ(static_cast(i), JSObject::GetProperty(thread, entries, first).GetValue()->GetInt()); @@ -270,8 +270,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, Iterator) callInfo->SetCallArg(0, JSTaggedValue(100 + i)); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(array->GetSize(), static_cast(NODE_NUMBERS + i + 1)); @@ -291,8 +291,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, GetIndexOfKeyAndGetIndexOfValue) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i + 1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(pArray->GetSize(), static_cast(i + 1)); @@ -305,8 +305,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, GetIndexOfKeyAndGetIndexOfValue) callInfo->SetThis(pArray.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(2)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::GetIndexOfKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::GetIndexOfKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(2)); } @@ -318,8 +318,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, GetIndexOfKeyAndGetIndexOfValue) callInfo->SetThis(pArray.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(4)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::GetIndexOfValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::GetIndexOfValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(3)); } @@ -337,8 +337,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, GetIndexOfKeyAndGetIndexOfValue) callInfo->SetCallArg(0, JSTaggedValue(100 + i)); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(pArray->GetSize(), static_cast(NODE_NUMBERS + i + 1)); @@ -352,8 +352,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, GetIndexOfKeyAndGetIndexOfValue) callInfo->SetThis(pArray.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(102)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::GetIndexOfKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::GetIndexOfKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(10)); } @@ -367,8 +367,8 @@ HWTEST_F_L0(ContainersPlainArrayTest, GetIndexOfKeyAndGetIndexOfValue) callInfo->SetThis(pArray.GetTaggedValue()); callInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersPlainArray::GetIndexOfValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersPlainArray::GetIndexOfValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(11)); } diff --git a/ecmascript/containers/tests/containers_stack_test.cpp b/ecmascript/containers/tests/containers_stack_test.cpp index 2247de20ed4cc524865a5c8cd06872706daf4c85..c2074843bc7785c89dadb2e9363e958649ba2e4e 100644 --- a/ecmascript/containers/tests/containers_stack_test.cpp +++ b/ecmascript/containers/tests/containers_stack_test.cpp @@ -88,8 +88,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::Stack))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -105,8 +105,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersStack::StackConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersStack::StackConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle stack(thread, result); return stack; @@ -123,8 +123,8 @@ HWTEST_F_L0(ContainersStackTest, StackConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersStack::StackConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersStack::StackConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIStack()); @@ -144,11 +144,11 @@ HWTEST_F_L0(ContainersStackTest, PushAndPeek) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersStack::Push(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersStack::Push(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); - EXPECT_EQ(ContainersStack::Peek(callInfo.get()), JSTaggedValue(i)); + EXPECT_EQ(ContainersStack::Peek(callInfo), JSTaggedValue(i)); } } @@ -162,8 +162,8 @@ HWTEST_F_L0(ContainersStackTest, Pop) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersStack::Push(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersStack::Push(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -174,8 +174,8 @@ HWTEST_F_L0(ContainersStackTest, Pop) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersStack::Pop(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersStack::Pop(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(num--)); } @@ -191,10 +191,10 @@ HWTEST_F_L0(ContainersStackTest, IsEmpty) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersStack::Push(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersStack::Push(callInfo); TestHelper::TearDownFrame(thread, prev); - JSTaggedValue result = ContainersStack::IsEmpty(callInfo.get()); + JSTaggedValue result = ContainersStack::IsEmpty(callInfo); EXPECT_EQ(result, JSTaggedValue::False()); } @@ -205,12 +205,12 @@ HWTEST_F_L0(ContainersStackTest, IsEmpty) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersStack::Pop(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersStack::Pop(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(num--)); if (num == -1) { - JSTaggedValue consequence = ContainersStack::IsEmpty(callInfo.get()); + JSTaggedValue consequence = ContainersStack::IsEmpty(callInfo); EXPECT_EQ(consequence, JSTaggedValue::True()); } } @@ -226,9 +226,9 @@ HWTEST_F_L0(ContainersStackTest, Locate) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersStack::Push(callInfo.get()); - JSTaggedValue result = ContainersStack::Locate(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersStack::Push(callInfo); + JSTaggedValue result = ContainersStack::Locate(callInfo); EXPECT_EQ(result, JSTaggedValue(i)); TestHelper::TearDownFrame(thread, prev); } @@ -244,8 +244,8 @@ HWTEST_F_L0(ContainersStackTest, ForEach) callInfo->SetThis(stack.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersStack::Push(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersStack::Push(callInfo); TestHelper::TearDownFrame(thread, prev); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -259,8 +259,8 @@ HWTEST_F_L0(ContainersStackTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dlist.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersStack::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersStack::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } } diff --git a/ecmascript/containers/tests/containers_treemap_test.cpp b/ecmascript/containers/tests/containers_treemap_test.cpp index a79193fe54fcde144be4dca82cbdea60341c1362..cd46442afdeda249d38a58986c51323d0a350a00 100644 --- a/ecmascript/containers/tests/containers_treemap_test.cpp +++ b/ecmascript/containers/tests/containers_treemap_test.cpp @@ -126,8 +126,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::TreeMap))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -143,8 +143,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersTreeMap::TreeMapConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersTreeMap::TreeMapConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle map(thread, result); return map; @@ -163,8 +163,8 @@ HWTEST_F_L0(ContainersTreeMapTest, TreeMapConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersTreeMap::TreeMapConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersTreeMap::TreeMapConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPITreeMap()); @@ -188,8 +188,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAndGet) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -212,8 +212,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAndGet) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -225,8 +225,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAndGet) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -241,8 +241,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAndGet) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, value.GetTaggedValue()); } @@ -261,8 +261,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -274,8 +274,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersTreeMap::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersTreeMap::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(rvalue, JSTaggedValue(i)); } @@ -287,8 +287,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); if (i < REMOVE_SIZE) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -314,8 +314,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS - REMOVE_SIZE + i + 1); @@ -331,8 +331,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Remove) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersTreeMap::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersTreeMap::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(rvalue, value.GetTaggedValue())); } @@ -351,8 +351,8 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -366,8 +366,8 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::HasKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::HasKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); } @@ -378,8 +378,8 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::HasValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::HasValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); } @@ -402,8 +402,8 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -419,8 +419,8 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::HasKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::HasKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); } @@ -433,8 +433,8 @@ HWTEST_F_L0(ContainersTreeMapTest, HasKeyAndHasValue) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::HasValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::HasValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); } @@ -453,8 +453,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -465,8 +465,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetFirstKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetFirstKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); } @@ -476,8 +476,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetLastKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetLastKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS - 1)); } @@ -499,8 +499,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -512,8 +512,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetFirstKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetFirstKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); } @@ -525,8 +525,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetFirstKeyAndGetLastKey) auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetLastKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetLastKey(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, key.GetTaggedValue()); } @@ -544,8 +544,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -557,8 +557,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(tmap->GetSize(), 0); } @@ -568,8 +568,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::Undefined()); } @@ -591,8 +591,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -604,8 +604,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(tmap->GetSize(), 0); } @@ -617,8 +617,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Clear) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::Undefined()); } @@ -636,8 +636,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -650,8 +650,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, smap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::SetAll(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::SetAll(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(dmap->GetSize(), NODE_NUMBERS); } @@ -661,8 +661,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -684,8 +684,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) callInfo->SetThis(smap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -696,8 +696,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, smap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::SetAll(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::SetAll(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(dmap->GetSize(), NODE_NUMBERS * 2); } @@ -711,8 +711,8 @@ HWTEST_F_L0(ContainersTreeMapTest, SetAll) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); } @@ -731,8 +731,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -745,8 +745,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetLowerKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetLowerKey(callInfo); TestHelper::TearDownFrame(thread, prev); if (i == 0) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -761,8 +761,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetHigherKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetHigherKey(callInfo); TestHelper::TearDownFrame(thread, prev); if (i >= NODE_NUMBERS - 1) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -788,8 +788,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -807,8 +807,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetLowerKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetLowerKey(callInfo); TestHelper::TearDownFrame(thread, prev); if (i == 0) { EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS - 1)); @@ -828,8 +828,8 @@ HWTEST_F_L0(ContainersTreeMapTest, GetLowerKeyAndGetHigherKey) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::GetHigherKey(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::GetHigherKey(callInfo); TestHelper::TearDownFrame(thread, prev); if (i >= NODE_NUMBERS - 1) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -851,8 +851,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -862,8 +862,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterKeys(thread, ContainersTreeMap::Keys(callInfo1.get())); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterKeys(thread, ContainersTreeMap::Keys(callInfo1)); TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(iterKeys->IsJSAPITreeMapIterator()); @@ -873,8 +873,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterKeys.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(i, JSIterator::IteratorValue(thread, result)->GetInt()); } @@ -883,8 +883,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(tmap.GetTaggedValue()); - auto prev2 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterValues(thread, ContainersTreeMap::Values(callInfo1.get())); + auto prev2 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterValues(thread, ContainersTreeMap::Values(callInfo1)); TestHelper::TearDownFrame(thread, prev2); EXPECT_TRUE(iterValues->IsJSAPITreeMapIterator()); @@ -893,8 +893,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(i, JSIterator::IteratorValue(thread, result)->GetInt()); } @@ -916,8 +916,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result1 = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result1 = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result1.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result1.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -931,8 +931,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterKeys.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); @@ -946,8 +946,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(value, JSIterator::IteratorValue(thread, result))); } @@ -957,8 +957,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) auto callInfo3 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo3->SetFunction(JSTaggedValue::Undefined()); callInfo3->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev3 = TestHelper::SetupFrame(thread, callInfo3.get()); - JSHandle iter(thread, ContainersTreeMap::Entries(callInfo3.get())); + [[maybe_unused]] auto prev3 = TestHelper::SetupFrame(thread, callInfo3); + JSHandle iter(thread, ContainersTreeMap::Entries(callInfo3)); TestHelper::TearDownFrame(thread, prev3); EXPECT_TRUE(iter->IsJSAPITreeMapIterator()); @@ -971,8 +971,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result1.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result1.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); entries.Update(JSIterator::IteratorValue(thread, result1).GetTaggedValue()); EXPECT_EQ(i, JSObject::GetProperty(thread, entries, first).GetValue()->GetInt()); @@ -989,8 +989,8 @@ HWTEST_F_L0(ContainersTreeMapTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); entries.Update(JSIterator::IteratorValue(thread, result).GetTaggedValue()); EXPECT_TRUE(JSTaggedValue::SameValue(key, JSObject::GetProperty(thread, entries, first).GetValue())); @@ -1011,8 +1011,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -1025,8 +1025,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) callInfo->SetCallArg(0, JSTaggedValue(NODE_NUMBERS / 2)); callInfo->SetCallArg(1, JSTaggedValue(NODE_NUMBERS)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Replace(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Replace(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS); @@ -1037,8 +1037,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); if (i == (NODE_NUMBERS / 2)) { EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS)); @@ -1064,8 +1064,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -1082,8 +1082,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Replace(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Replace(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue::True()); EXPECT_EQ(tmap->GetSize(), NODE_NUMBERS * 2); @@ -1103,8 +1103,8 @@ HWTEST_F_L0(ContainersTreeMapTest, Replace) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(result, value.GetTaggedValue())); } @@ -1122,8 +1122,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -1140,8 +1140,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -1152,8 +1152,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i * 2)); } @@ -1164,8 +1164,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -1186,8 +1186,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -1203,8 +1203,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -1215,8 +1215,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i * 4)); // 4 means 4 times } @@ -1227,8 +1227,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i * 2)); } @@ -1244,8 +1244,8 @@ HWTEST_F_L0(ContainersTreeMapTest, ForEach) callInfo->SetThis(dmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Get(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Get(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, value.GetTaggedValue()); } @@ -1264,8 +1264,8 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); @@ -1286,8 +1286,8 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) callInfo->SetThis(tmap.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); callInfo->SetCallArg(1, value.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), NODE_NUMBERS + i + 1); @@ -1297,8 +1297,8 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterKeys(thread, ContainersTreeMap::Keys(callInfo1.get())); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterKeys(thread, ContainersTreeMap::Keys(callInfo1)); TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(iterKeys->IsJSAPITreeMapIterator()); @@ -1310,8 +1310,8 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterKeys.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); @@ -1321,8 +1321,8 @@ HWTEST_F_L0(ContainersTreeMapTest, CustomCompareFunctionTest) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterKeys.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeMapIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeMapIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ((NODE_NUMBERS - 1 - i), JSIterator::IteratorValue(thread, result)->GetInt()); } @@ -1340,12 +1340,12 @@ HWTEST_F_L0(ContainersTreeMapTest, IsEmpty) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeMap::Set(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeMap::Set(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsJSAPITreeMap()); EXPECT_EQ(JSAPITreeMap::Cast(result.GetTaggedObject())->GetSize(), i + 1); - JSTaggedValue isEmpty = ContainersTreeMap::IsEmpty(callInfo.get()); + JSTaggedValue isEmpty = ContainersTreeMap::IsEmpty(callInfo); EXPECT_EQ(isEmpty, JSTaggedValue::False()); } @@ -1355,10 +1355,10 @@ HWTEST_F_L0(ContainersTreeMapTest, IsEmpty) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tmap.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeMap::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeMap::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); - JSTaggedValue isEmpty = ContainersTreeMap::IsEmpty(callInfo.get()); + JSTaggedValue isEmpty = ContainersTreeMap::IsEmpty(callInfo); EXPECT_EQ(isEmpty, JSTaggedValue::True()); } } diff --git a/ecmascript/containers/tests/containers_treeset_test.cpp b/ecmascript/containers/tests/containers_treeset_test.cpp index ec5837494f3f7a5028a636f48b0299c3b7256842..14f87fe267348c6dcf02f720e971624a18a802b6 100644 --- a/ecmascript/containers/tests/containers_treeset_test.cpp +++ b/ecmascript/containers/tests/containers_treeset_test.cpp @@ -123,8 +123,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::TreeSet))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -140,8 +140,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersTreeSet::TreeSetConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersTreeSet::TreeSetConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle set(thread, result); return set; @@ -160,8 +160,8 @@ HWTEST_F_L0(ContainersTreeSetTest, TreeSetConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersTreeSet::TreeSetConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersTreeSet::TreeSetConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPITreeSet()); @@ -184,8 +184,8 @@ HWTEST_F_L0(ContainersTreeSetTest, AddAndHas) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -205,8 +205,8 @@ HWTEST_F_L0(ContainersTreeSetTest, AddAndHas) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); @@ -219,8 +219,8 @@ HWTEST_F_L0(ContainersTreeSetTest, AddAndHas) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -233,8 +233,8 @@ HWTEST_F_L0(ContainersTreeSetTest, AddAndHas) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -252,8 +252,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -265,8 +265,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersTreeSet::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersTreeSet::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(rvalue.IsTrue()); } @@ -278,8 +278,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); if (i < REMOVE_SIZE) { EXPECT_TRUE(result.IsFalse()); @@ -301,8 +301,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - REMOVE_SIZE + i + 1); @@ -318,8 +318,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue rvalue = ContainersTreeSet::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue rvalue = ContainersTreeSet::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(rvalue.IsTrue()); } @@ -333,8 +333,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Remove) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); if (i < REMOVE_SIZE) { EXPECT_TRUE(result.IsFalse()); @@ -355,8 +355,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -367,8 +367,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetFirstValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetFirstValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); } @@ -378,8 +378,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetLastValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetLastValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS - 1)); } @@ -397,8 +397,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); @@ -411,8 +411,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetFirstValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetFirstValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); } @@ -425,8 +425,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetFirstValueAndGetLastValue) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetLastValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetLastValue(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, key.GetTaggedValue()); } @@ -443,8 +443,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -455,8 +455,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeSet::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeSet::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(tset->GetSize(), 0); } @@ -466,8 +466,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsFalse()); } @@ -485,8 +485,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -498,8 +498,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeSet::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeSet::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(tset->GetSize(), 0); } @@ -512,8 +512,8 @@ HWTEST_F_L0(ContainersTreeSetTest, Clear) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsFalse()); } @@ -530,8 +530,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -544,8 +544,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetLowerValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetLowerValue(callInfo); TestHelper::TearDownFrame(thread, prev); if (i == 0) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -560,8 +560,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetHigherValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetHigherValue(callInfo); TestHelper::TearDownFrame(thread, prev); if (i >= NODE_NUMBERS - 1) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -583,8 +583,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); @@ -605,8 +605,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetLowerValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetLowerValue(callInfo); TestHelper::TearDownFrame(thread, prev); if (i == 0) { EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS - 1)); @@ -626,8 +626,8 @@ HWTEST_F_L0(ContainersTreeSetTest, GetLowerValueAndGetHigherValue) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::GetHigherValue(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::GetHigherValue(callInfo); TestHelper::TearDownFrame(thread, prev); if (i == NODE_NUMBERS - 1) { EXPECT_EQ(result, JSTaggedValue::Undefined()); @@ -648,8 +648,8 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -661,8 +661,8 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::PopFirst(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::PopFirst(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - 1); @@ -673,8 +673,8 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::PopLast(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::PopLast(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(NODE_NUMBERS - 1)); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS - 2); // 2 means two elements @@ -693,8 +693,8 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i - 1); @@ -707,8 +707,8 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::PopFirst(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::PopFirst(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(1)); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2 - 3); // 3 means three elements @@ -722,8 +722,8 @@ HWTEST_F_L0(ContainersTreeSetTest, PopFirstAndPopLast) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::PopLast(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::PopLast(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, key.GetTaggedValue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS * 2 - 4); // 4 means four elements @@ -741,8 +741,8 @@ HWTEST_F_L0(ContainersTreeSetTest, IsEmpty) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::IsEmpty(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::IsEmpty(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), 0); @@ -755,8 +755,8 @@ HWTEST_F_L0(ContainersTreeSetTest, IsEmpty) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -767,8 +767,8 @@ HWTEST_F_L0(ContainersTreeSetTest, IsEmpty) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::IsEmpty(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::IsEmpty(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsFalse()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS); @@ -786,8 +786,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -797,8 +797,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterValues(thread, ContainersTreeSet::Values(callInfo1.get())); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterValues(thread, ContainersTreeSet::Values(callInfo1)); TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(iterValues->IsJSAPITreeSetIterator()); { @@ -808,8 +808,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeSetIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(i, JSIterator::IteratorValue(thread, result)->GetInt()); } @@ -827,8 +827,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); @@ -844,8 +844,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeSetIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); @@ -856,8 +856,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) auto callInfo2 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo2->SetFunction(JSTaggedValue::Undefined()); callInfo2->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread, callInfo2.get()); - JSHandle iter(thread, ContainersTreeSet::Entries(callInfo2.get())); + [[maybe_unused]] auto prev2 = TestHelper::SetupFrame(thread, callInfo2); + JSHandle iter(thread, ContainersTreeSet::Entries(callInfo2)); TestHelper::TearDownFrame(thread, prev2); EXPECT_TRUE(iter->IsJSAPITreeSetIterator()); @@ -870,8 +870,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeSetIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); entries.Update(JSIterator::IteratorValue(thread, result).GetTaggedValue()); EXPECT_EQ(i, JSObject::GetProperty(thread, entries, first).GetValue()->GetInt()); @@ -885,8 +885,8 @@ HWTEST_F_L0(ContainersTreeSetTest, KeysAndValuesAndEntries) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iter.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeSetIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); entries.Update(JSIterator::IteratorValue(thread, result).GetTaggedValue()); EXPECT_TRUE(JSTaggedValue::SameValue(key, JSObject::GetProperty(thread, entries, first).GetValue())); @@ -906,8 +906,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -925,8 +925,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeSet::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeSet::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } @@ -938,8 +938,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) callInfo->SetThis(dset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -956,8 +956,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS / 2 + i + 1); @@ -972,8 +972,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, dset.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersTreeSet::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersTreeSet::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); } EXPECT_EQ(dset->GetSize(), NODE_NUMBERS + 2); @@ -987,8 +987,8 @@ HWTEST_F_L0(ContainersTreeSetTest, ForEach) callInfo->SetThis(dset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -1007,8 +1007,8 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), i + 1); @@ -1027,8 +1027,8 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) callInfo->SetThis(tset.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersTreeSet::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersTreeSet::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(tset->GetSize(), NODE_NUMBERS + i + 1); @@ -1039,8 +1039,8 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(tset.GetTaggedValue()); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSHandle iterValues(thread, ContainersTreeSet::Values(callInfo1.get())); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSHandle iterValues(thread, ContainersTreeSet::Values(callInfo1)); TestHelper::TearDownFrame(thread, prev1); EXPECT_TRUE(iterValues->IsJSAPITreeSetIterator()); JSMutableHandle result(thread, JSTaggedValue::Undefined()); @@ -1052,8 +1052,8 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeSetIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); JSHandle itRes = JSIterator::IteratorValue(thread, result); EXPECT_TRUE(JSTaggedValue::SameValue(key, itRes)); @@ -1063,8 +1063,8 @@ HWTEST_F_L0(ContainersTreeSetTest, CustomCompareFunctionTest) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(iterValues.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - result.Update(JSAPITreeSetIterator::Next(callInfo.get())); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + result.Update(JSAPITreeSetIterator::Next(callInfo)); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ((NODE_NUMBERS - 1 - i), JSIterator::IteratorValue(thread, result)->GetInt()); } diff --git a/ecmascript/containers/tests/containers_vector_test.cpp b/ecmascript/containers/tests/containers_vector_test.cpp index b0a4901239a321ce0a051a4043d7b97ac1a5e7e2..12b352d7b94482443e1d6cb8f2b528274a1a2880 100644 --- a/ecmascript/containers/tests/containers_vector_test.cpp +++ b/ecmascript/containers/tests/containers_vector_test.cpp @@ -105,8 +105,8 @@ protected: objCallInfo->SetFunction(JSTaggedValue::Undefined()); objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(ContainerTag::Vector))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); return result; @@ -122,8 +122,8 @@ protected: objCallInfo->SetThis(JSTaggedValue::Undefined()); objCallInfo->SetCallArg(0, compareHandle.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersVector::VectorConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersVector::VectorConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle vector(thread, result); return vector; @@ -142,8 +142,8 @@ HWTEST_F_L0(ContainersVectorTest, VectorConstructor) objCallInfo->SetNewTarget(newTarget.GetTaggedValue()); objCallInfo->SetThis(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = ContainersVector::VectorConstructor(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = ContainersVector::VectorConstructor(objCallInfo); TestHelper::TearDownFrame(thread, prev); ASSERT_TRUE(result.IsJSAPIVector()); @@ -166,8 +166,8 @@ HWTEST_F_L0(ContainersVectorTest, AddAndHas) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), i + 1); @@ -187,8 +187,8 @@ HWTEST_F_L0(ContainersVectorTest, AddAndHas) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), ELEMENT_NUMS + i + 1); @@ -202,8 +202,8 @@ HWTEST_F_L0(ContainersVectorTest, AddAndHas) callInfo->SetCallArg(0, JSTaggedValue(i)); callInfo->SetCallArg(1, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::Insert(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::Insert(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(vector->GetSize(), ELEMENT_NUMS * 2 + i + 1); } @@ -215,8 +215,8 @@ HWTEST_F_L0(ContainersVectorTest, AddAndHas) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -229,8 +229,8 @@ HWTEST_F_L0(ContainersVectorTest, AddAndHas) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, key.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Has(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Has(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -247,12 +247,12 @@ HWTEST_F_L0(ContainersVectorTest, GetFirstValueAndGetLastValue) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); // double - result = ContainersVector::Add(callInfo.get()); + result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), 2 * (i + 1)); @@ -266,8 +266,8 @@ HWTEST_F_L0(ContainersVectorTest, GetFirstValueAndGetLastValue) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetIndexOf(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetIndexOf(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(2 * i)); } @@ -278,8 +278,8 @@ HWTEST_F_L0(ContainersVectorTest, GetFirstValueAndGetLastValue) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetLastIndexOf(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetLastIndexOf(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(2 * i + 1)); } @@ -289,8 +289,8 @@ HWTEST_F_L0(ContainersVectorTest, GetFirstValueAndGetLastValue) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetFirstElement(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetFirstElement(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); } @@ -300,8 +300,8 @@ HWTEST_F_L0(ContainersVectorTest, GetFirstValueAndGetLastValue) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetLastElement(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetLastElement(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(7)); } @@ -319,8 +319,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), i + 1); @@ -333,8 +333,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::RemoveByIndex(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::RemoveByIndex(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(0)); EXPECT_EQ(vector->GetSize(), 7); @@ -346,8 +346,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsFalse()); EXPECT_EQ(vector->GetSize(), 7); @@ -359,8 +359,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(1)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Remove(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Remove(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), 6); @@ -373,8 +373,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetCallArg(0, JSTaggedValue(2)); callInfo->SetCallArg(1, JSTaggedValue(6)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::RemoveByRange(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::RemoveByRange(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(vector->GetSize(), 2); } @@ -384,8 +384,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::IsEmpty(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::IsEmpty(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsFalse()); } @@ -395,8 +395,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::Clear(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::Clear(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(vector->GetSize(), 0); } @@ -406,8 +406,8 @@ HWTEST_F_L0(ContainersVectorTest, RemoveByIndexAndRemoveAndRemoveRangeAndClear) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::IsEmpty(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::IsEmpty(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -424,8 +424,8 @@ HWTEST_F_L0(ContainersVectorTest, ReplaceAllElementsAndForEach) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), i + 1); @@ -444,8 +444,8 @@ HWTEST_F_L0(ContainersVectorTest, ReplaceAllElementsAndForEach) callInfo->SetCallArg(0, func.GetTaggedValue()); callInfo->SetCallArg(1, vec.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::ForEach(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::ForEach(callInfo); TestHelper::TearDownFrame(thread, prev); for (int32_t i = 0; i < ELEMENT_NUMS; i++) { auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -453,8 +453,8 @@ HWTEST_F_L0(ContainersVectorTest, ReplaceAllElementsAndForEach) callInfo1->SetThis(vector.GetTaggedValue()); callInfo1->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSTaggedValue result = ContainersVector::Get(callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSTaggedValue result = ContainersVector::Get(callInfo1); TestHelper::TearDownFrame(thread, prev1); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -470,8 +470,8 @@ HWTEST_F_L0(ContainersVectorTest, ReplaceAllElementsAndForEach) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, func.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::ReplaceAllElements(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::ReplaceAllElements(callInfo); TestHelper::TearDownFrame(thread, prev); for (int32_t i = 0; i < ELEMENT_NUMS; i++) { auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); @@ -479,8 +479,8 @@ HWTEST_F_L0(ContainersVectorTest, ReplaceAllElementsAndForEach) callInfo1->SetThis(vector.GetTaggedValue()); callInfo1->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSTaggedValue result = ContainersVector::Get(callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSTaggedValue result = ContainersVector::Get(callInfo1); TestHelper::TearDownFrame(thread, prev1); EXPECT_EQ(result, JSTaggedValue(i * 2)); } @@ -498,8 +498,8 @@ HWTEST_F_L0(ContainersVectorTest, Sort) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); } @@ -512,8 +512,8 @@ HWTEST_F_L0(ContainersVectorTest, Sort) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::Sort(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::Sort(callInfo); TestHelper::TearDownFrame(thread, prev); for (int32_t i = 0; i < ELEMENT_NUMS; i++) { @@ -522,8 +522,8 @@ HWTEST_F_L0(ContainersVectorTest, Sort) callInfo1->SetThis(vector.GetTaggedValue()); callInfo1->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSTaggedValue result = ContainersVector::Get(callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSTaggedValue result = ContainersVector::Get(callInfo1); TestHelper::TearDownFrame(thread, prev1); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -541,8 +541,8 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), i + 1); @@ -554,8 +554,8 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue vec = ContainersVector::Clone(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue vec = ContainersVector::Clone(callInfo); TestHelper::TearDownFrame(thread, prev); JSHandle handleVec(thread, vec); EXPECT_EQ(handleVec->GetSize(), vector->GetSize()); @@ -566,8 +566,8 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) callInfo1->SetThis(vec); callInfo1->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSTaggedValue result = ContainersVector::Get(callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSTaggedValue result = ContainersVector::Get(callInfo1); TestHelper::TearDownFrame(thread, prev1); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -578,8 +578,8 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue arr = ContainersVector::ConvertToArray(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue arr = ContainersVector::ConvertToArray(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(arr.IsJSArray()); JSHandle handleArr(thread, arr); @@ -597,8 +597,8 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, array.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::CopyToArray(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::CopyToArray(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(array->IsJSArray()); for (int32_t i = 0; i < ELEMENT_NUMS; i++) { @@ -607,7 +607,7 @@ HWTEST_F_L0(ContainersVectorTest, CloneAndConvertToArrayAndCopyToArray) callInfo1->SetThis(array.GetTaggedValue()); callInfo1->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); int result = JSArray::GetProperty(thread, JSHandle(array), i).GetValue()->GetInt(); TestHelper::TearDownFrame(thread, prev1); EXPECT_EQ(result, i); @@ -626,8 +626,8 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), i + 1); @@ -640,8 +640,8 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - int32_t capacity = ContainersVector::GetCapacity(callInfo.get()).GetInt(); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + int32_t capacity = ContainersVector::GetCapacity(callInfo).GetInt(); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(capacity, 10); } @@ -652,8 +652,8 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(20)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::IncreaseCapacityTo(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::IncreaseCapacityTo(callInfo); TestHelper::TearDownFrame(thread, prev); } // getCapacity @@ -662,8 +662,8 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - int32_t newCapacity1 = ContainersVector::GetCapacity(callInfo.get()).GetInt(); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + int32_t newCapacity1 = ContainersVector::GetCapacity(callInfo).GetInt(); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(newCapacity1, 20); } @@ -673,8 +673,8 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - ContainersVector::TrimToCurrentLength(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + ContainersVector::TrimToCurrentLength(callInfo); TestHelper::TearDownFrame(thread, prev); } // getCapacity @@ -683,8 +683,8 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - int32_t newCapacity2 = ContainersVector::GetCapacity(callInfo.get()).GetInt(); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + int32_t newCapacity2 = ContainersVector::GetCapacity(callInfo).GetInt(); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(newCapacity2, 8); } @@ -696,16 +696,16 @@ HWTEST_F_L0(ContainersVectorTest, SubVectorAndGetCapacityAndTrimToCurrentLengthA callInfo->SetCallArg(0, JSTaggedValue(0)); callInfo->SetCallArg(1, JSTaggedValue(2)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue vec = ContainersVector::SubVector(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue vec = ContainersVector::SubVector(callInfo); for (int32_t i = 0; i < 2; i++) { auto callInfo1 = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); callInfo1->SetFunction(JSTaggedValue::Undefined()); callInfo1->SetThis(vec); callInfo1->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1.get()); - JSTaggedValue result = ContainersVector::Get(callInfo1.get()); + [[maybe_unused]] auto prev1 = TestHelper::SetupFrame(thread, callInfo1); + JSTaggedValue result = ContainersVector::Get(callInfo1); TestHelper::TearDownFrame(thread, prev); EXPECT_EQ(result, JSTaggedValue(i)); } @@ -723,8 +723,8 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) callInfo->SetThis(vector.GetTaggedValue()); callInfo->SetCallArg(0, JSTaggedValue(i)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::Add(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::Add(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(result.IsTrue()); EXPECT_EQ(vector->GetSize(), i + 1); @@ -735,8 +735,8 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) auto callInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); callInfo->SetFunction(JSTaggedValue::Undefined()); callInfo->SetThis(vector.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::ToString(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::ToString(callInfo); EXPECT_TRUE(result.IsString()); } @@ -748,8 +748,8 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) callInfo->SetCallArg(0, JSTaggedValue(1)); callInfo->SetCallArg(1, JSTaggedValue(3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetLastIndexFrom(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetLastIndexFrom(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(1))); } @@ -761,8 +761,8 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) callInfo->SetCallArg(0, JSTaggedValue(1)); callInfo->SetCallArg(1, JSTaggedValue(3)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetIndexFrom(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetIndexFrom(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(-1))); } @@ -774,8 +774,8 @@ HWTEST_F_L0(ContainersVectorTest, ToStringAndGetLastIndexFromAndGetIndexFrom) callInfo->SetCallArg(0, JSTaggedValue(10)); callInfo->SetCallArg(1, JSTaggedValue(0)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); - JSTaggedValue result = ContainersVector::GetIndexFrom(callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); + JSTaggedValue result = ContainersVector::GetIndexFrom(callInfo); TestHelper::TearDownFrame(thread, prev); EXPECT_TRUE(JSTaggedValue::SameValue(result, JSTaggedValue(-1))); } diff --git a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp index bcacea01f938738948647b89a9754af2586117d8..043d395b5190a98074fc6f233c6b3fc60878eade 100644 --- a/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp +++ b/ecmascript/dfx/cpu_profiler/cpu_profiler.cpp @@ -35,10 +35,10 @@ CpuProfiler::CpuProfiler() { generator_ = new SamplesRecord(); if (sem_init(&sem_[0], 0, 0) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] init failed"; + LOG_ECMA(ERROR) << "sem_[0] init failed"; } if (sem_init(&sem_[1], 0, 0) != 0) { - LOG(ERROR, RUNTIME) << "sem_[1] init failed"; + LOG_ECMA(ERROR) << "sem_[1] init failed"; } } @@ -65,13 +65,13 @@ void CpuProfiler::StartCpuProfilerForInfo(const EcmaVM *vm) struct sigaction sa; sa.sa_handler = &GetStackSignalHandler; if (sigemptyset(&sa.sa_mask) != 0) { - LOG(ERROR, RUNTIME) << "Parameter set signal set initialization and emptying failed"; + LOG_ECMA(ERROR) << "Parameter set signal set initialization and emptying failed"; isProfiling_ = false; return; } sa.sa_flags = SA_RESTART; if (sigaction(SIGINT, &sa, nullptr) != 0) { - LOG(ERROR, RUNTIME) << "sigaction failed to set signal"; + LOG_ECMA(ERROR) << "sigaction failed to set signal"; isProfiling_ = false; return; } @@ -90,7 +90,7 @@ void CpuProfiler::StartCpuProfilerForFile(const EcmaVM *vm, const std::string &f isProfiling_ = true; std::string absoluteFilePath(""); if (!CheckFileName(fileName, absoluteFilePath)) { - LOG(ERROR, RUNTIME) << "The fileName contains illegal characters"; + LOG_ECMA(ERROR) << "The fileName contains illegal characters"; isProfiling_ = false; return; } @@ -101,7 +101,7 @@ void CpuProfiler::StartCpuProfilerForFile(const EcmaVM *vm, const std::string &f generator_->SetFileName(fileName_); generator_->fileHandle_.open(fileName_.c_str()); if (generator_->fileHandle_.fail()) { - LOG(ERROR, RUNTIME) << "File open failed"; + LOG_ECMA(ERROR) << "File open failed"; isProfiling_ = false; return; } @@ -110,13 +110,13 @@ void CpuProfiler::StartCpuProfilerForFile(const EcmaVM *vm, const std::string &f struct sigaction sa; sa.sa_handler = &GetStackSignalHandler; if (sigemptyset(&sa.sa_mask) != 0) { - LOG(ERROR, RUNTIME) << "Parameter set signal set initialization and emptying failed"; + LOG_ECMA(ERROR) << "Parameter set signal set initialization and emptying failed"; isProfiling_ = false; return; } sa.sa_flags = SA_RESTART; if (sigaction(SIGINT, &sa, nullptr) != 0) { - LOG(ERROR, RUNTIME) << "sigaction failed to set signal"; + LOG_ECMA(ERROR) << "sigaction failed to set signal"; isProfiling_ = false; return; } @@ -134,27 +134,27 @@ std::unique_ptr CpuProfiler::StopCpuProfilerForInfo() { std::unique_ptr profileInfo; if (!isProfiling_) { - LOG(ERROR, RUNTIME) << "Do not execute stop cpuprofiler twice in a row or didn't execute the start\ + LOG_ECMA(ERROR) << "Do not execute stop cpuprofiler twice in a row or didn't execute the start\ or the sampling thread is not started"; return profileInfo; } if (outToFile_) { - LOG(ERROR, RUNTIME) << "Can not Stop a CpuProfiler sampling which is for file output by this stop method"; + LOG_ECMA(ERROR) << "Can not Stop a CpuProfiler sampling which is for file output by this stop method"; return profileInfo; } if (static_cast(tid_) != syscall(SYS_gettid)) { - LOG(ERROR, RUNTIME) << "Thread attempted to close other sampling threads"; + LOG_ECMA(ERROR) << "Thread attempted to close other sampling threads"; return profileInfo; } isProfiling_ = false; SamplingProcessor::SetIsStart(false); generator_->SetLastSampleFlag(); if (sem_post(&sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] post failed"; + LOG_ECMA(ERROR) << "sem_[0] post failed"; return profileInfo; } if (sem_wait(&sem_[1]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[1] wait failed"; + LOG_ECMA(ERROR) << "sem_[1] wait failed"; return profileInfo; } @@ -174,30 +174,30 @@ void CpuProfiler::SetCpuSamplingInterval(int interval) void CpuProfiler::StopCpuProfilerForFile() { if (!isProfiling_) { - LOG(ERROR, RUNTIME) << "Do not execute stop cpuprofiler twice in a row or didn't execute the start\ + LOG_ECMA(ERROR) << "Do not execute stop cpuprofiler twice in a row or didn't execute the start\ or the sampling thread is not started"; return; } if (!outToFile_) { - LOG(ERROR, RUNTIME) << "Can not Stop a CpuProfiler sampling which is for return profile info by\ + LOG_ECMA(ERROR) << "Can not Stop a CpuProfiler sampling which is for return profile info by\ this stop method"; return; } if (static_cast(tid_) != syscall(SYS_gettid)) { - LOG(ERROR, RUNTIME) << "Thread attempted to close other sampling threads"; + LOG_ECMA(ERROR) << "Thread attempted to close other sampling threads"; return; } isProfiling_ = false; SamplingProcessor::SetIsStart(false); generator_->SetLastSampleFlag(); if (sem_post(&sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] post failed"; + LOG_ECMA(ERROR) << "sem_[0] post failed"; return; } if (sem_wait(&sem_[1]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[1] wait failed"; + LOG_ECMA(ERROR) << "sem_[1] wait failed"; return; } generator_->WriteMethodsAndSampleInfo(true); @@ -213,10 +213,10 @@ void CpuProfiler::StopCpuProfilerForFile() CpuProfiler::~CpuProfiler() { if (sem_destroy(&sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] destroy failed"; + LOG_ECMA(ERROR) << "sem_[0] destroy failed"; } if (sem_destroy(&sem_[1]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[1] destroy failed"; + LOG_ECMA(ERROR) << "sem_[1] destroy failed"; } if (generator_ != nullptr) { delete generator_; @@ -254,7 +254,7 @@ void CpuProfiler::GetCurrentProcessInfo(struct CurrentProcessInfo ¤tProces currentProcessInfo.nowTimeStamp = SamplingProcessor::GetMicrosecondsTimeStamp() % TIME_CHANGE; currentProcessInfo.pid = getpid(); if (syscall(SYS_gettid) == -1) { - LOG_ECMA(FATAL) << "syscall failed"; + LOG_FULL(FATAL) << "syscall failed"; UNREACHABLE(); } tid_ = currentProcessInfo.tid = static_cast(syscall(SYS_gettid)); @@ -270,10 +270,10 @@ void CpuProfiler::GetFrameStack(JSThread *thread) if (!SamplesRecord::staticGcState_) { FrameHandler frameHandler(thread); for (; frameHandler.HasFrame(); frameHandler.PrevInterpretedFrame()) { - if (frameHandler.IsEntryFrame()) { + if (!frameHandler.IsInterpretedFrame()) { continue; } - auto *method = frameHandler.GetMethod(); + auto method = frameHandler.CheckAndGetMethod(); if (method != nullptr && staticStackInfo_.count(method) == 0) { ParseMethodInfo(method, frameHandler); } @@ -287,7 +287,10 @@ void CpuProfiler::ParseMethodInfo(JSMethod *method, FrameHandler frameHandler) struct FrameInfo codeEntry; if (method != nullptr && method->IsNativeWithCallField()) { codeEntry.codeType = "other"; - codeEntry.functionName = "native"; + auto addr = method->GetNativePointer(); + std::stringstream strm; + strm << addr; + codeEntry.functionName = "native(" + strm.str() + ")"; staticStackInfo_.insert(std::make_pair(method, codeEntry)); } else if (method != nullptr) { codeEntry.codeType = "JS"; @@ -343,7 +346,7 @@ void CpuProfiler::IsNeedAndGetStack(JSThread *thread) if (thread->GetStackSignal()) { GetFrameStack(thread); if (sem_post(&sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] post failed"; + LOG_ECMA(ERROR) << "sem_[0] post failed"; return; } thread->SetGetStackSignal(false); @@ -355,7 +358,7 @@ void CpuProfiler::GetStackSignalHandler([[maybe_unused]] int signal) JSThread *thread = SamplingProcessor::GetJSThread(); GetFrameStack(thread); if (sem_post(&sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] post failed"; + LOG_ECMA(ERROR) << "sem_[0] post failed"; return; } } @@ -370,12 +373,12 @@ std::string CpuProfiler::GetProfileName() const size_t result = 0; result = strftime(time1, sizeof(time1), "%Y%m%d", &nowTime1); if (result == 0) { - LOG(ERROR, RUNTIME) << "get time failed"; + LOG_ECMA(ERROR) << "get time failed"; return ""; } result = strftime(time2, sizeof(time2), "%H%M%S", &nowTime1); if (result == 0) { - LOG(ERROR, RUNTIME) << "get time failed"; + LOG_ECMA(ERROR) << "get time failed"; return ""; } std::string profileName = "cpuprofile-"; @@ -399,7 +402,7 @@ bool CpuProfiler::CheckFileName(const std::string &fileName, std::string &absolu CVector resolvedPath(PATH_MAX); auto result = realpath(fileName.c_str(), resolvedPath.data()); if (result == nullptr) { - LOG(INFO, RUNTIME) << "The file path does not exist"; + LOG_ECMA(INFO) << "The file path does not exist"; } std::ofstream file(resolvedPath.data()); if (!file.good()) { diff --git a/ecmascript/dfx/cpu_profiler/sampling_processor.cpp b/ecmascript/dfx/cpu_profiler/sampling_processor.cpp index c90ad1fb89d94e88e63c90e0dc74c1394351b78a..cb7c5938495307fb4d664b77166cc5f20e23864b 100644 --- a/ecmascript/dfx/cpu_profiler/sampling_processor.cpp +++ b/ecmascript/dfx/cpu_profiler/sampling_processor.cpp @@ -46,16 +46,16 @@ bool SamplingProcessor::Run([[maybe_unused]] uint32_t threadIndex) if (!SamplesRecord::staticGcState_) { thread->SetGetStackSignal(true); if (sem_wait(&CpuProfiler::sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] wait failed"; + LOG_ECMA(ERROR) << "sem_[0] wait failed"; } } #else if (pthread_kill(pid_, SIGINT) != 0) { - LOG(ERROR, RUNTIME) << "pthread_kill signal failed"; + LOG_ECMA(ERROR) << "pthread_kill signal failed"; return false; } if (sem_wait(&CpuProfiler::sem_[0]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[0] wait failed"; + LOG_ECMA(ERROR) << "sem_[0] wait failed"; return false; } #endif @@ -82,7 +82,7 @@ bool SamplingProcessor::Run([[maybe_unused]] uint32_t threadIndex) uint64_t stopTime = GetMicrosecondsTimeStamp(); generator_->SetThreadStopTime(stopTime); if (sem_post(&CpuProfiler::sem_[1]) != 0) { - LOG(ERROR, RUNTIME) << "sem_[1] post failed"; + LOG_ECMA(ERROR) << "sem_[1] post failed"; return false; } return true; diff --git a/ecmascript/dfx/hprof/heap_profiler.cpp b/ecmascript/dfx/hprof/heap_profiler.cpp index 00792920f7586dbb2708b51a682dff163a2e40ef..764915dece9785e0e16b813322315b327bd658b2 100644 --- a/ecmascript/dfx/hprof/heap_profiler.cpp +++ b/ecmascript/dfx/hprof/heap_profiler.cpp @@ -36,8 +36,9 @@ bool HeapProfiler::DumpHeapSnapshot(DumpFormat dumpFormat, Stream *stream, Progr { [[maybe_unused]] bool heapClean = ForceFullGC(vm_); ASSERT(heapClean); + LOG_ECMA(INFO) << "HeapProfiler DumpSnapshot start"; size_t heapSize = vm_->GetHeap()->GetHeapObjectSize(); - LOG(ERROR, RUNTIME) << "HeapProfiler DumpSnapshot heap size " << heapSize; + LOG_ECMA(ERROR) << "HeapProfiler DumpSnapshot heap size " << heapSize; int32_t heapCount = vm_->GetHeap()->GetHeapObjectCount(); if (progress != nullptr) { progress->ReportProgress(0, heapCount); @@ -54,13 +55,13 @@ bool HeapProfiler::DumpHeapSnapshot(DumpFormat dumpFormat, Stream *stream, Progr return jsonSerializer_->Serialize(snapshot, stream); } -bool HeapProfiler::StartHeapTracking(double timeInterval, bool isVmMode, Stream *stream) +bool HeapProfiler::StartHeapTracking(double timeInterval, bool isVmMode, Stream *stream, bool traceAllocation) { - HeapSnapshot *snapshot = MakeHeapSnapshot(SampleType::REAL_TIME, isVmMode); + HeapSnapshot *snapshot = MakeHeapSnapshot(SampleType::REAL_TIME, isVmMode, false, traceAllocation); if (snapshot == nullptr) { return false; } - + heapTracker_ = std::make_unique(snapshot, timeInterval, stream); const_cast(vm_)->StartHeapTracking(heapTracker_.get()); heapTracker_->StartTracing(); @@ -120,7 +121,7 @@ CString HeapProfiler::GetTimeStamp() }; struct tm *timeData = localtime_r(&timeSource, &tm); if (timeData == nullptr) { - LOG_ECMA(FATAL) << "localtime_r failed"; + LOG_FULL(FATAL) << "localtime_r failed"; UNREACHABLE(); } CString stamp; @@ -149,17 +150,17 @@ bool HeapProfiler::ForceFullGC(const EcmaVM *vm) return false; } -HeapSnapshot *HeapProfiler::MakeHeapSnapshot(SampleType sampleType, bool isVmMode, bool isPrivate) +HeapSnapshot *HeapProfiler::MakeHeapSnapshot(SampleType sampleType, bool isVmMode, bool isPrivate, bool traceAllocation) { - LOG(ERROR, RUNTIME) << "HeapProfiler::MakeHeapSnapshot"; + LOG_ECMA(ERROR) << "HeapProfiler::MakeHeapSnapshot"; DISALLOW_GARBAGE_COLLECTION; const_cast(vm_->GetHeap())->Prepare(); switch (sampleType) { case SampleType::ONE_SHOT: { auto *snapshot = const_cast(vm_->GetNativeAreaAllocator()) - ->New(vm_, isVmMode, isPrivate); + ->New(vm_, isVmMode, isPrivate, traceAllocation); if (snapshot == nullptr) { - LOG_ECMA(FATAL) << "alloc snapshot failed"; + LOG_FULL(FATAL) << "alloc snapshot failed"; UNREACHABLE(); } snapshot->BuildUp(); @@ -168,9 +169,9 @@ HeapSnapshot *HeapProfiler::MakeHeapSnapshot(SampleType sampleType, bool isVmMod } case SampleType::REAL_TIME: { auto *snapshot = const_cast(vm_->GetNativeAreaAllocator()) - ->New(vm_, isVmMode, isPrivate); + ->New(vm_, isVmMode, isPrivate, traceAllocation); if (snapshot == nullptr) { - LOG_ECMA(FATAL) << "alloc snapshot failed"; + LOG_FULL(FATAL) << "alloc snapshot failed"; UNREACHABLE(); } AddSnapshot(snapshot); diff --git a/ecmascript/dfx/hprof/heap_profiler.h b/ecmascript/dfx/hprof/heap_profiler.h index bb017708dc4435afa7eb1efba89e9691bba6783c..b13d8513b76cfb3ee99763da6eda08e4d8b0afca 100644 --- a/ecmascript/dfx/hprof/heap_profiler.h +++ b/ecmascript/dfx/hprof/heap_profiler.h @@ -38,7 +38,7 @@ public: jsonSerializer_ = const_cast(vm->GetNativeAreaAllocator())->New(); if (UNLIKELY(jsonSerializer_ == nullptr)) { - LOG_ECMA(FATAL) << "alloc snapshot json serializer failed"; + LOG_FULL(FATAL) << "alloc snapshot json serializer failed"; UNREACHABLE(); } } @@ -53,7 +53,8 @@ public: void AddSnapshot(HeapSnapshot *snapshot); - bool StartHeapTracking(double timeInterval, bool isVmMode = true, Stream *stream = nullptr) override; + bool StartHeapTracking(double timeInterval, bool isVmMode = true, + Stream *stream = nullptr, bool traceAllocation = false) override; bool StopHeapTracking(Stream *stream, Progress *progress = nullptr) override; private: @@ -65,7 +66,8 @@ private: /** * make a new heap snapshot and put it into a container eg, vector */ - HeapSnapshot *MakeHeapSnapshot(SampleType sampleType, bool isVmMode = true, bool isPrivate = false); + HeapSnapshot *MakeHeapSnapshot(SampleType sampleType, bool isVmMode = true, + bool isPrivate = false, bool traceAllocation = false); std::string GenDumpFileName(DumpFormat dumpFormat); CString GetTimeStamp(); void ClearSnapshot(); diff --git a/ecmascript/dfx/hprof/heap_profiler_interface.h b/ecmascript/dfx/hprof/heap_profiler_interface.h index 1e38c6832b12e6e4afa3b8f77a3e1b685cc8f958..54ce4ed6a066e6009447d9bd5e2300ea093161f3 100644 --- a/ecmascript/dfx/hprof/heap_profiler_interface.h +++ b/ecmascript/dfx/hprof/heap_profiler_interface.h @@ -35,7 +35,8 @@ public: virtual bool DumpHeapSnapshot(DumpFormat dumpFormat, Stream *stream, Progress *progress = nullptr, bool isVmMode = true, bool isPrivate = false) = 0; - virtual bool StartHeapTracking(double timeInterval, bool isVmMode = true, Stream *stream = nullptr) = 0; + virtual bool StartHeapTracking(double timeInterval, bool isVmMode = true, + Stream *stream = nullptr, bool traceAllocation = false) = 0; virtual bool StopHeapTracking(Stream *stream, Progress *progress = nullptr) = 0; NO_MOVE_SEMANTIC(HeapProfilerInterface); diff --git a/ecmascript/dfx/hprof/heap_snapshot.cpp b/ecmascript/dfx/hprof/heap_snapshot.cpp index ddb448c319bb25cf63dc36b9c8e319d7254c76f5..ed62192b86192875d368dad394d857a7e2dc7a32 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot.cpp @@ -33,6 +33,7 @@ #include "ecmascript/property_attributes.h" #include "ecmascript/tagged_array.h" #include "ecmascript/tagged_dictionary.h" +#include "ecmascript/jspandafile/js_pandafile_manager.h" namespace panda::ecmascript { CString *HeapSnapshot::GetString(const CString &as) @@ -46,7 +47,7 @@ Node *Node::NewNode(const EcmaVM *vm, size_t id, size_t index, CString *name, No auto node = const_cast(vm->GetNativeAreaAllocator()) ->New(id, index, name, type, size, 0, NewAddress(entry), isLive); if (UNLIKELY(node == nullptr)) { - LOG_ECMA(FATAL) << "internal allocator failed"; + LOG_FULL(FATAL) << "internal allocator failed"; UNREACHABLE(); } return node; @@ -56,7 +57,7 @@ Edge *Edge::NewEdge(const EcmaVM *vm, uint64_t id, EdgeType type, Node *from, No { auto edge = const_cast(vm->GetNativeAreaAllocator())->New(id, type, from, to, name); if (UNLIKELY(edge == nullptr)) { - LOG_ECMA(FATAL) << "internal allocator failed"; + LOG_FULL(FATAL) << "internal allocator failed"; UNREACHABLE(); } return edge; @@ -72,6 +73,11 @@ HeapSnapshot::~HeapSnapshot() } nodes_.clear(); edges_.clear(); + traceInfoStack_.clear(); + stackInfo_.clear(); + scriptIdMap_.clear(); + methodToTraceNodeId_.clear(); + traceNodeIndex_.clear(); } bool HeapSnapshot::BuildUp() @@ -91,6 +97,9 @@ bool HeapSnapshot::Verify() void HeapSnapshot::PrepareSnapshot() { FillNodes(); + if (trackAllocations()) { + PrepareTraceInfo(); + } } void HeapSnapshot::UpdateNode() @@ -119,33 +128,26 @@ bool HeapSnapshot::FinishSnapshot() void HeapSnapshot::RecordSampleTime() { - uint32_t len = timeStamps_.size(); - if (len > 0) { - if (sequenceId_ != timeStamps_[len - 1U].GetLastSequenceId()) { - timeStamps_.emplace_back(sequenceId_); - } - } else { - timeStamps_.emplace_back(sequenceId_); - } + timeStamps_.emplace_back(sequenceId_ + SEQ_STEP); } void HeapSnapshot::PushHeapStat(Stream* stream) { CVector statsBuffer; if (stream == nullptr) { - LOG(ERROR, DEBUGGER) << "HeapSnapshot::PushHeapStat::stream is nullptr"; + LOG_DEBUGGER(ERROR) << "HeapSnapshot::PushHeapStat::stream is nullptr"; return; } - int preChunkSize = stream->GetSize(); - uint32_t sequenceId = 0; + int32_t preChunkSize = stream->GetSize(); + int32_t sequenceId = 0; auto iter = nodes_.begin(); for (size_t timeIndex = 0; timeIndex < timeStamps_.size(); ++timeIndex) { TimeStamp& timeStamp = timeStamps_[timeIndex]; - sequenceId = static_cast(timeStamp.GetLastSequenceId()); - uint32_t nodesSize = 0; - uint32_t nodesCount = 0; + sequenceId = timeStamp.GetLastSequenceId(); + int32_t nodesSize = 0; + int32_t nodesCount = 0; - while (iter != nodes_.end() && (*iter)->GetId() <= sequenceId) { + while (iter != nodes_.end() && (*iter)->GetId() <= static_cast(sequenceId)) { nodesCount++; nodesSize += (*iter)->GetSelfSize(); iter++; @@ -154,35 +156,38 @@ void HeapSnapshot::PushHeapStat(Stream* stream) && ((nodesCount != 0) && (nodesSize != 0))) { timeStamp.SetCount(nodesCount); timeStamp.SetSize(nodesSize); - statsBuffer.emplace_back(static_cast(timeIndex), nodesCount, nodesSize); - if (static_cast(statsBuffer.size()) >= preChunkSize) { - stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); + statsBuffer.emplace_back(static_cast(timeIndex), nodesCount, nodesSize); + if (static_cast(statsBuffer.size()) >= preChunkSize) { + stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); statsBuffer.clear(); } } } if (!statsBuffer.empty()) { - stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); + stream->UpdateHeapStats(&statsBuffer.front(), static_cast(statsBuffer.size())); statsBuffer.clear(); } - stream->UpdateLastSeenObjectId(sequenceId); + stream->UpdateLastSeenObjectId(sequenceId_); } -void HeapSnapshot::AddNode(TaggedObject* address) +Node *HeapSnapshot::AddNode(TaggedObject* address) { - GenerateNode(JSTaggedValue(address)); + return GenerateNode(JSTaggedValue(address)); } void HeapSnapshot::MoveNode(uintptr_t address, TaggedObject* forward_address) { int sequenceId = -1; + int traceNodeId = 0; Node *node = entryMap_.FindAndEraseNode(address); if (node != nullptr) { sequenceId = static_cast(node->GetId()); + traceNodeId = node->GetStackTraceId(); EraseNodeUnique(node); } - GenerateNode(JSTaggedValue(forward_address), sequenceId); + node = GenerateNode(JSTaggedValue(forward_address), sequenceId); + node->SetTraceId(traceNodeId); } // NOLINTNEXTLINE(readability-function-size) @@ -233,6 +238,8 @@ CString *HeapSnapshot::GenerateNodeName(TaggedObject *entry) return GetString("Range Error"); case JSType::JS_TYPE_ERROR: return GetString("Type Error"); + case JSType::JS_AGGREGATE_ERROR: + return GetString("Aggregate Error"); case JSType::JS_REFERENCE_ERROR: return GetString("Reference Error"); case JSType::JS_URI_ERROR: @@ -332,6 +339,14 @@ CString *HeapSnapshot::GenerateNodeName(TaggedObject *entry) return GetString("PromiseExecutorFunction"); case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: return GetString("PromiseAllResolveElementFunction"); + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: + return GetString("PromiseAnyRejectElementFunction"); + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: + return GetString("PromiseAllSettledElementFunction"); + case JSType::JS_PROMISE_FINALLY_FUNCTION: + return GetString("PromiseFinallyFunction"); + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: + return GetString("PromiseValueThunkOrThrowerFunction"); case JSType::JS_GENERATOR_FUNCTION: return GetString("JSGeneratorFunction"); case JSType::SYMBOL: @@ -384,6 +399,14 @@ CString *HeapSnapshot::GenerateNodeName(TaggedObject *entry) return GetString("ArrayList"); case JSType::JS_API_ARRAYLIST_ITERATOR: return GetString("ArrayListIterator"); + case JSType::JS_API_LIGHT_WEIGHT_MAP: + return GetString("LightWeightMap"); + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: + return GetString("LightWeightMapIterator"); + case JSType::JS_API_LIGHT_WEIGHT_SET: + return GetString("LightWeightSet"); + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: + return GetString("LightWeightSetIterator"); case JSType::JS_API_TREE_MAP: return GetString("TreeMap"); case JSType::JS_API_TREE_SET: @@ -524,7 +547,7 @@ Node *HeapSnapshot::GenerateNode(JSTaggedValue entry, int sequenceId) node = GenerateStringNode(entry, sequenceId); } if (node == nullptr) { - LOG(DEBUG, RUNTIME) << "string node nullptr"; + LOG_ECMA(DEBUG) << "string node nullptr"; } return node; } @@ -588,6 +611,157 @@ Node *HeapSnapshot::GenerateNode(JSTaggedValue entry, int sequenceId) return node; } +TraceNode::TraceNode(TraceTree* tree, uint32_t nodeIndex) + : tree_(tree), + nodeIndex_(nodeIndex), + totalSize_(0), + totalCount_(0), + id_(tree->GetNextNodeId()) +{ +} + +TraceNode::~TraceNode() +{ + for (TraceNode* node : children_) { + delete node; + } + children_.clear(); +} + +TraceNode* TraceTree::AddNodeToTree(CVector traceNodeIndex) +{ + uint32_t len = traceNodeIndex.size(); + if (len == 0) { + return nullptr; + } + + TraceNode* node = GetRoot(); + for (int i = len - 1; i >= 0; i--) { + node = node->FindOrAddChild(traceNodeIndex[i]); + } + return node; +} + +TraceNode* TraceNode::FindOrAddChild(uint32_t nodeIndex) +{ + TraceNode* child = FindChild(nodeIndex); + if (child == nullptr) { + child = new TraceNode(tree_, nodeIndex); + children_.push_back(child); + } + return child; +} + +TraceNode* TraceNode::FindChild(uint32_t nodeIndex) +{ + for (TraceNode* node : children_) { + if (node->GetNodeIndex() == nodeIndex) { + return node; + } + } + return nullptr; +} + +void HeapSnapshot::AddTraceNodeId(JSMethod *method) +{ + uint32_t traceNodeId = 0; + auto result = methodToTraceNodeId_.find(method); + if (result == methodToTraceNodeId_.end()) { + traceNodeId = traceInfoStack_.size() - 1; + methodToTraceNodeId_.insert(std::make_pair(method, traceNodeId)); + } else { + traceNodeId = result->second; + } + traceNodeIndex_.emplace_back(traceNodeId); +} + +int HeapSnapshot::AddTraceNode(int sequenceId, int size) +{ + traceNodeIndex_.clear(); + FrameHandler frameHandler(vm_->GetAssociatedJSThread()); + for (; frameHandler.HasFrame(); frameHandler.PrevInterpretedFrame()) { + if (!frameHandler.IsInterpretedFrame()) { + continue; + } + auto method = frameHandler.CheckAndGetMethod(); + if (method == nullptr || method->IsNativeWithCallField()) { + continue; + } + if (stackInfo_.count(method) == 0) { + AddMethodInfo(method, frameHandler, sequenceId); + } + AddTraceNodeId(method); + } + + TraceNode* topNode = traceTree_.AddNodeToTree(traceNodeIndex_); + if (topNode == nullptr) { + return -1; + } + int totalSize = topNode->GetTotalSize(); + totalSize += size; + topNode->SetTotalSize(totalSize); + int totalCount = topNode->GetTotalCount(); + topNode->SetTotalCount(++totalCount); + return topNode->GetId(); +} + +void HeapSnapshot::AddMethodInfo(JSMethod *method, const FrameHandler &frameHandler, int sequenceId) +{ + struct FunctionInfo codeEntry; + codeEntry.functionId = sequenceId; + const std::string &functionName = method->ParseFunctionName(); + if (functionName.empty()) { + codeEntry.functionName = "anonymous"; + } else { + codeEntry.functionName = functionName; + } + GetString(codeEntry.functionName.c_str()); + + // source file + tooling::JSPtExtractor *debugExtractor = + JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile()); + const std::string &sourceFile = debugExtractor->GetSourceFile(method->GetMethodId()); + if (sourceFile.empty()) { + codeEntry.scriptName = ""; + } else { + codeEntry.scriptName = sourceFile; + auto iter = scriptIdMap_.find(codeEntry.scriptName); + if (iter == scriptIdMap_.end()) { + scriptIdMap_.insert(std::make_pair(codeEntry.scriptName, scriptIdMap_.size() + 1)); + codeEntry.scriptId = static_cast(scriptIdMap_.size()); + } else { + codeEntry.scriptId = iter->second; + } + } + GetString(codeEntry.scriptName.c_str()); + + // line number + int32_t lineNumber = 0; + int32_t columnNumber = 0; + auto callbackLineFunc = [&](int32_t line) -> bool { + lineNumber = line + 1; + return true; + }; + auto callbackColumnFunc = [&](int32_t column) -> bool { + columnNumber = column + 1; + return true; + }; + panda_file::File::EntityId methodId = method->GetMethodId(); + uint32_t offset = frameHandler.GetBytecodeOffset(); + if (!debugExtractor->MatchLineWithOffset(callbackLineFunc, methodId, offset) || + !debugExtractor->MatchColumnWithOffset(callbackColumnFunc, methodId, offset)) { + codeEntry.lineNumber = 0; + codeEntry.columnNumber = 0; + } else { + codeEntry.lineNumber = lineNumber; + codeEntry.columnNumber = columnNumber; + } + + traceInfoStack_.emplace_back(codeEntry); + stackInfo_.insert(std::make_pair(method, codeEntry)); + return; +} + Node *HeapSnapshot::GenerateStringNode(JSTaggedValue entry, int sequenceId) { Node *node = nullptr; @@ -663,7 +837,7 @@ void HeapSnapshot::FillEdges() toValue.RemoveWeakTag(); } if (toValue.IsHeapObject()) { - auto *to = reinterpret_cast(toValue.GetHeapObject()); + auto *to = reinterpret_cast(toValue.GetTaggedObject()); entryTo = entryMap_.FindEntry(Node::NewAddress(to)); } if (entryTo == nullptr) { diff --git a/ecmascript/dfx/hprof/heap_snapshot.h b/ecmascript/dfx/hprof/heap_snapshot.h index 5f95f766beb050a35fa940eb36457ac13db0bc71..cc2bf8dd982d42e3c29389b1f9c68bdf85839d38 100644 --- a/ecmascript/dfx/hprof/heap_snapshot.h +++ b/ecmascript/dfx/hprof/heap_snapshot.h @@ -30,6 +30,7 @@ #include "ecmascript/mem/c_containers.h" #include "os/mem.h" #include "ecmascript/tooling/interface/stream.h" +#include "ecmascript/interpreter/frame_handler.h" namespace panda::ecmascript { // Define the Object Graphic @@ -107,6 +108,10 @@ public: { isLive_ = isLive; } + void SetTraceId(uint64_t traceId) + { + traceId_ = traceId; + } static Node *NewNode(const EcmaVM *vm, size_t id, size_t index, CString *name, NodeType type, size_t size, TaggedObject *entry, bool isLive = true); template @@ -197,22 +202,22 @@ public: return timeStampUs_; } - uint32_t GetSize() const + int32_t GetSize() const { return size_; } - void SetSize(uint32_t size) + void SetSize(int32_t size) { size_ = size; } - uint32_t GetCount() const + int32_t GetCount() const { return count_; } - void SetCount(uint32_t count) + void SetCount(int32_t count) { count_ = count; } @@ -228,8 +233,8 @@ private: int lastSequenceId_ {0}; int64_t timeStampUs_ {0}; - uint32_t size_ {0}; - uint32_t count_ {0}; + int32_t size_ {0}; + int32_t count_ {0}; }; class HeapEntryMap { @@ -256,13 +261,95 @@ private: CUnorderedMap nodesMap_ {}; }; +struct FunctionInfo { + int functionId = 0; + std::string functionName = ""; + std::string scriptName = ""; + int scriptId = 0; + int columnNumber = -1; + int lineNumber = -1; +}; + +class TraceTree; +class TraceNode { +public: + TraceNode(TraceTree* tree, uint32_t nodeIndex); + ~TraceNode(); + + TraceNode(const TraceNode&) = delete; + TraceNode& operator=(const TraceNode&) = delete; + TraceNode* FindChild(uint32_t nodeIndex); + TraceNode* FindOrAddChild(uint32_t nodeIndex); + uint32_t GetNodeIndex() const + { + return nodeIndex_; + } + uint32_t GetTotalSize() const + { + return totalSize_; + } + uint32_t GetTotalCount() const + { + return totalCount_; + } + uint32_t GetId() const + { + return id_; + } + const std::vector& GetChildren() const + { + return children_; + } + TraceNode &SetTotalSize(uint32_t totalSize) + { + totalSize_ = totalSize; + return *this; + } + TraceNode &SetTotalCount(uint32_t totalCount) + { + totalCount_ = totalCount; + return *this; + } + +private: + TraceTree* tree_; + uint32_t nodeIndex_; + uint32_t totalSize_; + uint32_t totalCount_; + uint32_t id_; + std::vector children_; +}; + +class TraceTree { +public: + TraceTree() : nextNodeId_(1), root_(this, 0) + { + } + ~TraceTree() = default; + TraceTree(const TraceTree&) = delete; + TraceTree& operator=(const TraceTree&) = delete; + TraceNode* AddNodeToTree(CVector traceNodeIndex); + TraceNode* GetRoot() + { + return &root_; + } + uint32_t GetNextNodeId() + { + return nextNodeId_++; + } + +private: + uint32_t nextNodeId_; + TraceNode root_; +}; + class HeapSnapshot { public: static constexpr int SEQ_STEP = 2; NO_MOVE_SEMANTIC(HeapSnapshot); NO_COPY_SEMANTIC(HeapSnapshot); - explicit HeapSnapshot(const EcmaVM *vm, const bool isVmMode, const bool isPrivate) - : stringTable_(vm), vm_(vm), isVmMode_(isVmMode), isPrivate_(isPrivate) + explicit HeapSnapshot(const EcmaVM *vm, const bool isVmMode, const bool isPrivate, const bool trackAllocations) + : stringTable_(vm), vm_(vm), isVmMode_(isVmMode), isPrivate_(isPrivate), trackAllocations_(trackAllocations) { } ~HeapSnapshot(); @@ -271,11 +358,14 @@ public: void PrepareSnapshot(); void UpdateNode(); - void AddNode(TaggedObject* address); + Node *AddNode(TaggedObject* address); void MoveNode(uintptr_t address, TaggedObject* forward_address); void RecordSampleTime(); bool FinishSnapshot(); void PushHeapStat(Stream* stream); + int AddTraceNode(int sequenceId, int size); + void AddMethodInfo(JSMethod *method, const FrameHandler &frameHandler, int sequenceId); + void AddTraceNodeId(JSMethod *method); const CVector &GetTimeStamps() const { @@ -329,6 +419,29 @@ public: return isPrivate_; } + bool trackAllocations() const + { + return trackAllocations_; + } + + const CVector &GetTrackAllocationsStack() const + { + return traceInfoStack_; + } + + TraceTree* GetTraceTree() + { + return &traceTree_; + } + + void PrepareTraceInfo() + { + struct FunctionInfo info; + info.functionName = "(root)"; + GetString(info.functionName.c_str()); + traceInfoStack_.push_back(info); + } + private: void FillNodes(); Node *GenerateNode(JSTaggedValue entry, int sequenceId = -1); @@ -359,6 +472,13 @@ private: bool isVmMode_ {true}; bool isPrivate_ {false}; Node* privateStringNode_ {nullptr}; + bool trackAllocations_ {false}; + CVector traceInfoStack_ {}; + CMap stackInfo_; + CMap scriptIdMap_; + TraceTree traceTree_; + CMap methodToTraceNodeId_; + CVector traceNodeIndex_; }; class EntryVisitor { diff --git a/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp b/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp index 8a3dc97b35d195f62bf61bdd884e1b2892a6fc3a..7bd01343156a9115fe31c07edb0b334c5d5ff894 100644 --- a/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp +++ b/ecmascript/dfx/hprof/heap_snapshot_json_serializer.cpp @@ -22,7 +22,7 @@ namespace panda::ecmascript { bool HeapSnapshotJSONSerializer::Serialize(HeapSnapshot *snapshot, Stream *stream) { // Serialize Node/Edge/String-Table - LOG(ERROR, RUNTIME) << "HeapSnapshotJSONSerializer::Serialize begin"; + LOG_ECMA(ERROR) << "HeapSnapshotJSONSerializer::Serialize begin"; snapshot_ = snapshot; ASSERT(snapshot_->GetNodes() != nullptr && snapshot_->GetEdges() != nullptr && snapshot_->GetEcmaStringTable() != nullptr); @@ -41,7 +41,7 @@ bool HeapSnapshotJSONSerializer::Serialize(HeapSnapshot *snapshot, Stream *strea SerializerSnapshotClosure(); // 9. WriteChunk(); - LOG(ERROR, RUNTIME) << "HeapSnapshotJSONSerializer::Serialize exit"; + LOG_ECMA(ERROR) << "HeapSnapshotJSONSerializer::Serialize exit"; return true; } @@ -76,8 +76,7 @@ void HeapSnapshotJSONSerializer::SerializeSnapshotHeader() stringBuffer_ << "\"location_fields\":[\"object_index\",\"script_id\",\"line\",\"column\"]},\n"; // 10. stringBuffer_ << "\"node_count\":" << snapshot_->GetNodeCount() << ",\n"; // 11. stringBuffer_ << "\"edge_count\":" << snapshot_->GetEdgeCount() << ",\n"; // 12. - stringBuffer_ << "\"trace_function_count\":" - << "0\n"; // 13. + stringBuffer_ << "\"trace_function_count\":" << snapshot_->GetTrackAllocationsStack().size() << "\n"; // 13. stringBuffer_ << "},\n"; // 14. } @@ -133,12 +132,60 @@ void HeapSnapshotJSONSerializer::SerializeEdges() void HeapSnapshotJSONSerializer::SerializeTraceFunctionInfo() { - stringBuffer_ << "\"trace_function_infos\":[],\n"; // Empty + const CVector trackAllocationsStack = snapshot_->GetTrackAllocationsStack(); + const StringHashMap *stringTable = snapshot_->GetEcmaStringTable(); + + stringBuffer_ << "\"trace_function_infos\":["; // Empty + size_t i = 0; + + for (const auto &info : trackAllocationsStack) { + if (i > 0) { // add comma except the first line + stringBuffer_ << ","; + } + stringBuffer_ << info.functionId << ","; + CString functionName(info.functionName.c_str()); + stringBuffer_ << stringTable->GetStringId(&functionName) << ","; + CString scriptName(info.scriptName.c_str()); + stringBuffer_ << stringTable->GetStringId(&scriptName) << ","; + stringBuffer_ << info.scriptId << ","; + stringBuffer_ << info.columnNumber << ","; + stringBuffer_ << info.lineNumber << "\n"; + i++; + } + stringBuffer_ << "],\n"; } void HeapSnapshotJSONSerializer::SerializeTraceTree() { - stringBuffer_ << "\"trace_tree\":[],\n"; // Empty + stringBuffer_ << "\"trace_tree\":["; + TraceTree* tree = snapshot_->GetTraceTree(); + if (tree != nullptr) { + SerializeTraceNode(tree->GetRoot()); + } + stringBuffer_ << "],\n"; +} + +void HeapSnapshotJSONSerializer::SerializeTraceNode(TraceNode* node) +{ + if (node == nullptr) { + return; + } + + stringBuffer_ << node->GetId() << ","; + stringBuffer_ << node->GetNodeIndex() << ","; + stringBuffer_ << node->GetTotalCount() << ","; + stringBuffer_ << node->GetTotalSize() << ","; + stringBuffer_ << "["; + + int i = 0; + for (TraceNode* child : node->GetChildren()) { + if (i > 0) { + stringBuffer_ << ","; + } + SerializeTraceNode(child); + i++; + } + stringBuffer_ << "]"; } void HeapSnapshotJSONSerializer::SerializeSamples() diff --git a/ecmascript/dfx/hprof/heap_snapshot_json_serializer.h b/ecmascript/dfx/hprof/heap_snapshot_json_serializer.h index 2606070edbabdd2cfd7185445492c783540eae69..fc1b92d72c6848678b51877246294da8729f4356 100644 --- a/ecmascript/dfx/hprof/heap_snapshot_json_serializer.h +++ b/ecmascript/dfx/hprof/heap_snapshot_json_serializer.h @@ -28,6 +28,7 @@ using fstream = std::fstream; using stringstream = std::stringstream; class HeapSnapshot; +class TraceNode; class HeapSnapshotJSONSerializer { public: @@ -43,6 +44,7 @@ private: void SerializeEdges(); void SerializeTraceFunctionInfo(); void SerializeTraceTree(); + void SerializeTraceNode(TraceNode* node); void SerializeSamples(); void SerializeLocations(); void SerializeStringTable(); diff --git a/ecmascript/dfx/hprof/heap_tracker.cpp b/ecmascript/dfx/hprof/heap_tracker.cpp index 0d3e4d98ebc84d7f5fee457585c7f44ccd22fab3..fb16b4b8839057d8850e240c8f290b8e2c20dd16 100644 --- a/ecmascript/dfx/hprof/heap_tracker.cpp +++ b/ecmascript/dfx/hprof/heap_tracker.cpp @@ -33,8 +33,17 @@ void HeapTrackerSample::Run() void HeapTracker::AllocationEvent(TaggedObject* address) { + Node *node; if (snapshot_ != nullptr) { - snapshot_->AddNode(address); + node = snapshot_->AddNode(address); + if (node != nullptr && snapshot_->trackAllocations()) { + int size = node->GetSelfSize(); + int sequenceId = node->GetId(); + int traceId = snapshot_->AddTraceNode(sequenceId, size); + if (traceId != -1) { + node->SetTraceId(static_cast(traceId)); + } + } } } diff --git a/ecmascript/dfx/native_dfx/backtrace.cpp b/ecmascript/dfx/native_dfx/backtrace.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8397aba54d5170287f1f26159aae9703b8c70b9f --- /dev/null +++ b/ecmascript/dfx/native_dfx/backtrace.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/dfx/native_dfx/backtrace.h" + +#include +#include +#include +#include +#include + +#include "mem/mem.h" + +namespace panda::ecmascript { +static const std::string LIB_UNWIND_SO_NAME = "libunwind.so"; +static const int MAX_STACK_SIZE = 16; +static const int ALIGN_WIDTH = 2; + +using UnwBackTraceFunc = int (*)(void**, int); + +void PrintBacktrace(uintptr_t value) +{ + static UnwBackTraceFunc unwBackTrace = nullptr; + if (!unwBackTrace) { + void *handle = dlopen(LIB_UNWIND_SO_NAME.c_str(), RTLD_NOW); + if (handle == nullptr) { + LOG_ECMA(ERROR) << "dlopen libunwind.so failed"; + return; + } + unwBackTrace = reinterpret_cast(dlsym(handle, "unw_backtrace")); + if (unwBackTrace == nullptr) { + LOG_ECMA(ERROR) << "dlsym unw_backtrace failed"; + return; + } + } + + void *buffer[MAX_STACK_SIZE] = { nullptr }; + int level = unwBackTrace((void**)&buffer, MAX_STACK_SIZE); + std::ostringstream stack; + for (int i = 1; i < level; i++) { + const char *file = ""; + const char *symbol = ""; + uintptr_t offset = 0; + Dl_info info; + if (dladdr(buffer[i], &info)) { + if (info.dli_sname) { + symbol = info.dli_sname; + } + if (info.dli_fname) { + file = info.dli_fname; + } + if (info.dli_fbase) { + offset = ToUintPtr(buffer[i]) - ToUintPtr(info.dli_fbase); + } + } + stack << "#" << std::setw(ALIGN_WIDTH) << std::dec << i << ": " + << file << "(" << "+" << std::hex << offset << ")" << std::endl; + } + LOG_ECMA(INFO) << "=====================Backtrace(" << std::hex << value <<")========================"; + LOG_ECMA(INFO) << stack.str(); + stack.clear(); +} +} // namespace panda::ecmascript diff --git a/ecmascript/dfx/native_dfx/backtrace.h b/ecmascript/dfx/native_dfx/backtrace.h new file mode 100644 index 0000000000000000000000000000000000000000..a43aab2d5f55d0a0f9b2c7869c1e148c2605a712 --- /dev/null +++ b/ecmascript/dfx/native_dfx/backtrace.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_DFX_NATIVE_DFX_BACKTRACE_H +#define ECMASCRIPT_DFX_NATIVE_DFX_BACKTRACE_H + +#include + +namespace panda::ecmascript { +void PrintBacktrace(uintptr_t value); +} // namespace panda::ecmascript +#endif // ECMASCRIPT_DFX_NATIVE_DFX_BACKTRACE_H diff --git a/ecmascript/dfx/vmstat/runtime_stat.cpp b/ecmascript/dfx/vmstat/runtime_stat.cpp index 6b4e85925aa145fbd7f320614a8e8af542aba379..1527a4ede995007e9c366cb954966686b6d7d296 100644 --- a/ecmascript/dfx/vmstat/runtime_stat.cpp +++ b/ecmascript/dfx/vmstat/runtime_stat.cpp @@ -68,14 +68,14 @@ void EcmaRuntimeStat::ResetAllCount() void EcmaRuntimeStat::PrintAllStats() const { - LOG(INFO, RUNTIME) << "panda runtime stat:"; + LOG_ECMA(INFO) << "panda runtime stat:"; static constexpr int nameRightAdjustment = 45; static constexpr int numberRightAdjustment = 12; - LOG(INFO, RUNTIME) << std::right << std::setw(nameRightAdjustment) << "InterPreter && GC && C++ Builtin Function" + LOG_ECMA(INFO) << std::right << std::setw(nameRightAdjustment) << "InterPreter && GC && C++ Builtin Function" << std::setw(numberRightAdjustment) << "Time(ns)" << std::setw(numberRightAdjustment) << "Count" << std::setw(numberRightAdjustment) << "MaxTime(ns)" << std::setw(numberRightAdjustment) << "AvgTime(ns)"; - LOG(INFO, RUNTIME) << "============================================================" + LOG_ECMA(INFO) << "============================================================" << "========================================================="; CVector callerStat; @@ -92,7 +92,7 @@ void EcmaRuntimeStat::PrintAllStats() const for (auto &runCallerStat : callerStat) { if (runCallerStat.TotalCount() != 0) { totalTime += runCallerStat.TotalTime(); - LOG(INFO, RUNTIME) << std::right << std::setw(nameRightAdjustment) << runCallerStat.Name() + LOG_ECMA(INFO) << std::right << std::setw(nameRightAdjustment) << runCallerStat.Name() << std::setw(numberRightAdjustment) << runCallerStat.TotalTime() << std::setw(numberRightAdjustment) << runCallerStat.TotalCount() << std::setw(numberRightAdjustment) << runCallerStat.MaxTime() @@ -100,24 +100,22 @@ void EcmaRuntimeStat::PrintAllStats() const << runCallerStat.TotalTime() / runCallerStat.TotalCount(); } } - LOG(INFO, RUNTIME) << "------------------------------------------------------------" + LOG_ECMA(INFO) << "------------------------------------------------------------" << "---------------------------------------------------------"; - LOG(INFO, RUNTIME) << std::right << std::setw(nameRightAdjustment) << "Total Time(ns)" + LOG_ECMA(INFO) << std::right << std::setw(nameRightAdjustment) << "Total Time(ns)" << std::setw(numberRightAdjustment) << totalTime; } EcmaRuntimeStatScope::EcmaRuntimeStatScope(EcmaVM *vm) : vm_(vm) { - JSRuntimeOptions options = vm_->GetJSOptions(); - if (options.IsEnableRuntimeStat()) { + if (vm_->GetJSOptions().IsEnableRuntimeStat()) { vm_->SetRuntimeStatEnable(true); } } EcmaRuntimeStatScope::~EcmaRuntimeStatScope() { - JSRuntimeOptions options = vm_->GetJSOptions(); - if (options.IsEnableRuntimeStat()) { + if (vm_->GetJSOptions().IsEnableRuntimeStat()) { vm_->SetRuntimeStatEnable(false); } vm_ = nullptr; diff --git a/ecmascript/dump.cpp b/ecmascript/dump.cpp index 3b54a4fecdabe2f7cd8ea9678ac10c49f1c3fd7d..82d584c2c6a9e903b77584c5568219aa64778c98 100644 --- a/ecmascript/dump.cpp +++ b/ecmascript/dump.cpp @@ -34,6 +34,10 @@ #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list.h" @@ -144,6 +148,8 @@ CString JSHClass::DumpJSType(JSType type) return "Range Error"; case JSType::JS_TYPE_ERROR: return "Type Error"; + case JSType::JS_AGGREGATE_ERROR: + return "Aggregate Error"; case JSType::JS_REFERENCE_ERROR: return "Reference Error"; case JSType::JS_URI_ERROR: @@ -244,6 +250,14 @@ CString JSHClass::DumpJSType(JSType type) return "PromiseExecutorFunction"; case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: return "PromiseAllResolveElementFunction"; + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: + return "PromiseAnyRejectElementFunction"; + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: + return "PromiseAllSettledElementFunction"; + case JSType::JS_PROMISE_FINALLY_FUNCTION: + return "PromiseFinallyFunction"; + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: + return "PromiseValueThunkOrThrowerFunction"; case JSType::MICRO_JOB_QUEUE: return "MicroJobQueue"; case JSType::PENDING_JOB: @@ -322,6 +336,14 @@ CString JSHClass::DumpJSType(JSType type) return "TSArrayType"; case JSType::JS_API_ARRAYLIST_ITERATOR: return "JSArraylistIterator"; + case JSType::JS_API_LIGHT_WEIGHT_MAP: + return "LightWeightMap"; + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: + return "LightWeightMapIterator"; + case JSType::JS_API_LIGHT_WEIGHT_SET: + return "LightWeightSet"; + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: + return "LightWeightSetIterator"; case JSType::JS_API_TREE_MAP: return "TreeMap"; case JSType::JS_API_TREE_SET: @@ -431,12 +453,13 @@ static void DumpHClass(const JSHClass *jshclass, std::ostream &os, bool withDeta } os << " - Flags : " << std::setw(DUMP_TYPE_OFFSET); - os << "Ctor :" << jshclass->IsConstructor(); - os << "| Callable :" << jshclass->IsCallable(); - os << "| Extensible :" << jshclass->IsExtensible(); + os << "IsCtor :" << std::boolalpha << jshclass->IsConstructor(); + os << "| IsCallable :" << std::boolalpha << jshclass->IsCallable(); + os << "| IsExtensible :" << std::boolalpha << jshclass->IsExtensible(); os << "| ElementRepresentation :" << static_cast(jshclass->GetElementRepresentation()); os << "| NumberOfProps :" << std::dec << jshclass->NumberOfProps(); os << "| InlinedProperties :" << std::dec << jshclass->GetInlinedProperties(); + os << "| IsTSType :" << std::boolalpha << jshclass->IsTSType(); os << "\n"; } @@ -504,6 +527,7 @@ static void DumpObject(TaggedObject *obj, std::ostream &os) case JSType::JS_EVAL_ERROR: case JSType::JS_RANGE_ERROR: case JSType::JS_TYPE_ERROR: + case JSType::JS_AGGREGATE_ERROR: case JSType::JS_REFERENCE_ERROR: case JSType::JS_URI_ERROR: case JSType::JS_SYNTAX_ERROR: @@ -614,6 +638,18 @@ static void DumpObject(TaggedObject *obj, std::ostream &os) case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: JSPromiseAllResolveElementFunction::Cast(obj)->Dump(os); break; + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: + JSPromiseAnyRejectElementFunction::Cast(obj)->Dump(os); + break; + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: + JSPromiseAllSettledElementFunction::Cast(obj)->Dump(os); + break; + case JSType::JS_PROMISE_FINALLY_FUNCTION: + JSPromiseFinallyFunction::Cast(obj)->Dump(os); + break; + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: + JSPromiseValueThunkOrThrowerFunction::Cast(obj)->Dump(os); + break; case JSType::MICRO_JOB_QUEUE: MicroJobQueue::Cast(obj)->Dump(os); break; @@ -727,6 +763,18 @@ static void DumpObject(TaggedObject *obj, std::ostream &os) case JSType::JS_API_ARRAYLIST_ITERATOR: JSAPIArrayListIterator::Cast(obj)->Dump(os); break; + case JSType::JS_API_LIGHT_WEIGHT_MAP: + JSAPILightWeightMap::Cast(obj)->Dump(os); + break; + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: + JSAPILightWeightMapIterator::Cast(obj)->Dump(os); + break; + case JSType::JS_API_LIGHT_WEIGHT_SET: + JSAPILightWeightSet::Cast(obj)->Dump(os); + break; + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: + JSAPILightWeightSetIterator::Cast(obj)->Dump(os); + break; case JSType::TS_OBJECT_TYPE: TSObjectType::Cast(obj)->Dump(os); break; @@ -821,13 +869,13 @@ static void DumpObject(TaggedObject *obj, std::ostream &os) JSAPIPlainArrayIterator::Cast(obj)->Dump(os); break; case JSType::JS_CJS_MODULE: - JSCjsModule::Cast(obj)->Dump(os); + CjsModule::Cast(obj)->Dump(os); break; case JSType::JS_CJS_REQUIRE: - JSCjsRequire::Cast(obj)->Dump(os); + CjsRequire::Cast(obj)->Dump(os); break; case JSType::JS_CJS_EXPORTS: - JSCjsExports::Cast(obj)->Dump(os); + CjsExports::Cast(obj)->Dump(os); break; default: UNREACHABLE(); @@ -1263,11 +1311,9 @@ void JSPrimitiveRef::Dump(std::ostream &os) const void BigInt::Dump(std::ostream &os) const { - os << " - Data : "; - GetData().DumpTaggedValue(os); - os << "\n"; - os << " - value : " << ToStdString(DECIMAL) << "\n"; + os << " - length : " << GetLength() << "\n"; os << " - Sign : " << GetSign() << "\n"; + os << " - value : " << ToStdString(DECIMAL) << "\n"; } void JSDate::Dump(std::ostream &os) const @@ -1655,6 +1701,15 @@ void JSArray::Dump(std::ostream &os) const JSObject::Dump(os); } +void JSArrayIterator::Dump(std::ostream &os) const +{ + JSArray *array = JSArray::Cast(GetIteratedArray().GetTaggedObject()); + os << " - length: " << std::dec << array->GetArrayLength() << "\n"; + os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; + os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; + JSObject::Dump(os); +} + void JSAPIArrayList::Dump(std::ostream &os) const { os << " - length: " << std::dec << GetSize() << "\n"; @@ -1684,24 +1739,53 @@ void JSAPIDequeIterator::Dump(std::ostream &os) const JSObject::Dump(os); } -void JSAPIStack::Dump(std::ostream &os) const +void JSAPILightWeightMap::Dump(std::ostream &os) const { - os << " - top: " << std::dec << GetTop() << "\n"; + int capacity = GetSize(); + os << " - length: " << std::dec << capacity << "\n"; + int i = 0; + TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); + TaggedArray *keyArray = TaggedArray::Cast(GetKeys().GetTaggedObject()); + TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + while (capacity > i) { + os << " hash: "; + hashArray->Get(i).DumpTaggedValue(os); + os << " key: "; + keyArray->Get(i).DumpTaggedValue(os); + os << " value: "; + valueArray->Get(i).DumpTaggedValue(os); + os << "\n"; + i++; + } JSObject::Dump(os); } -void JSAPIStackIterator::Dump(std::ostream &os) const +void JSAPILightWeightMapIterator::Dump(std::ostream &os) const { - JSAPIStack *stack = JSAPIStack::Cast(GetIteratedStack().GetTaggedObject()); - os << " - length: " << std::dec << stack->GetSize() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; + os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; JSObject::Dump(os); } -void JSArrayIterator::Dump(std::ostream &os) const +void JSAPILightWeightSet::Dump(std::ostream &os) const +{ + TaggedArray *keys = TaggedArray::Cast(GetHashes().GetTaggedObject()); + TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + uint32_t len = GetLength(); + for (uint32_t i = 0; i < len; i++) { + os << " - keys: "; + keys->Get(i).DumpTaggedValue(os); + os << "\n"; + os << " - values: "; + values->Get(i).DumpTaggedValue(os); + os << "\n"; + } + os << " - length: " << std::dec << len << "\n"; + JSObject::Dump(os); +} + +void JSAPILightWeightSetIterator::Dump(std::ostream &os) const { - JSArray *array = JSArray::Cast(GetIteratedArray().GetTaggedObject()); - os << " - length: " << std::dec << array->GetArrayLength() << "\n"; os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; os << " - IterationKind: " << std::dec << static_cast(GetIterationKind()) << "\n"; JSObject::Dump(os); @@ -1797,6 +1881,20 @@ void JSAPIQueueIterator::Dump(std::ostream &os) const JSObject::Dump(os); } +void JSAPIStack::Dump(std::ostream &os) const +{ + os << " - top: " << std::dec << GetTop() << "\n"; + JSObject::Dump(os); +} + +void JSAPIStackIterator::Dump(std::ostream &os) const +{ + JSAPIStack *stack = JSAPIStack::Cast(GetIteratedStack().GetTaggedObject()); + os << " - length: " << std::dec << stack->GetSize() << "\n"; + os << " - nextIndex: " << std::dec << GetNextIndex() << "\n"; + JSObject::Dump(os); +} + void JSAPIVector::Dump(std::ostream &os) const { os << " - length: " << std::dec << GetSize() << "\n"; @@ -1834,13 +1932,16 @@ void JSRegExp::Dump(std::ostream &os) const { os << "\n"; os << " - ByteCodeBuffer: "; - GetByteCodeBuffer().Dump(os); + GetByteCodeBuffer().D(); os << "\n"; os << " - OriginalSource: "; - GetOriginalSource().Dump(os); + GetOriginalSource().D(); os << "\n"; os << " - OriginalFlags: "; - GetOriginalFlags().Dump(os); + GetOriginalFlags().D(); + os << "\n"; + os << " - GroupName: "; + GetGroupName().D(); os << "\n"; os << " - Length: " << GetLength(); os << "\n"; @@ -1914,6 +2015,8 @@ void GlobalEnv::Dump(std::ostream &os) const GetReferenceErrorFunction().GetTaggedValue().Dump(os); os << " - TypeErrorFunction: "; GetTypeErrorFunction().GetTaggedValue().Dump(os); + os << " - AggregateErrorFunction: "; + GetAggregateErrorFunction().GetTaggedValue().Dump(os); os << " - URIErrorFunction: "; GetURIErrorFunction().GetTaggedValue().Dump(os); os << " - SyntaxErrorFunction: "; @@ -2202,6 +2305,52 @@ void JSPromiseAllResolveElementFunction::Dump(std::ostream &os) const JSObject::Dump(os); } +void JSPromiseAnyRejectElementFunction::Dump(std::ostream &os) const +{ + os << " - index: "; + JSTaggedValue(GetIndex()).Dump(os); + os << " - errors: "; + GetErrors().Dump(os); + os << " - capability: "; + GetCapability().Dump(os); + os << " - remaining-elements: "; + GetRemainingElements().Dump(os); + os << " - already-called: "; + GetAlreadyCalled().Dump(os); + JSObject::Dump(os); +} + +void JSPromiseAllSettledElementFunction::Dump(std::ostream &os) const +{ + os << " - already-called: "; + GetAlreadyCalled().Dump(os); + os << " - index: "; + JSTaggedValue(GetIndex()).Dump(os); + os << " - values: "; + GetValues().Dump(os); + os << " - capability: "; + GetCapability().Dump(os); + os << " - remaining-elements: "; + GetRemainingElements().Dump(os); + JSObject::Dump(os); +} + +void JSPromiseFinallyFunction::Dump(std::ostream &os) const +{ + os << " - constructor: "; + GetConstructor().Dump(os); + os << " - onFinally: "; + GetOnFinally().Dump(os); + JSObject::Dump(os); +} + +void JSPromiseValueThunkOrThrowerFunction::Dump(std::ostream &os) const +{ + os << " - result: "; + GetResult().Dump(os); + JSObject::Dump(os); +} + void MicroJobQueue::Dump(std::ostream &os) const { os << " - promise-job-queue: "; @@ -2214,8 +2363,20 @@ void PendingJob::Dump(std::ostream &os) const { os << " - job: "; GetJob().Dump(os); + os << "\n"; os << " - arguments: "; GetArguments().Dump(os); +#if defined(ENABLE_HITRACE) + os << "\n"; + os << " - chainId: " << GetChainId(); + os << "\n"; + os << " - spanId: " << GetSpanId(); + os << "\n"; + os << " - parentSpanId: " << GetParentSpanId(); + os << "\n"; + os << " - flags: " << GetFlags(); + os << "\n"; +#endif } void CompletionRecord::Dump(std::ostream &os) const @@ -2645,15 +2806,17 @@ void TSClassType::Dump(std::ostream &os) const os << typeKind; os << "\n"; os << " - ExtensionTypeGT: "; - JSTaggedValue extensionType = GetExtensionType(); - if (extensionType.IsUndefined()) { + GlobalTSTypeRef extensionGT = GetExtensionGT(); + if (extensionGT.IsDefault()) { os << " (base class type) "; } else { - uint64_t extensionTypeGT = TSType::Cast(extensionType.GetTaggedObject())->GetGTRef().GetType(); - os << extensionTypeGT; + os << extensionGT.GetType(); } os << "\n"; + CString hasLinked = GetHasLinked() ? "true" : "false"; + os << " - HasLinked: " << hasLinked << "\n"; + os << " - InstanceType: " << "\n"; if (GetInstanceType().IsTSObjectType()) { TSObjectType *instanceType = TSObjectType::Cast(GetInstanceType().GetTaggedObject()); @@ -2983,7 +3146,7 @@ void ModuleNamespace::Dump(std::ostream &os) const os << "\n"; } -void JSCjsModule::Dump(std::ostream &os) const +void CjsModule::Dump(std::ostream &os) const { os << " - current module path: "; GetPath().Dump(os); @@ -2993,13 +3156,13 @@ void JSCjsModule::Dump(std::ostream &os) const os << "\n"; } -void JSCjsRequire::Dump(std::ostream &os) const +void CjsRequire::Dump(std::ostream &os) const { - os << " --- JSCjsRequire is JSFunction: "; + os << " --- CjsRequire is JSFunction: "; os << "\n"; } -void JSCjsExports::Dump(std::ostream &os) const +void CjsExports::Dump(std::ostream &os) const { DISALLOW_GARBAGE_COLLECTION; JSHClass *jshclass = GetJSHClass(); @@ -3097,6 +3260,7 @@ static void DumpObject(TaggedObject *obj, case JSType::JS_EVAL_ERROR: case JSType::JS_RANGE_ERROR: case JSType::JS_TYPE_ERROR: + case JSType::JS_AGGREGATE_ERROR: case JSType::JS_REFERENCE_ERROR: case JSType::JS_URI_ERROR: case JSType::JS_SYNTAX_ERROR: @@ -3201,6 +3365,18 @@ static void DumpObject(TaggedObject *obj, case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: JSPromiseAllResolveElementFunction::Cast(obj)->DumpForSnapshot(vec); return; + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: + JSPromiseAnyRejectElementFunction::Cast(obj)->DumpForSnapshot(vec); + return; + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: + JSPromiseAllSettledElementFunction::Cast(obj)->DumpForSnapshot(vec); + return; + case JSType::JS_PROMISE_FINALLY_FUNCTION: + JSPromiseFinallyFunction::Cast(obj)->DumpForSnapshot(vec); + return; + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: + JSPromiseValueThunkOrThrowerFunction::Cast(obj)->DumpForSnapshot(vec); + return; case JSType::MICRO_JOB_QUEUE: MicroJobQueue::Cast(obj)->DumpForSnapshot(vec); return; @@ -3257,13 +3433,13 @@ static void DumpObject(TaggedObject *obj, JSNumberFormat::Cast(obj)->DumpForSnapshot(vec); return; case JSType::JS_CJS_MODULE: - JSCjsModule::Cast(obj)->DumpForSnapshot(vec); + CjsModule::Cast(obj)->DumpForSnapshot(vec); return; case JSType::JS_CJS_EXPORTS: - JSCjsExports::Cast(obj)->DumpForSnapshot(vec); + CjsExports::Cast(obj)->DumpForSnapshot(vec); return; case JSType::JS_CJS_REQUIRE: - JSCjsExports::Cast(obj)->DumpForSnapshot(vec); + CjsRequire::Cast(obj)->DumpForSnapshot(vec); return; case JSType::JS_COLLATOR: JSCollator::Cast(obj)->DumpForSnapshot(vec); @@ -3292,6 +3468,18 @@ static void DumpObject(TaggedObject *obj, case JSType::JS_API_ARRAYLIST_ITERATOR: JSAPIArrayListIterator::Cast(obj)->DumpForSnapshot(vec); return; + case JSType::JS_API_LIGHT_WEIGHT_MAP: + JSAPILightWeightMap::Cast(obj)->DumpForSnapshot(vec); + return; + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: + JSAPILightWeightMapIterator::Cast(obj)->DumpForSnapshot(vec); + return; + case JSType::JS_API_LIGHT_WEIGHT_SET: + JSAPILightWeightSet::Cast(obj)->DumpForSnapshot(vec); + return; + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: + JSAPILightWeightSetIterator::Cast(obj)->DumpForSnapshot(vec); + return; case JSType::JS_API_TREE_MAP: JSAPITreeMap::Cast(obj)->DumpForSnapshot(vec); return; @@ -3694,7 +3882,7 @@ void JSPrimitiveRef::DumpForSnapshot(std::vector> &vec) const { - vec.push_back(std::make_pair(CString("Data"), GetData())); + vec.push_back(std::make_pair(CString("Length"), JSTaggedValue(GetLength()))); vec.push_back(std::make_pair(CString("Sign"), JSTaggedValue(GetSign()))); } @@ -3804,6 +3992,21 @@ void JSAPIArrayListIterator::DumpForSnapshot(std::vector> &vec) const +{ + JSObject::DumpForSnapshot(vec); +} + +void JSAPILightWeightMapIterator::DumpForSnapshot(std::vector> &vec) const +{ + JSAPILightWeightMap *map = + JSAPILightWeightMap::Cast(GetIteratedLightWeightMap().GetTaggedObject()); + map->DumpForSnapshot(vec); + vec.push_back(std::make_pair(CString("NextIndex"), JSTaggedValue(GetNextIndex()))); + vec.push_back(std::make_pair(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind())))); + JSObject::DumpForSnapshot(vec); +} + void JSAPIQueue::DumpForSnapshot(std::vector> &vec) const { JSObject::DumpForSnapshot(vec); @@ -3829,6 +4032,22 @@ void JSAPIDequeIterator::DumpForSnapshot(std::vector> &vec) const +{ + JSObject::DumpForSnapshot(vec); +} + +void JSAPILightWeightSetIterator::DumpForSnapshot(std::vector> &vec) const +{ + JSAPILightWeightSet *set = + JSAPILightWeightSet::Cast(GetIteratedLightWeightSet().GetTaggedObject()); + set->DumpForSnapshot(vec); + vec.push_back(std::make_pair(CString("NextIndex"), JSTaggedValue(GetNextIndex()))); + vec.push_back(std::make_pair(CString("IterationKind"), JSTaggedValue(static_cast(GetIterationKind())))); + JSObject::DumpForSnapshot(vec); +} + void JSAPIStack::DumpForSnapshot(std::vector> &vec) const { JSObject::DumpForSnapshot(vec); @@ -3884,7 +4103,7 @@ void JSRegExp::DumpForSnapshot(std::vector> &v { vec.push_back(std::make_pair(CString("originalSource"), GetOriginalSource())); vec.push_back(std::make_pair(CString("originalFlags"), GetOriginalFlags())); - + vec.push_back(std::make_pair(CString("groupName"), GetGroupName())); JSObject::DumpForSnapshot(vec); } @@ -3951,6 +4170,7 @@ void GlobalEnv::DumpForSnapshot(std::vector> & vec.push_back(std::make_pair(CString("RangeErrorFunction"), GetRangeErrorFunction().GetTaggedValue())); vec.push_back(std::make_pair(CString("ReferenceErrorFunction"), GetReferenceErrorFunction().GetTaggedValue())); vec.push_back(std::make_pair(CString("TypeErrorFunction"), GetTypeErrorFunction().GetTaggedValue())); + vec.push_back(std::make_pair(CString("AggregateErrorFunction"), GetAggregateErrorFunction().GetTaggedValue())); vec.push_back(std::make_pair(CString("URIErrorFunction"), GetURIErrorFunction().GetTaggedValue())); vec.push_back(std::make_pair(CString("SyntaxErrorFunction"), GetSyntaxErrorFunction().GetTaggedValue())); vec.push_back(std::make_pair(CString("EvalErrorFunction"), GetEvalErrorFunction().GetTaggedValue())); @@ -4048,6 +4268,10 @@ void GlobalEnv::DumpForSnapshot(std::vector> & vec.push_back(std::make_pair(CString("Undefined"), globalConst->GetUndefined())); vec.push_back(std::make_pair(CString("ArrayListFunction"), globalConst->GetArrayListFunction())); vec.push_back(std::make_pair(CString("ArrayListIteratorPrototype"), globalConst->GetArrayListIteratorPrototype())); + vec.push_back( + std::make_pair(CString("LightWeightMapIteratorPrototype"), globalConst->GetLightWeightMapIteratorPrototype())); + vec.push_back( + std::make_pair(CString("LightWeightSetIteratorPrototype"), globalConst->GetLightWeightSetIteratorPrototype())); vec.push_back(std::make_pair(CString("TreeMapIteratorPrototype"), globalConst->GetTreeMapIteratorPrototype())); vec.push_back(std::make_pair(CString("TreeSetIteratorPrototype"), globalConst->GetTreeSetIteratorPrototype())); vec.push_back(std::make_pair(CString("VectorFunction"), globalConst->GetVectorFunction())); @@ -4141,6 +4365,39 @@ void JSPromiseAllResolveElementFunction::DumpForSnapshot(std::vector> &vec) const +{ + vec.push_back(std::make_pair(CString("index"), JSTaggedValue(GetIndex()))); + vec.push_back(std::make_pair(CString("errors"), GetErrors())); + vec.push_back(std::make_pair(CString("capability"), GetCapability())); + vec.push_back(std::make_pair(CString("remaining-elements"), GetRemainingElements())); + vec.push_back(std::make_pair(CString("already-called"), GetAlreadyCalled())); + JSObject::DumpForSnapshot(vec); +} + +void JSPromiseAllSettledElementFunction::DumpForSnapshot(std::vector> &vec) const +{ + vec.push_back(std::make_pair(CString("already-called"), GetAlreadyCalled())); + vec.push_back(std::make_pair(CString("index"), JSTaggedValue(GetIndex()))); + vec.push_back(std::make_pair(CString("values"), GetValues())); + vec.push_back(std::make_pair(CString("capability"), GetCapability())); + vec.push_back(std::make_pair(CString("remaining-elements"), GetRemainingElements())); + JSObject::DumpForSnapshot(vec); +} + +void JSPromiseFinallyFunction::DumpForSnapshot(std::vector> &vec) const +{ + vec.push_back(std::make_pair(CString("constructor"), GetConstructor())); + vec.push_back(std::make_pair(CString("onFinally"), GetOnFinally())); + JSObject::DumpForSnapshot(vec); +} + +void JSPromiseValueThunkOrThrowerFunction::DumpForSnapshot(std::vector> &vec) const +{ + vec.push_back(std::make_pair(CString("result"), GetResult())); + JSObject::DumpForSnapshot(vec); +} + void MicroJobQueue::DumpForSnapshot(std::vector> &vec) const { vec.push_back(std::make_pair(CString("promise-job-queue"), GetPromiseJobQueue())); @@ -4390,7 +4647,8 @@ void TSClassType::DumpForSnapshot(std::vector> vec.push_back(std::make_pair(CString("InstanceType"), GetInstanceType())); vec.push_back(std::make_pair(CString("ConstructorType"), GetConstructorType())); vec.push_back(std::make_pair(CString("PrototypeType"), GetPrototypeType())); - vec.push_back(std::make_pair(CString("ExtensionType"), GetExtensionType())); + vec.push_back(std::make_pair(CString("ExtensionGTRawData"), JSTaggedValue(GetExtensionGTRawData()))); + vec.push_back(std::make_pair(CString("HasLinked"), JSTaggedValue(GetHasLinked()))); } void TSInterfaceType::DumpForSnapshot(std::vector> &vec) const @@ -4468,7 +4726,7 @@ void ModuleNamespace::DumpForSnapshot(std::vector> &vec) const +void CjsModule::DumpForSnapshot(std::vector> &vec) const { vec.push_back(std::make_pair(CString("Id"), GetId())); vec.push_back(std::make_pair(CString("Path"), GetPath())); @@ -4476,12 +4734,12 @@ void JSCjsModule::DumpForSnapshot(std::vector> vec.push_back(std::make_pair(CString("Filename"), GetFilename())); } -void JSCjsExports::DumpForSnapshot(std::vector> &vec) const +void CjsExports::DumpForSnapshot(std::vector> &vec) const { vec.push_back(std::make_pair(CString("Exports"), GetExports())); } -void JSCjsRequire::DumpForSnapshot(std::vector> &vec) const +void CjsRequire::DumpForSnapshot(std::vector> &vec) const { vec.push_back(std::make_pair(CString("Cache"), GetCache())); vec.push_back(std::make_pair(CString("Parent"), GetParent())); diff --git a/ecmascript/ecma_global_storage-inl.h b/ecmascript/ecma_global_storage-inl.h deleted file mode 100644 index 2cfdb249e1a38e4d0d6c99c821029fe9806833c2..0000000000000000000000000000000000000000 --- a/ecmascript/ecma_global_storage-inl.h +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef ECMASCRIPT_ECMA_GLOABL_STORAGE_INL_H -#define ECMASCRIPT_ECMA_GLOABL_STORAGE_INL_H - -#include "ecmascript/ecma_global_storage.h" -#include "ecmascript/mem/chunk.h" - -namespace panda::ecmascript { -template -inline EcmaGlobalStorage::NodeList *EcmaGlobalStorage::NodeList::NodeToNodeList(T *node) -{ - uintptr_t ptr = ToUintPtr(node) - node->GetIndex() * sizeof(T); - return reinterpret_cast *>(ptr); -} - -template -T *EcmaGlobalStorage::NodeList::NewNode(JSTaggedType value) -{ - if (IsFull()) { - return nullptr; - } - T *node = &nodeList_[index_++]; - node->SetPrev(nullptr); - node->SetNext(usedList_); - node->SetObject(value); - node->SetUsing(true); - if (usedList_ != nullptr) { - usedList_->SetPrev(node); - } - usedList_ = node; - return node; -} - -template -void EcmaGlobalStorage::NodeList::FreeNode(T *node) -{ - if (node->GetPrev() != nullptr) { - node->GetPrev()->SetNext(node->GetNext()); - } - if (node->GetNext() != nullptr) { - node->GetNext()->SetPrev(node->GetPrev()); - } - if (node == usedList_) { - usedList_ = reinterpret_cast(node->GetNext()); - } - node->SetPrev(nullptr); - node->SetNext(freeList_); - node->SetObject(JSTaggedValue::Undefined().GetRawData()); - node->SetUsing(false); - if (node->IsWeak()) { - reinterpret_cast(node)->SetReference(nullptr); - reinterpret_cast(node)->SetCallback(nullptr); - } - if (freeList_ != nullptr) { - freeList_->SetPrev(node); - } - freeList_ = node; -} - -template -T *EcmaGlobalStorage::NodeList::GetFreeNode(JSTaggedType value) -{ - T *node = freeList_; - if (node != nullptr) { - freeList_ = reinterpret_cast(node->GetNext()); - - node->SetPrev(nullptr); - node->SetNext(usedList_); - node->SetObject(value); - node->SetUsing(true); - if (usedList_ != nullptr) { - usedList_->SetPrev(node); - } - usedList_ = node; - } - return node; -} - -template -void EcmaGlobalStorage::NodeList::LinkTo(NodeList *prev) -{ - next_ = nullptr; - prev_ = prev; - prev_->next_ = this; -} - -template -void EcmaGlobalStorage::NodeList::RemoveList() -{ - if (next_ != nullptr) { - next_->SetPrev(prev_); - } - if (prev_ != nullptr) { - prev_->SetNext(next_); - } - if (freeNext_ != nullptr) { - freeNext_->SetFreePrev(freePrev_); - } - if (freePrev_ != nullptr) { - freePrev_->SetFreeNext(freeNext_); - } -} - -template -uintptr_t EcmaGlobalStorage::NewGlobalHandleImplement(NodeList **storage, NodeList **freeList, JSTaggedType value) -{ -#if ECMASCRIPT_ENABLE_NEW_HANDLE_CHECK - thread_->CheckJSTaggedType(value); -#endif - if (!(*storage)->IsFull()) { - // alloc new block - T *node = (*storage)->NewNode(value); - ASSERT(node != nullptr); - return node->GetObjectAddress(); - } - if (*freeList != nullptr) { - // use free_list node - Node *node = (*freeList)->GetFreeNode(value); - ASSERT(node != nullptr); - if (!(*freeList)->HasFreeNode()) { - auto next = (*freeList)->GetFreeNext(); - (*freeList)->SetFreeNext(nullptr); - (*freeList)->SetFreePrev(nullptr); - if (next != nullptr) { - next->SetFreePrev(nullptr); - } - *freeList = next; - } - return node->GetObjectAddress(); - } - auto block = chunk_->New>(); - block->LinkTo(*storage); - *storage = block; - - // use node in block finally - T *node = (*storage)->NewNode(value); - ASSERT(node != nullptr); - return node->GetObjectAddress(); -} - -inline uintptr_t EcmaGlobalStorage::NewGlobalHandle(JSTaggedType value) -{ - uintptr_t ret = NewGlobalHandleImplement(&lastGlobalNodes_, &freeListNodes_, value); - return ret; -} - -template -inline void EcmaGlobalStorage::DisposeGlobalHandle(T *node, NodeList **freeList, NodeList **topNodes, - NodeList **lastNodes) -{ - NodeList *list = NodeList::NodeToNodeList(node); - list->FreeNode(node); - - // If NodeList has no usage node, then delete NodeList - if (!list->HasUsagedNode() && (*topNodes != *lastNodes)) { - list->RemoveList(); - if (*freeList == list) { - *freeList = list->GetNext(); - } - if (*topNodes == list) { - *topNodes = list->GetNext(); - } - if (*lastNodes == list) { - *lastNodes = list->GetPrev(); - } - chunk_->Delete(list); - } else { - // Add to freeList - if (list != *freeList && list->GetFreeNext() == nullptr && list->GetFreePrev() == nullptr) { - list->SetFreeNext(*freeList); - if (*freeList != nullptr) { - (*freeList)->SetFreePrev(list); - } - *freeList = list; - } - } -} - -inline void EcmaGlobalStorage::DisposeGlobalHandle(uintptr_t nodeAddr) -{ - Node *node = reinterpret_cast(nodeAddr); - if (!node->IsUsing()) { - return; - } - if (node->IsWeak()) { - DisposeGlobalHandle(reinterpret_cast(node), &weakFreeListNodes_, &topWeakGlobalNodes_, - &lastWeakGlobalNodes_); - } else { - DisposeGlobalHandle(node, &freeListNodes_, &topGlobalNodes_, &lastGlobalNodes_); - } -} - -inline uintptr_t EcmaGlobalStorage::SetWeak(uintptr_t nodeAddr, void *ref, WeakClearCallback callback) -{ - auto value = reinterpret_cast(nodeAddr)->GetObject(); - DisposeGlobalHandle(nodeAddr); - uintptr_t addr = NewGlobalHandleImplement(&lastWeakGlobalNodes_, &weakFreeListNodes_, value); - WeakNode *node = reinterpret_cast(addr); - node->SetReference(ref); - node->SetCallback(callback); - return addr; -} - -inline uintptr_t EcmaGlobalStorage::ClearWeak(uintptr_t nodeAddr) -{ - auto value = reinterpret_cast(nodeAddr)->GetObject(); - DisposeGlobalHandle(nodeAddr); - uintptr_t ret = NewGlobalHandleImplement(&lastGlobalNodes_, &freeListNodes_, value); - return ret; -} - -inline bool EcmaGlobalStorage::IsWeak(uintptr_t addr) const -{ - Node *node = reinterpret_cast(addr); - return node->IsWeak(); -} -} // namespace panda::ecmascript -#endif // ECMASCRIPT_ECMA_GLOABL_STORAGE_INL_H diff --git a/ecmascript/ecma_global_storage.h b/ecmascript/ecma_global_storage.h index 1bd22f61f85c73359f56cf43e622960c8b63f4cb..12aba77217a4021e19a9fab03bd3ec61170b5a5a 100644 --- a/ecmascript/ecma_global_storage.h +++ b/ecmascript/ecma_global_storage.h @@ -174,15 +174,93 @@ public: } ~NodeList() = default; - inline static NodeList *NodeToNodeList(T *node); + inline static NodeList *NodeToNodeList(T *node) + { + uintptr_t ptr = ToUintPtr(node) - node->GetIndex() * sizeof(T); + return reinterpret_cast *>(ptr); + } - inline T *NewNode(JSTaggedType value); - inline T *GetFreeNode(JSTaggedType value); + inline T *NewNode(JSTaggedType value) + { + if (IsFull()) { + return nullptr; + } + T *node = &nodeList_[index_++]; + node->SetPrev(nullptr); + node->SetNext(usedList_); + node->SetObject(value); + node->SetUsing(true); + if (usedList_ != nullptr) { + usedList_->SetPrev(node); + } + usedList_ = node; + return node; + } - inline void FreeNode(T *node); + inline T *GetFreeNode(JSTaggedType value) + { + T *node = freeList_; + if (node != nullptr) { + freeList_ = reinterpret_cast(node->GetNext()); + + node->SetPrev(nullptr); + node->SetNext(usedList_); + node->SetObject(value); + node->SetUsing(true); + if (usedList_ != nullptr) { + usedList_->SetPrev(node); + } + usedList_ = node; + } + return node; + } - inline void LinkTo(NodeList *prev); - inline void RemoveList(); + inline void FreeNode(T *node) + { + if (node->GetPrev() != nullptr) { + node->GetPrev()->SetNext(node->GetNext()); + } + if (node->GetNext() != nullptr) { + node->GetNext()->SetPrev(node->GetPrev()); + } + if (node == usedList_) { + usedList_ = reinterpret_cast(node->GetNext()); + } + node->SetPrev(nullptr); + node->SetNext(freeList_); + node->SetObject(JSTaggedValue::Undefined().GetRawData()); + node->SetUsing(false); + if (node->IsWeak()) { + reinterpret_cast(node)->SetReference(nullptr); + reinterpret_cast(node)->SetCallback(nullptr); + } + if (freeList_ != nullptr) { + freeList_->SetPrev(node); + } + freeList_ = node; + } + + inline void LinkTo(NodeList *prev) + { + next_ = nullptr; + prev_ = prev; + prev_->next_ = this; + } + inline void RemoveList() + { + if (next_ != nullptr) { + next_->SetPrev(prev_); + } + if (prev_ != nullptr) { + prev_->SetNext(next_); + } + if (freeNext_ != nullptr) { + freeNext_->SetFreePrev(freePrev_); + } + if (freePrev_ != nullptr) { + freePrev_->SetFreeNext(freeNext_); + } + } inline bool IsFull() { @@ -259,11 +337,49 @@ public: NodeList *freePrev_ {nullptr}; }; - inline uintptr_t NewGlobalHandle(JSTaggedType value); - inline void DisposeGlobalHandle(uintptr_t addr); - inline uintptr_t SetWeak(uintptr_t addr, void *ref = nullptr, WeakClearCallback callback = nullptr); - inline uintptr_t ClearWeak(uintptr_t addr); - inline bool IsWeak(uintptr_t addr) const; + inline uintptr_t NewGlobalHandle(JSTaggedType value) + { + uintptr_t ret = NewGlobalHandleImplement(&lastGlobalNodes_, &freeListNodes_, value); + return ret; + } + + inline void DisposeGlobalHandle(uintptr_t nodeAddr) + { + Node *node = reinterpret_cast(nodeAddr); + if (!node->IsUsing()) { + return; + } + if (node->IsWeak()) { + DisposeGlobalHandle(reinterpret_cast(node), &weakFreeListNodes_, &topWeakGlobalNodes_, + &lastWeakGlobalNodes_); + } else { + DisposeGlobalHandle(node, &freeListNodes_, &topGlobalNodes_, &lastGlobalNodes_); + } + } + + inline uintptr_t SetWeak(uintptr_t nodeAddr, void *ref = nullptr, WeakClearCallback callback = nullptr) + { + auto value = reinterpret_cast(nodeAddr)->GetObject(); + DisposeGlobalHandle(nodeAddr); + uintptr_t addr = NewGlobalHandleImplement(&lastWeakGlobalNodes_, &weakFreeListNodes_, value); + WeakNode *node = reinterpret_cast(addr); + node->SetReference(ref); + node->SetCallback(callback); + return addr; + } + + inline uintptr_t ClearWeak(uintptr_t nodeAddr) + { + auto value = reinterpret_cast(nodeAddr)->GetObject(); + DisposeGlobalHandle(nodeAddr); + uintptr_t ret = NewGlobalHandleImplement(&lastGlobalNodes_, &freeListNodes_, value); + return ret; + } + inline bool IsWeak(uintptr_t addr) const + { + Node *node = reinterpret_cast(addr); + return node->IsWeak(); + } template void IterateUsageGlobal(Callback callback) @@ -296,10 +412,73 @@ private: NO_MOVE_SEMANTIC(EcmaGlobalStorage); template - inline void DisposeGlobalHandle(T *node, NodeList **freeLis, NodeList **topNodes, - NodeList **lastNodes); + inline void DisposeGlobalHandle(T *node, NodeList **freeList, NodeList **topNodes, + NodeList **lastNodes) + { + NodeList *list = NodeList::NodeToNodeList(node); + list->FreeNode(node); + + // If NodeList has no usage node, then delete NodeList + if (!list->HasUsagedNode() && (*topNodes != *lastNodes)) { + list->RemoveList(); + if (*freeList == list) { + *freeList = list->GetNext(); + } + if (*topNodes == list) { + *topNodes = list->GetNext(); + } + if (*lastNodes == list) { + *lastNodes = list->GetPrev(); + } + chunk_->Delete(list); + } else { + // Add to freeList + if (list != *freeList && list->GetFreeNext() == nullptr && list->GetFreePrev() == nullptr) { + list->SetFreeNext(*freeList); + if (*freeList != nullptr) { + (*freeList)->SetFreePrev(list); + } + *freeList = list; + } + } + } + template - inline uintptr_t NewGlobalHandleImplement(NodeList **storage, NodeList **freeList, JSTaggedType value); + inline uintptr_t NewGlobalHandleImplement(NodeList **storage, NodeList **freeList, JSTaggedType value) + { + #if ECMASCRIPT_ENABLE_NEW_HANDLE_CHECK + thread_->CheckJSTaggedType(value); + #endif + if (!(*storage)->IsFull()) { + // alloc new block + T *node = (*storage)->NewNode(value); + ASSERT(node != nullptr); + return node->GetObjectAddress(); + } + if (*freeList != nullptr) { + // use free_list node + Node *node = (*freeList)->GetFreeNode(value); + ASSERT(node != nullptr); + if (!(*freeList)->HasFreeNode()) { + auto next = (*freeList)->GetFreeNext(); + (*freeList)->SetFreeNext(nullptr); + (*freeList)->SetFreePrev(nullptr); + if (next != nullptr) { + next->SetFreePrev(nullptr); + } + *freeList = next; + } + return node->GetObjectAddress(); + } + auto block = chunk_->New>(); + block->LinkTo(*storage); + *storage = block; + + // use node in block finally + T *node = (*storage)->NewNode(value); + ASSERT(node != nullptr); + return node->GetObjectAddress(); + } [[maybe_unused]] JSThread *thread_ {nullptr}; Chunk *chunk_ {nullptr}; diff --git a/ecmascript/ecma_macros.h b/ecmascript/ecma_macros.h index c96755861d3a2e99afc3b2234b950d831885171a..951171cde6b80db97916c203fb1267eac89acb2a 100644 --- a/ecmascript/ecma_macros.h +++ b/ecmascript/ecma_macros.h @@ -17,6 +17,7 @@ #define ECMASCRIPT_ECMA_MACROS_H #include "ecmascript/common.h" +#include "ecmascript/log_wrapper.h" #include "libpandabase/trace/trace.h" #if defined(ENABLE_BYTRACE) @@ -25,16 +26,9 @@ #if defined(__cplusplus) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define LOG_ECMA(type) \ - LOG(type, ECMASCRIPT) << __func__ << " Line:" << __LINE__ << " " // NOLINT(bugprone-lambda-function-name) -#define ECMA_GC_LOG() LOG(DEBUG, ECMASCRIPT) << " ecmascript gc log: " - -#define OPTIONAL_LOG(ecmaVM, level, component) \ - LOG_IF(ecmaVM->IsOptionalLogEnabled(), level, component) - -#define COMPILER_LOG(level) LOG(level, ECMASCRIPT) -#define COMPILER_OPTIONAL_LOG(level) LOG_IF(IsLogEnabled(), level, ECMASCRIPT) +#define OPTIONAL_LOG(vm, level) LOG_ECMA_IF(vm->IsOptionalLogEnabled(), level) +#define OPTIONAL_LOG_COMPILER(level) LOG_ECMA_IF(IsLogEnabled(), level) #if !defined(ENABLE_BYTRACE) #define ECMA_BYTRACE_NAME(tag, name) trace::ScopedTrace scopedTrace(name) @@ -42,6 +36,14 @@ #define ECMA_BYTRACE_NAME(tag, name) HITRACE_METER_NAME(tag, name); trace::ScopedTrace scopedTrace(name) #endif +#if defined(ENABLE_HITRACE) + #define ENQUEUE_JOB_HITRACE(pendingJob, queueType) job::EnqueueJobScope hitraceScope(pendingJob, queueType) + #define EXECUTE_JOB_HITRACE(pendingJob) job::ExecuteJobScope hitraceScope(pendingJob) +#else + #define ENQUEUE_JOB_HITRACE(pendingJob, queueType) + #define EXECUTE_JOB_HITRACE(pendingJob) +#endif + /* Note: We can't statically decide the element type is a primitive or heap object, especially for */ /* dynamically-typed languages like JavaScript. So we simply skip the read-barrier. */ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -361,10 +363,11 @@ if (record->IsThrow()) { \ JSHandle reject(thread, (capability)->GetReject()); \ JSHandle undefine = globalConst->GetHandledUndefined(); \ - EcmaRuntimeCallInfo info = \ + EcmaRuntimeCallInfo *info = \ EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefine, undefine, 1); \ - info.SetCallArg(record->GetValue()); \ - JSTaggedValue res = JSFunction::Call(&info); \ + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); \ + info->SetCallArg(record->GetValue()); \ + JSTaggedValue res = JSFunction::Call(info); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, res); \ return (capability)->GetPromise(); \ } \ @@ -373,10 +376,11 @@ (thread)->ClearException(); \ JSHandle reject(thread, (capability)->GetReject()); \ JSHandle undefined = globalConst->GetHandledUndefined(); \ - EcmaRuntimeCallInfo info = \ + EcmaRuntimeCallInfo *info = \ EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); \ - info.SetCallArg(value.GetTaggedValue()); \ - JSTaggedValue res = JSFunction::Call(&info); \ + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); \ + info->SetCallArg(value.GetTaggedValue()); \ + JSTaggedValue res = JSFunction::Call(info); \ RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, res); \ return (capability)->GetPromise(); \ } \ @@ -405,7 +409,7 @@ // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define DECL_CAST(TYPE) \ - static TYPE *Cast(ObjectHeader *object) \ + static TYPE *Cast(TaggedObject *object) \ { \ ASSERT(JSTaggedValue(object).Is##TYPE()); \ return reinterpret_cast(object); \ @@ -457,14 +461,14 @@ #if ECMASCRIPT_ENABLE_CAST_CHECK #define CAST_CHECK(CAST_TYPE, CHECK_METHOD) \ - static inline CAST_TYPE *Cast(ObjectHeader *object) \ + static inline CAST_TYPE *Cast(TaggedObject *object) \ { \ if (!JSTaggedValue(object).CHECK_METHOD()) { \ std::abort(); \ } \ return static_cast(object); \ } \ - static inline const CAST_TYPE *ConstCast(const ObjectHeader *object) \ + static inline const CAST_TYPE *ConstCast(const TaggedObject *object) \ { \ if (!JSTaggedValue(object).CHECK_METHOD()) { \ std::abort(); \ @@ -473,23 +477,23 @@ } # else #define CAST_CHECK(CAST_TYPE, CHECK_METHOD) \ - static inline CAST_TYPE *Cast(ObjectHeader *object) \ + static inline CAST_TYPE *Cast(TaggedObject *object) \ { \ ASSERT(JSTaggedValue(object).CHECK_METHOD()); \ return static_cast(object); \ } \ - static const inline CAST_TYPE *ConstCast(const ObjectHeader *object) \ + static const inline CAST_TYPE *ConstCast(const TaggedObject *object) \ { \ ASSERT(JSTaggedValue(object).CHECK_METHOD()); \ return static_cast(object); \ } #define CAST_NO_CHECK(CAST_TYPE) \ - static inline CAST_TYPE *Cast(ObjectHeader *object) \ + static inline CAST_TYPE *Cast(TaggedObject *object) \ { \ return static_cast(object); \ } \ - static const inline CAST_TYPE *ConstCast(const ObjectHeader *object) \ + static const inline CAST_TYPE *ConstCast(const TaggedObject *object) \ { \ return static_cast(object); \ } @@ -513,19 +517,14 @@ } #endif -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define CHECK_DUMP_FIELDS(begin, end, num) \ - LOG_IF((num) != ((end) - (begin)) / JSTaggedValue::TaggedTypeSize(), FATAL, RUNTIME) \ - << "Fields in obj are not in dump list. "; - -#define CHECK_OBJECT_SIZE(size) \ - if ((size) == 0) { \ - LOG(FATAL, ECMASCRIPT) << __func__ << " Line: " << __LINE__ << " objectSize is " << (size); \ +#define CHECK_OBJECT_SIZE(size) \ + if ((size) == 0) { \ + LOG_FULL(FATAL) << __func__ << ":" << __LINE__ << " objectSize is " << (size); \ } -#define CHECK_REGION_END(begin, end) \ - if ((begin) > (end)) { \ - LOG(FATAL, ECMASCRIPT) << __func__ << " Line: " << __LINE__ << " begin: " << (begin) << " end: " << (end); \ +#define CHECK_REGION_END(begin, end) \ + if ((begin) > (end)) { \ + LOG_FULL(FATAL) << __func__ << ":" << __LINE__ << " begin: " << (begin) << " end: " << (end); \ } #define CHECK_JS_THREAD(vm) ASSERT(vm->GetJSThread()->GetThreadId() == JSThread::GetCurrentThreadId()) diff --git a/ecmascript/ecma_param_configuration.h b/ecmascript/ecma_param_configuration.h index 4cd3e720c6cdb585b365b82899cca2a6c44aeb1c..00e9eba1be596f24a1c5634ca98829687888a0a5 100644 --- a/ecmascript/ecma_param_configuration.h +++ b/ecmascript/ecma_param_configuration.h @@ -19,17 +19,155 @@ #include "libpandabase/mem/mem.h" namespace panda::ecmascript { - // MEMEORY SIZE SHOULD ROUND UP TO 256KB - static constexpr size_t MAX_HEAP_SIZE = 256_MB; // Recommended range: 128-256MB - static constexpr size_t DEFAULT_SEMI_SPACE_SIZE = 2_MB; // Recommended range: 2-4MB - static constexpr size_t MAX_SEMI_SPACE_SIZE = 16_MB; // Recommended range: 2-16MB - static constexpr size_t DEFAULT_NONMOVABLE_SPACE_SIZE = 4_MB; // Recommended range: 4-8MB - static constexpr size_t DEFAULT_SNAPSHOT_SPACE_SIZE = 256_KB; - static constexpr size_t MAX_SNAPSHOT_SPACE_SIZE = 8_MB; - static constexpr size_t DEFAULT_MACHINECODE_SPACE_SIZE = 8_MB; - - static constexpr size_t MIN_AllOC_LIMIT_GROWING_STEP = 8_MB; - static constexpr uint32_t MAX_STACK_SIZE = 512_KB; +static constexpr size_t DEFAULT_HEAP_SIZE = 256_MB; // Recommended range: 128-256MB +static constexpr size_t DEFAULT_WORKER_HEAP_SIZE = 64_MB; // Recommended range: 64_MB + +class EcmaParamConfiguration { +public: + EcmaParamConfiguration(bool isWorker, size_t poolSize) + { + if (isWorker) { + maxHeapSize_ = DEFAULT_WORKER_HEAP_SIZE; + } else { + if (poolSize >= DEFAULT_HEAP_SIZE) { + maxHeapSize_ = DEFAULT_HEAP_SIZE; + } else { + maxHeapSize_ = poolSize; // pool is too small, no memory left for worker + } + } + Initialize(); + } + + void Initialize() + { + if (maxHeapSize_ < LOW_MEMORY) { + UNREACHABLE(); + } + if (maxHeapSize_ < MEDIUM_MEMORY) { // 64_MB ~ 128_MB + minSemiSpaceSize_ = 2_MB; + maxSemiSpaceSize_ = 4_MB; + defaultReadOnlySpaceSize_ = 256_KB; + defaultNonMovableSpaceSize_ = 2_MB; + defaultSnapshotSpaceSize_ = 512_KB; + defaultMachineCodeSpaceSize_ = 2_MB; + semiSpaceTriggerConcurrentMark_ = 1_MB; + semiSpaceOvershootSize_ = 2_MB; + minAllocLimitGrowingStep_ = 2_MB; + minGrowingStep_ = 4_MB; + maxStackSize_ = 512_KB; + } else if (maxHeapSize_ < HIGH_MEMORY) { // 128_MB ~ 256_MB + minSemiSpaceSize_ = 2_MB; + maxSemiSpaceSize_ = 8_MB; + defaultReadOnlySpaceSize_ = 256_KB; + defaultNonMovableSpaceSize_ = 4_MB; + defaultSnapshotSpaceSize_ = 512_KB; + defaultMachineCodeSpaceSize_ = 2_MB; + semiSpaceTriggerConcurrentMark_ = 1.5_MB; + semiSpaceOvershootSize_ = 2_MB; + minAllocLimitGrowingStep_ = 4_MB; + minGrowingStep_ = 8_MB; + maxStackSize_ = 512_KB; + } else { // 256_MB + minSemiSpaceSize_ = 2_MB; + maxSemiSpaceSize_ = 16_MB; + defaultReadOnlySpaceSize_ = 256_KB; + defaultNonMovableSpaceSize_ = 4_MB; + defaultSnapshotSpaceSize_ = 4_MB; + defaultMachineCodeSpaceSize_ = 8_MB; + semiSpaceTriggerConcurrentMark_ = 1.5_MB; + semiSpaceOvershootSize_ = 2_MB; + minAllocLimitGrowingStep_ = 8_MB; + minGrowingStep_ = 16_MB; + maxStackSize_ = 512_KB; + } + size_t half = 2; + defaultHugeObjectSpaceSize_ = maxHeapSize_ / half; + } + + size_t GetMaxHeapSize() const + { + return maxHeapSize_; + } + + size_t GetMinSemiSpaceSize() const + { + return minSemiSpaceSize_; + } + + size_t GetMaxSemiSpaceSize() const + { + return maxSemiSpaceSize_; + } + + size_t GetDefaultReadOnlySpaceSize() const + { + return defaultReadOnlySpaceSize_; + } + + size_t GetDefaultNonMovableSpaceSize() const + { + return defaultNonMovableSpaceSize_; + } + + size_t GetDefaultSnapshotSpaceSize() const + { + return defaultSnapshotSpaceSize_; + } + + size_t GetDefaultMachineCodeSpaceSize() const + { + return defaultMachineCodeSpaceSize_; + } + + size_t GetSemiSpaceTriggerConcurrentMark() const + { + return semiSpaceTriggerConcurrentMark_; + } + + size_t GetSemiSpaceOvershootSize() const + { + return semiSpaceOvershootSize_; + } + + size_t GetDefaultHugeObjectSpaceSize() const + { + return defaultHugeObjectSpaceSize_; + } + + size_t GetMinAllocLimitGrowingStep() const + { + return minAllocLimitGrowingStep_; + } + + size_t GetMinGrowingStep() const + { + return minGrowingStep_; + } + + uint32_t GetMaxStackSize() const + { + return maxStackSize_; + } + +private: + static constexpr size_t LOW_MEMORY = 64_MB; + static constexpr size_t MEDIUM_MEMORY = 128_MB; + static constexpr size_t HIGH_MEMORY = 256_MB; + + size_t maxHeapSize_ {0}; + size_t minSemiSpaceSize_ {0}; + size_t maxSemiSpaceSize_ {0}; + size_t defaultReadOnlySpaceSize_ {0}; + size_t defaultNonMovableSpaceSize_ {0}; + size_t defaultSnapshotSpaceSize_ {0}; + size_t defaultMachineCodeSpaceSize_ {0}; + size_t defaultHugeObjectSpaceSize_ {0}; + size_t semiSpaceTriggerConcurrentMark_ {0}; + size_t semiSpaceOvershootSize_ {0}; + size_t minAllocLimitGrowingStep_ {0}; + size_t minGrowingStep_ {0}; + uint32_t maxStackSize_ {0}; +}; } // namespace panda::ecmascript #endif // ECMASCRIPT_ECMA_PARAM_CONFIGURATION_H diff --git a/ecmascript/ecma_runtime_call_info.h b/ecmascript/ecma_runtime_call_info.h index 3a82b42e7cf2436181c3d1023177249a0d8da695..131a4226affa506a7c323187cbf7fd3bcc30c642 100644 --- a/ecmascript/ecma_runtime_call_info.h +++ b/ecmascript/ecma_runtime_call_info.h @@ -25,17 +25,21 @@ #include "ecmascript/tagged_array.h" namespace panda::ecmascript { -class EcmaRuntimeCallInfo; +struct EcmaRuntimeCallInfo; using EcmaEntrypoint = JSTaggedValue (*)(EcmaRuntimeCallInfo *); -class EcmaRuntimeCallInfo { -public: - // For builtins interpreter call - EcmaRuntimeCallInfo(JSThread *thread, size_t numArgs, JSTaggedType *args) - : thread_(thread), numArgs_(numArgs), stackArgs_(args) {} - - ~EcmaRuntimeCallInfo() = default; +struct EcmaRuntimeCallInfo : public base::AlignedStruct { + enum class Index : size_t { + ThreadIndex = 0, + NumArgsIndex, + StackArgsIndex, + NumOfMembers + }; +public: inline JSThread *GetThread() const { return thread_; @@ -56,7 +60,7 @@ public: SetArg(THIS_INDEX, tagged); } - inline void SetCallArg(size_t idx, const JSTaggedValue tagged) + inline void SetCallArg(int32_t idx, const JSTaggedValue tagged) { ASSERT_PRINT(idx < GetArgsNumber(), "Can not set values out of index range"); SetArg(idx + FIRST_ARGS_INDEX, tagged); @@ -97,38 +101,37 @@ public: const JSTaggedValue arg3, const JSTaggedValue arg4) { ASSERT_PRINT(GetArgsNumber() == 5, "args number is not 5"); // 5: args number - SetArg(FIRST_ARGS_INDEX, arg0); SetArg(FIRST_ARGS_INDEX + 1, arg1); SetArg(FIRST_ARGS_INDEX + 2, arg2); // 2: second index SetArg(FIRST_ARGS_INDEX + 3, arg3); // 3: third index - SetArg(FIRST_ARGS_INDEX + 4, arg4); // 4: four index + SetArg(FIRST_ARGS_INDEX + 4, arg4); // 4: fourth index } - inline void SetCallArg(size_t argc, const JSTaggedType argv[]) + inline void SetCallArg(int32_t argc, const JSTaggedType argv[]) { - for (size_t i = 0; i < argc; i++) { + for (int32_t i = 0; i < argc; i++) { SetCallArg(i, JSTaggedValue(argv[i])); } } - inline void SetCallArg(size_t argsLength, const JSHandle args) + inline void SetCallArg(int32_t argsLength, const JSHandle args) { - for (size_t i = 0; i < argsLength; i++) { + for (int32_t i = 0; i < argsLength; i++) { SetCallArg(i, args->Get(thread_, i)); } } - inline void SetCallArg(size_t argsLength, const TaggedArray* args) + inline void SetCallArg(int32_t argsLength, const TaggedArray* args) { - for (size_t i = 0; i < argsLength; i++) { + for (int32_t i = 0; i < argsLength; i++) { SetCallArg(i, args->Get(thread_, i)); } } - inline void SetCallArg(size_t argsLength, size_t startIndex, const EcmaRuntimeCallInfo* argv, size_t offset) + inline void SetCallArg(int32_t argsLength, int32_t startIndex, const EcmaRuntimeCallInfo* argv, int32_t offset) { - for (size_t i = startIndex; i < argsLength; i++) { + for (int32_t i = startIndex; i < argsLength; i++) { SetCallArg(i, argv->GetCallArgValue(i - startIndex + offset)); } } @@ -148,7 +151,7 @@ public: return GetArg(THIS_INDEX); } - inline JSHandle GetCallArg(size_t idx) const + inline JSHandle GetCallArg(int32_t idx) const { return GetArg(idx + FIRST_ARGS_INDEX); } @@ -171,7 +174,7 @@ public: return thisObj.GetTaggedValue(); } - inline JSTaggedValue GetCallArgValue(size_t idx) const + inline JSTaggedValue GetCallArgValue(int32_t idx) const { JSHandle arg = GetCallArg(idx); return arg.GetTaggedValue(); @@ -181,43 +184,28 @@ public: * The number of arguments pairs excluding the 'func', 'new.target' and 'this'. For instance: * for code fragment: " foo(v1); ", GetArgsNumber() returns 1 */ - inline size_t GetArgsNumber() const + inline int32_t GetArgsNumber() const { - return numArgs_; + return numArgs_ - NUM_MANDATORY_JSFUNC_ARGS; } - inline JSTaggedType *GetArgs() const + inline JSTaggedType *GetArgs() { return stackArgs_; } - static constexpr size_t GetThreadOffset() - { - return MEMBER_OFFSET(EcmaRuntimeCallInfo, thread_); - } - - static constexpr size_t GetNumArgsOffset() - { - return MEMBER_OFFSET(EcmaRuntimeCallInfo, numArgs_); - } - - static constexpr size_t GetStackArgsOffset() - { - return MEMBER_OFFSET(EcmaRuntimeCallInfo, stackArgs_); - } - private: enum ArgsIndex : uint8_t { FUNC_INDEX = 0, NEW_TARGET_INDEX, THIS_INDEX, FIRST_ARGS_INDEX }; - inline uintptr_t GetArgAddress(size_t idx) const + inline uintptr_t GetArgAddress(int32_t idx) const { - if (stackArgs_ != nullptr && (idx < static_cast(numArgs_ + NUM_MANDATORY_JSFUNC_ARGS))) { + if (idx < numArgs_) { return reinterpret_cast(&stackArgs_[idx]); } return 0U; } - inline void SetArg(size_t idx, const JSTaggedValue tagged) + inline void SetArg(int32_t idx, const JSTaggedValue tagged) { uintptr_t addr = GetArgAddress(idx); if (addr != 0U) { @@ -225,15 +213,15 @@ private: } } - inline JSHandle GetArg(size_t idx) const + inline JSHandle GetArg(int32_t idx) const { return JSHandle(GetArgAddress(idx)); } private: - JSThread *thread_ {nullptr}; - size_t numArgs_ = 0; - JSTaggedType *stackArgs_ {nullptr}; + alignas(EAS) JSThread *thread_ {nullptr}; + alignas(EAS) int32_t numArgs_ {0}; // include func, newTarget, this, equal to stackArgs size. + __extension__ JSTaggedType stackArgs_[0]; // NOLINT(modernize-avoid-c-arrays) }; } // namespace panda::ecmascript diff --git a/ecmascript/ecma_string-inl.h b/ecmascript/ecma_string-inl.h index 099eb51aedcbdf01186d25369c69e4f5e7a21b07..fe5911016d62bc0cf141f3d95b55a58a5dff21f9 100644 --- a/ecmascript/ecma_string-inl.h +++ b/ecmascript/ecma_string-inl.h @@ -24,7 +24,7 @@ namespace panda::ecmascript { /* static */ -inline EcmaString *EcmaString::Cast(ObjectHeader *object) +inline EcmaString *EcmaString::Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsString()); return static_cast(object); @@ -59,7 +59,7 @@ inline EcmaString *EcmaString::CreateFromUtf8(const uint8_t *utf8Data, uint32_t ASSERT(string != nullptr); if (memcpy_s(string->GetDataUtf8Writable(), utf8Len, utf8Data, utf8Len) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } else { @@ -85,7 +85,7 @@ inline EcmaString *EcmaString::CreateFromUtf8NonMovable(const EcmaVM *vm, const EcmaString *string = AllocStringObjectNonMovable(vm, utf8Len); ASSERT(string != nullptr); if (memcpy_s(string->GetDataUtf8Writable(), utf8Len, utf8Data, utf8Len) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } ASSERT_PRINT(CanBeCompressed(string) == true, "Bad input canBeCompress!"); @@ -106,7 +106,7 @@ inline EcmaString *EcmaString::CreateFromUtf16(const uint16_t *utf16Data, uint32 } else { uint32_t len = utf16Len * (sizeof(uint16_t) / sizeof(uint8_t)); if (memcpy_s(string->GetDataUtf16Writable(), len, utf16Data, len) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -159,7 +159,7 @@ void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, u ASSERT(src->IsUtf8()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (length != 0 && memcpy_s(GetDataUtf8Writable() + start, destSize, src->GetDataUtf8(), length) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } else if (src->IsUtf8()) { @@ -173,7 +173,7 @@ void EcmaString::WriteData(EcmaString *src, uint32_t start, uint32_t destSize, u // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (length != 0 && memcpy_s(GetDataUtf16Writable() + start, ComputeDataSizeUtf16(destSize), src->GetDataUtf16(), ComputeDataSizeUtf16(length)) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } diff --git a/ecmascript/ecma_string.cpp b/ecmascript/ecma_string.cpp index f6e71e533c4c45974c2c256f0a45d70df27ce9ac..713c56b88bfcd6edca04d68f8fbfeac149985269 100644 --- a/ecmascript/ecma_string.cpp +++ b/ecmascript/ecma_string.cpp @@ -179,14 +179,15 @@ int32_t EcmaString::IndexOf(const EcmaString *rhs, int32_t pos) const const EcmaString *lhs = this; int32_t lhsCount = static_cast(lhs->GetLength()); int32_t rhsCount = static_cast(rhs->GetLength()); - if (rhsCount == 0) { - return pos; - } - if (pos >= lhsCount) { + if (pos > lhsCount) { return -1; } + if (rhsCount == 0) { + return pos; + } + if (pos < 0) { pos = 0; } @@ -382,7 +383,7 @@ bool EcmaString::StringCopy(Span &dst, size_t dstMax, Span &src, siz ASSERT(dstMax >= count); ASSERT(dst.Size() >= src.Size()); if (memcpy_s(dst.data(), dstMax, src.data(), count) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } return true; diff --git a/ecmascript/ecma_string.h b/ecmascript/ecma_string.h index ee6ef7e3ef739e12440e37e7aee75d5a9e78c0c2..b915b47b0121db03a1948908c0025e3bdf6ed4be 100644 --- a/ecmascript/ecma_string.h +++ b/ecmascript/ecma_string.h @@ -26,6 +26,7 @@ #include "ecmascript/mem/tagged_object.h" #include "ecmascript/mem/barriers.h" #include "macros.h" +#include "securec.h" namespace panda { namespace ecmascript { @@ -35,7 +36,7 @@ class EcmaVM; class EcmaString : public TaggedObject { public: - static EcmaString *Cast(ObjectHeader *object); + static EcmaString *Cast(TaggedObject *object); static const EcmaString *ConstCast(const TaggedObject *object); static EcmaString *CreateEmptyString(const EcmaVM *vm); @@ -90,7 +91,7 @@ public: const uint16_t *GetDataUtf16() const { - LOG_IF(!IsUtf16(), FATAL, RUNTIME) << "EcmaString: Read data as utf16 for utf8 string"; + LOG_ECMA_IF(!IsUtf16(), FATAL) << "EcmaString: Read data as utf16 for utf8 string"; return GetData(); } @@ -158,20 +159,20 @@ public: } if (!IsUtf16()) { if (length > std::numeric_limits::max() / 2 - 1) { // 2: half - LOG(FATAL, RUNTIME) << " length is higher than half of size_t::max"; + LOG_FULL(FATAL) << " length is higher than half of size_t::max"; UNREACHABLE(); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) // Only memcpy_s maxLength number of chars into buffer if length > maxLength if (length > maxLength) { if (memcpy_s(buf, maxLength, GetDataUtf8() + start, maxLength) != EOK) { - LOG(FATAL, RUNTIME) << "memcpy_s failed when length > maxlength"; + LOG_FULL(FATAL) << "memcpy_s failed when length > maxlength"; UNREACHABLE(); } return maxLength; } if (memcpy_s(buf, maxLength, GetDataUtf8() + start, length) != EOK) { - LOG(FATAL, RUNTIME) << "memcpy_s failed when length <= maxlength"; + LOG_FULL(FATAL) << "memcpy_s failed when length <= maxlength"; UNREACHABLE(); } return length; @@ -200,7 +201,7 @@ public: // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(buf, ComputeDataSizeUtf16(maxLength), GetDataUtf16() + start, ComputeDataSizeUtf16(length)) != EOK) { - LOG(FATAL, RUNTIME) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } return length; @@ -249,7 +250,8 @@ public: uint32_t GetHashcode() { uint32_t hashcode = GetRawHashcode(); - if (hashcode == 0) { + // GetLength() == 0 means it's an empty array.No need to computeHashCode again when hashseed is 0. + if (hashcode == 0 && GetLength() != 0) { hashcode = ComputeHashcode(0); SetRawHashcode(hashcode); } @@ -328,7 +330,7 @@ private: uint16_t *GetDataUtf16Writable() { - LOG_IF(!IsUtf16(), FATAL, RUNTIME) << "EcmaString: Read data as utf16 for utf8 string"; + LOG_ECMA_IF(!IsUtf16(), FATAL) << "EcmaString: Read data as utf16 for utf8 string"; return GetData(); } diff --git a/ecmascript/ecma_string_table.cpp b/ecmascript/ecma_string_table.cpp index fbc09f556a61a35efbb6103eab98712e01d5c63a..8888f258328d96d7b78abc33c1ddf718390a1c30 100644 --- a/ecmascript/ecma_string_table.cpp +++ b/ecmascript/ecma_string_table.cpp @@ -163,13 +163,13 @@ void EcmaStringTable::SweepWeakReference(const WeakRootVisitor &visitor) auto *object = it->second; auto fwd = visitor(object); if (fwd == nullptr) { - LOG(DEBUG, GC) << "StringTable: delete string " << std::hex << object + LOG_ECMA(VERBOSE) << "StringTable: delete string " << std::hex << object << ", val = " << ConvertToString(object); table_.erase(it++); } else if (fwd != object) { it->second = static_cast(fwd); ++it; - LOG(DEBUG, GC) << "StringTable: forward " << std::hex << object << " -> " << fwd; + LOG_ECMA(VERBOSE) << "StringTable: forward " << std::hex << object << " -> " << fwd; } else { ++it; } diff --git a/ecmascript/ecma_vm.cpp b/ecmascript/ecma_vm.cpp index 36cbe22bbd6c4e0857d4b349fc085fa65e56f53a..b83160bff8fa971eecfeffb2a1afdfd6f06292d9 100644 --- a/ecmascript/ecma_vm.cpp +++ b/ecmascript/ecma_vm.cpp @@ -49,7 +49,6 @@ #include "ecmascript/mem/mem.h" #include "ecmascript/mem/space.h" #include "ecmascript/mem/visitor.h" -#include "ecmascript/snapshot/mem/snapshot_env.h" #include "ecmascript/taskpool/task.h" #include "ecmascript/module/js_module_manager.h" #include "ecmascript/object_factory.h" @@ -78,9 +77,14 @@ namespace panda::ecmascript { /* static */ -EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options) +EcmaVM *EcmaVM::Create(const JSRuntimeOptions &options, EcmaParamConfiguration &config) { - auto vm = new EcmaVM(options); + JSRuntimeOptions newOptions = options; + // windows or mac disable asm interpreter and use c interpreter +#if defined(PANDA_TARGET_WINDOWS) || defined(PANDA_TARGET_MACOS) + newOptions.SetEnableAsmInterpreter(false); +#endif + auto vm = new EcmaVM(newOptions, config); if (UNLIKELY(vm == nullptr)) { LOG_ECMA(ERROR) << "Failed to create jsvm"; return nullptr; @@ -102,12 +106,13 @@ bool EcmaVM::Destroy(EcmaVM *vm) return false; } -EcmaVM::EcmaVM(JSRuntimeOptions options) +EcmaVM::EcmaVM(JSRuntimeOptions options, EcmaParamConfiguration config) : stringTable_(new EcmaStringTable(this)), nativeAreaAllocator_(std::make_unique()), heapRegionAllocator_(std::make_unique()), chunk_(nativeAreaAllocator_.get()), - nativePointerList_(&chunk_) + nativePointerList_(&chunk_), + ecmaParamConfiguration_(std::move(config)) { options_ = std::move(options); icEnabled_ = options_.EnableIC(); @@ -121,7 +126,7 @@ EcmaVM::EcmaVM(JSRuntimeOptions options) bool EcmaVM::Initialize() { - LOG(INFO, RUNTIME) << "EcmaVM Initialize"; + LOG_ECMA(INFO) << "EcmaVM Initialize"; ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "EcmaVM::Initialize"); Taskpool::GetCurrentTaskpool()->Initialize(); #ifndef PANDA_TARGET_WINDOWS @@ -134,7 +139,7 @@ bool EcmaVM::Initialize() gcStats_ = chunk_.New(heap_, options_.GetLongPauseTime()); factory_ = chunk_.New(thread_, heap_, &chunk_); if (UNLIKELY(factory_ == nullptr)) { - LOG_ECMA(FATAL) << "alloc factory_ failed"; + LOG_FULL(FATAL) << "alloc factory_ failed"; UNREACHABLE(); } [[maybe_unused]] EcmaHandleScope scope(thread_); @@ -166,6 +171,7 @@ bool EcmaVM::Initialize() globalConst->InitSpecialForSnapshot(); Builtins builtins; builtins.InitializeForSnapshot(thread_); + globalConstInitialized_ = true; } SetupRegExpResultCache(); @@ -176,6 +182,9 @@ bool EcmaVM::Initialize() debuggerManager_->Initialize(); tsLoader_ = new TSLoader(this); snapshotEnv_ = new SnapshotEnv(this); + if (!WIN_OR_MAC_PLATFORM) { + snapshotEnv_->Initialize(); + } fileLoader_ = new FileLoader(this); if (options_.GetEnableAsmInterpreter()) { LoadStubFile(); @@ -183,6 +192,7 @@ bool EcmaVM::Initialize() if (options_.GetEnableAsmInterpreter() && options_.WasAOTOutputFileSet()) { LoadAOTFiles(); } + heap_->GetReadOnlySpace()->SetReadOnly(); InitializeFinish(); return true; } @@ -213,7 +223,7 @@ void EcmaVM::InitializeEcmaScriptRunStat() "Invalid runtime caller number"); runtimeStat_ = chunk_.New(runtimeCallerNames, ecmascript::RUNTIME_CALLER_NUMBER); if (UNLIKELY(runtimeStat_ == nullptr)) { - LOG_ECMA(FATAL) << "alloc runtimeStat_ failed"; + LOG_FULL(FATAL) << "alloc runtimeStat_ failed"; UNREACHABLE(); } } @@ -227,7 +237,7 @@ void EcmaVM::SetRuntimeStatEnable(bool flag) InitializeEcmaScriptRunStat(); } } else { - LOG(INFO, RUNTIME) << "Runtime State duration:" << PandaRuntimeTimer::Now() - start << "(ns)"; + LOG_ECMA(INFO) << "Runtime State duration:" << PandaRuntimeTimer::Now() - start << "(ns)"; if (runtimeStat_->IsRuntimeStatEnabled()) { runtimeStat_->Print(); runtimeStat_->ResetAllCount(); @@ -244,7 +254,7 @@ bool EcmaVM::InitializeFinish() EcmaVM::~EcmaVM() { - LOG(INFO, RUNTIME) << "Destruct ecma_vm, vm address is: " << this; + LOG_ECMA(INFO) << "Destruct ecma_vm, vm address is: " << this; vmInitialized_ = false; Taskpool::GetCurrentTaskpool()->Destroy(); @@ -331,8 +341,7 @@ JSHandle EcmaVM::GetMicroJobQueue() const EcmaVM::CpuProfilingScope::CpuProfilingScope(EcmaVM* vm) : vm_(vm), profiler_(nullptr) { #if defined(ECMASCRIPT_SUPPORT_CPUPROFILER) - JSRuntimeOptions options = vm_->GetJSOptions(); - if (options.EnableCpuProfiler()) { + if (vm_->GetJSOptions().EnableCpuProfiler()) { profiler_ = CpuProfiler::GetInstance(); profiler_->CpuProfiler::StartCpuProfilerForFile(vm, ""); } @@ -348,16 +357,20 @@ EcmaVM::CpuProfilingScope::~CpuProfilingScope() #endif } -JSTaggedValue EcmaVM::InvokeEcmaAotEntrypoint(JSHandle mainFunc, const JSPandaFile *jsPandaFile) +JSTaggedValue EcmaVM::InvokeEcmaAotEntrypoint(JSHandle mainFunc, JSHandle &thisArg, + const JSPandaFile *jsPandaFile) { fileLoader_->UpdateJSMethods(mainFunc, jsPandaFile); - std::vector args(6, JSTaggedValue::Undefined().GetRawData()); // 6: number of para + std::vector args(7, JSTaggedValue::Undefined().GetRawData()); // 7: number of para args[0] = mainFunc.GetTaggedValue().GetRawData(); + args[2] = thisArg.GetTaggedValue().GetRawData(); // 2: parameter of this auto entry = thread_->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry); + JSTaggedValue env = mainFunc->GetLexicalEnv(); + args[6] = env.GetRawData(); // 6: last arg is env. auto res = reinterpret_cast(entry)(thread_->GetGlueAddr(), reinterpret_cast(thread_->GetCurrentSPFrame()), - static_cast(args.size()), - static_cast(args.size()), + static_cast(args.size()) - 1, + static_cast(args.size()) - 1, args.data(), mainFunc->GetCodeEntry()); return JSTaggedValue(res); @@ -391,17 +404,17 @@ Expected EcmaVM::InvokeEcmaEntrypoint(const JSPandaFile *js if (jsPandaFile->IsLoadedAOT()) { thread_->SetPrintBCOffset(true); - result = InvokeEcmaAotEntrypoint(func, jsPandaFile); + result = InvokeEcmaAotEntrypoint(func, global, jsPandaFile); } else { if (jsPandaFile->IsCjs()) { - CJSExecution(func, jsPandaFile); + CJSExecution(func, global, jsPandaFile); } else { JSHandle undefined = thread_->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, JSHandle(func), global, undefined, 0); EcmaRuntimeStatScope runtimeStatScope(this); CpuProfilingScope profilingScope(this); - EcmaInterpreter::Execute(&info); + EcmaInterpreter::Execute(info); } } if (!thread_->HasPendingException()) { @@ -425,39 +438,42 @@ JSTaggedValue EcmaVM::FindConstpool(const JSPandaFile *jsPandaFile) return iter->second; } -void EcmaVM::CJSExecution(JSHandle &func, const JSPandaFile *jsPandaFile) +void EcmaVM::CJSExecution(JSHandle &func, JSHandle &thisArg, const JSPandaFile *jsPandaFile) { [[maybe_unused]] EcmaHandleScope scope(thread_); ObjectFactory *factory = GetFactory(); // create "module", "exports", "require", "filename", "dirname" - JSHandle module = factory->NewCjsModule(); + JSHandle module = factory->NewCjsModule(); JSHandle require = GetGlobalEnv()->GetCjsRequireFunction(); - JSHandle exports = factory->NewCjsExports(); + JSHandle exports = factory->NewCjsExports(); JSMutableHandle filename(thread_, JSTaggedValue::Undefined());; JSMutableHandle dirname(thread_, JSTaggedValue::Undefined());; - JSRequireManager::ResolveCurrentPath(thread_, dirname, filename, jsPandaFile); + RequireManager::ResolveCurrentPath(thread_, dirname, filename, jsPandaFile); CJSInfo cjsInfo(module, require, exports, filename, dirname); - JSRequireManager::InitializeCommonJS(thread_, cjsInfo); + RequireManager::InitializeCommonJS(thread_, cjsInfo); // Execute main function - JSHandle global = GlobalEnv::Cast(globalEnv_.GetTaggedObject())->GetJSGlobalObject(); JSHandle undefined = thread_->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, JSHandle(func), - global, undefined, 5); // 5 : argument numbers - info.SetCallArg(cjsInfo.exportsHdl.GetTaggedValue(), - cjsInfo.requireHdl.GetTaggedValue(), - cjsInfo.moduleHdl.GetTaggedValue(), - cjsInfo.filenameHdl.GetTaggedValue(), - cjsInfo.dirnameHdl.GetTaggedValue()); + thisArg, undefined, 5); // 5 : argument numbers + if (info == nullptr) { + LOG_ECMA(ERROR) << "CJSExecution Stack overflow!"; + return; + } + info->SetCallArg(cjsInfo.exportsHdl.GetTaggedValue(), + cjsInfo.requireHdl.GetTaggedValue(), + cjsInfo.moduleHdl.GetTaggedValue(), + cjsInfo.filenameHdl.GetTaggedValue(), + cjsInfo.dirnameHdl.GetTaggedValue()); EcmaRuntimeStatScope runtimeStatScope(this); CpuProfilingScope profilingScope(this); - EcmaInterpreter::Execute(&info); + EcmaInterpreter::Execute(info); // Collecting module.exports : exports ---> module.exports --->Module._cache - JSRequireManager::CollectExecutedExp(thread_, cjsInfo); + RequireManager::CollectExecutedExp(thread_, cjsInfo); return; } @@ -490,7 +506,7 @@ void EcmaVM::EnableUserUncaughtErrorHandler() isUncaughtExceptionRegistered_ = true; } -void EcmaVM::HandleUncaughtException(ObjectHeader *exception) +void EcmaVM::HandleUncaughtException(TaggedObject *exception) { if (isUncaughtExceptionRegistered_) { return; @@ -503,14 +519,14 @@ void EcmaVM::HandleUncaughtException(ObjectHeader *exception) PrintJSErrorInfo(exceptionHandle); if (thread_->IsPrintBCOffset() && exceptionBCList_.size() != 0) { for (auto info : exceptionBCList_) { - LOG(ERROR, RUNTIME) << "Exception at function " << info.first << ": " << info.second; + LOG_ECMA(ERROR) << "Exception at function " << info.first << ": " << info.second; } } return; } JSHandle result = JSTaggedValue::ToString(thread_, exceptionHandle); CString string = ConvertToString(*result); - LOG(ERROR, RUNTIME) << string; + LOG_ECMA(ERROR) << string; } void EcmaVM::PrintJSErrorInfo(const JSHandle &exceptionInfo) @@ -525,7 +541,7 @@ void EcmaVM::PrintJSErrorInfo(const JSHandle &exceptionInfo) CString nameBuffer = ConvertToString(*name); CString msgBuffer = ConvertToString(*msg); CString stackBuffer = ConvertToString(*stack); - LOG(ERROR, RUNTIME) << nameBuffer << ": " << msgBuffer << "\n" << stackBuffer; + LOG_ECMA(ERROR) << nameBuffer << ": " << msgBuffer << "\n" << stackBuffer; } void EcmaVM::ProcessNativeDelete(const WeakRootVisitor &v0) @@ -608,7 +624,7 @@ void EcmaVM::ClearBufferData() bool EcmaVM::ExecutePromisePendingJob() { if (isProcessingPendingJob_) { - LOG(ERROR, RUNTIME) << "EcmaVM::ExecutePromisePendingJob can not reentrant"; + LOG_ECMA(ERROR) << "EcmaVM::ExecutePromisePendingJob can not reentrant"; return false; } if (!thread_->HasPendingException()) { @@ -668,21 +684,19 @@ void EcmaVM::SetupRegExpResultCache() void EcmaVM::LoadStubFile() { - std::string file = options_.GetStubFile(); - LOG(INFO, RUNTIME) << "Try to load stub file" << file.c_str(); - fileLoader_->LoadStubFile(file); + fileLoader_->LoadStubFile(); } void EcmaVM::LoadAOTFiles() { std::string file = options_.GetAOTOutputFile(); - LOG(INFO, RUNTIME) << "Try to load aot file" << file.c_str(); + LOG_ECMA(INFO) << "Try to load aot file" << file.c_str(); fileLoader_->LoadAOTFile(file); fileLoader_->TryLoadSnapshotFile(); } -void EcmaVM::SetAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry) +void EcmaVM::SaveAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry) { - fileLoader_->SetAOTFuncEntry(hash, methodId, funcEntry); + fileLoader_->SaveAOTFuncEntry(hash, methodId, funcEntry); } } // namespace panda::ecmascript diff --git a/ecmascript/ecma_vm.h b/ecmascript/ecma_vm.h index 13677dedcaddaebd2a569b38496ccd4e52f45d8d..2688dbd893f4575a2d06038b7ee7c5f28e7cd1e4 100644 --- a/ecmascript/ecma_vm.h +++ b/ecmascript/ecma_vm.h @@ -68,12 +68,12 @@ class Program; class TSLoader; class FileLoader; class ModuleManager; -class JSCjsModule; -class JSCjsExports; -class JSCjsRequire; +class CjsModule; +class CjsExports; +class CjsRequire; class CjsModuleCache; class SlowRuntimeStub; -class JSRequireManager; +class RequireManager; struct CJSInfo; using HostPromiseRejectionTracker = void (*)(const EcmaVM* vm, @@ -87,11 +87,11 @@ using ResolvePathCallback = std::function GetGlobalEnv() const; JSHandle GetMicroJobQueue() const; @@ -160,11 +165,11 @@ public: // Exclude GC thread if (options_.EnableThreadCheck()) { if (thread_ == nullptr) { - LOG(FATAL, RUNTIME) << "Fatal: ecma_vm has been destructed! vm address is: " << this; + LOG_FULL(FATAL) << "Fatal: ecma_vm has been destructed! vm address is: " << this; } if (!Taskpool::GetCurrentTaskpool()->IsInThreadPool(std::this_thread::get_id()) && thread_->GetThreadId() != JSThread::GetCurrentThreadId()) { - LOG(FATAL, RUNTIME) << "Fatal: ecma_vm cannot run in multi-thread!" + LOG_FULL(FATAL) << "Fatal: ecma_vm cannot run in multi-thread!" << " thread:" << thread_->GetThreadId() << " currentThread:" << JSThread::GetCurrentThreadId(); } @@ -173,11 +178,6 @@ public: return thread_; } - JSThread *GetJSThreadNoCheck() const - { - return thread_; - } - bool ICEnabled() const { return icEnabled_; @@ -332,7 +332,7 @@ public: JSTaggedValue FindConstpool(const JSPandaFile *jsPandaFile); - void SetAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry); + void SaveAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry); void StoreBCOffsetInfo(const std::string& methodName, int32_t bcOffset) { exceptionBCList_.emplace_back(std::pair(methodName, bcOffset)); @@ -350,7 +350,7 @@ public: protected: - void HandleUncaughtException(ObjectHeader *exception); + void HandleUncaughtException(TaggedObject *exception); void PrintJSErrorInfo(const JSHandle &exceptionInfo); @@ -371,9 +371,10 @@ private: Expected InvokeEcmaEntrypoint(const JSPandaFile *jsPandaFile); - JSTaggedValue InvokeEcmaAotEntrypoint(JSHandle mainFunc, const JSPandaFile *jsPandaFile); + JSTaggedValue InvokeEcmaAotEntrypoint(JSHandle mainFunc, JSHandle &thisArg, + const JSPandaFile *jsPandaFile); - void CJSExecution(JSHandle &func, const JSPandaFile *jsPandaFile); + void CJSExecution(JSHandle &func, JSHandle &thisArg, const JSPandaFile *jsPandaFile); void InitializeEcmaScriptRunStat(); @@ -441,6 +442,9 @@ private: // CJS resolve path Callbacks ResolvePathCallback resolvePathCallback_ {nullptr}; + // vm parameter configurations + EcmaParamConfiguration ecmaParamConfiguration_; + friend class Snapshot; friend class SnapshotProcessor; friend class ObjectFactory; diff --git a/ecmascript/file_loader.cpp b/ecmascript/file_loader.cpp index 953ca202a9f32a61a4463a90ebb27a9bdb70338e..98299d9134f79faac796d3610b036c114cfa1fc1 100644 --- a/ecmascript/file_loader.cpp +++ b/ecmascript/file_loader.cpp @@ -14,10 +14,14 @@ */ #include "ecmascript/file_loader.h" +#ifdef PANDA_TARGET_WINDOWS +#include "shlwapi.h" +#endif + #include "ecmascript/base/config.h" #include "ecmascript/compiler/bc_call_signature.h" #include "ecmascript/compiler/common_stubs.h" -#include "ecmascript/compiler/llvm/llvm_stackmap_parser.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "ecmascript/ecma_vm.h" #include "ecmascript/jspandafile/constpool_value.h" #include "ecmascript/jspandafile/js_pandafile.h" @@ -26,6 +30,9 @@ #include "ecmascript/js_thread.h" #include "ecmascript/snapshot/mem/snapshot.h" +extern const uint8_t _binary_stub_m_start[]; +extern const uint32_t _binary_stub_m_length; + namespace panda::ecmascript { void StubModulePackInfo::Save(const std::string &filename) { @@ -56,52 +63,46 @@ void StubModulePackInfo::Save(const std::string &filename) moduleFile.close(); } -bool StubModulePackInfo::Load(EcmaVM *vm, const std::string &filename) +bool StubModulePackInfo::Load(EcmaVM *vm) { // now MachineCode is non movable, code and stackmap sperately is saved to MachineCode // by calling NewMachineCodeObject. // then MachineCode will support movable, code is saved to MachineCode and stackmap is saved // to different heap which will be freed when stackmap is parsed by EcmaVM is started. - if (!VerifyFilePath(filename)) { - COMPILER_LOG(ERROR) << "Can not load stub file from path [ " << filename << " ], " - << "please execute ark_stub_compiler with options --stub-file."; + if (_binary_stub_m_length <= 1) { + LOG_FULL(FATAL) << "stub.m length <= 1, is default and invalid."; return false; } - std::ifstream moduleFile(filename.c_str(), std::ofstream::binary); - if (!moduleFile.good()) { - moduleFile.close(); - return false; - } - moduleFile.read(reinterpret_cast(&entryNum_), sizeof(entryNum_)); + BinaryBufferParser binBufparser((uint8_t *)_binary_stub_m_start, _binary_stub_m_length); + binBufparser.ParseBuffer(&entryNum_, sizeof(entryNum_)); entries_.resize(entryNum_); - moduleFile.read(reinterpret_cast(entries_.data()), sizeof(FuncEntryDes) * entryNum_); - moduleFile.read(reinterpret_cast(&moduleNum_), sizeof(moduleNum_)); + binBufparser.ParseBuffer(entries_.data(), sizeof(FuncEntryDes) * entryNum_); + binBufparser.ParseBuffer(&moduleNum_, sizeof(moduleNum_)); des_.resize(moduleNum_); uint32_t totalCodeSize = 0; - moduleFile.read(reinterpret_cast(&totalCodeSize), sizeof(totalCodeSize_)); + binBufparser.ParseBuffer(&totalCodeSize, sizeof(totalCodeSize_)); auto factory = vm->GetFactory(); auto codeHandle = factory->NewMachineCodeObject(totalCodeSize, nullptr); SetCode(codeHandle); uint32_t curUnitOffset = 0; for (size_t i = 0; i < moduleNum_; i++) { - moduleFile.read(reinterpret_cast(&(des_[i].hostCodeSectionAddr_)), + binBufparser.ParseBuffer(&(des_[i].hostCodeSectionAddr_), sizeof(des_[i].hostCodeSectionAddr_)); - moduleFile.read(reinterpret_cast(&(des_[i].codeSize_)), + binBufparser.ParseBuffer(&(des_[i].codeSize_), sizeof(des_[i].codeSize_)); uint32_t codeSize = des_[i].GetCodeSize(); // startAddr of current code unit on device side uintptr_t startAddr = codeHandle->GetDataOffsetAddress() + static_cast(curUnitOffset); - moduleFile.read(reinterpret_cast(startAddr), codeSize); + binBufparser.ParseBuffer(reinterpret_cast(startAddr), codeSize); curUnitOffset += codeSize; des_[i].SetDeviceCodeSecAddr(startAddr); - moduleFile.read(reinterpret_cast(&(des_[i].stackMapSize_)), + binBufparser.ParseBuffer(&(des_[i].stackMapSize_), sizeof(des_[i].stackMapSize_)); uint32_t stackmapSize = des_[i].GetStackMapSize(); std::unique_ptr stackmapPtr(std::make_unique(stackmapSize)); - moduleFile.read(reinterpret_cast(stackmapPtr.get()), stackmapSize); + binBufparser.ParseBuffer(stackmapPtr.get(), stackmapSize); if (stackmapSize != 0) { - bool enableLog = vm->GetJSOptions().WasSetlogCompiledMethods(); - kungfu::LLVMStackMapParser::GetInstance(enableLog).CalculateStackMap(std::move(stackmapPtr), + vm->GetFileLoader()->GetStackMapParser()->CalculateStackMap(std::move(stackmapPtr), des_[i].GetHostCodeSecAddr(), startAddr); } } @@ -114,14 +115,13 @@ bool StubModulePackInfo::Load(EcmaVM *vm, const std::string &filename) kungfu::Func2FpDelta fun2fpDelta; auto funSize = funcEntryDes.funcSize_; fun2fpDelta[funAddr] = std::make_pair(delta, funSize); - kungfu::LLVMStackMapParser::GetInstance().CalculateFuncFpDelta(fun2fpDelta); + vm->GetFileLoader()->GetStackMapParser()->CalculateFuncFpDelta(fun2fpDelta); } for (size_t i = 0; i < entries_.size(); i++) { auto des = des_[entries_[i].moduleIndex_]; entries_[i].codeAddr_ += des.GetDeviceCodeSecAddr(); } - moduleFile.close(); - COMPILER_LOG(INFO) << "Load stub file success"; + LOG_COMPILER(INFO) << "Load stub file success"; return true; } @@ -156,7 +156,7 @@ void AOTModulePackInfo::Save(const std::string &filename) bool AOTModulePackInfo::Load(EcmaVM *vm, const std::string &filename) { if (!VerifyFilePath(filename)) { - COMPILER_LOG(ERROR) << "Can not load aot file from path [ " << filename << " ], " + LOG_COMPILER(ERROR) << "Can not load aot file from path [ " << filename << " ], " << "please execute ark_aot_compiler with options --aot-file."; return false; } @@ -193,8 +193,7 @@ bool AOTModulePackInfo::Load(EcmaVM *vm, const std::string &filename) std::unique_ptr stackmapPtr(std::make_unique(stackmapSize)); moduleFile.read(reinterpret_cast(stackmapPtr.get()), stackmapSize); if (stackmapSize != 0) { - bool enableLog = vm->GetJSOptions().WasSetlogCompiledMethods(); - kungfu::LLVMStackMapParser::GetInstance(enableLog).CalculateStackMap(std::move(stackmapPtr), + vm->GetFileLoader()->GetStackMapParser()->CalculateStackMap(std::move(stackmapPtr), des_[i].GetHostCodeSecAddr(), startAddr); } } @@ -207,7 +206,7 @@ bool AOTModulePackInfo::Load(EcmaVM *vm, const std::string &filename) uintptr_t funAddr = startAddr + codeAddr; kungfu::Func2FpDelta fun2fpDelta; fun2fpDelta[funAddr] = std::make_pair(delta, funSize); - kungfu::LLVMStackMapParser::GetInstance().CalculateFuncFpDelta(fun2fpDelta); + vm->GetFileLoader()->GetStackMapParser()->CalculateFuncFpDelta(fun2fpDelta); } for (size_t i = 0; i < entries_.size(); i++) { @@ -215,10 +214,10 @@ bool AOTModulePackInfo::Load(EcmaVM *vm, const std::string &filename) entries_[i].codeAddr_ += des.GetDeviceCodeSecAddr(); auto curFileHash = aotFileHashs_[entries_[i].moduleIndex_]; auto curMethodId = entries_[i].indexInKind_; - vm->SetAOTFuncEntry(curFileHash, curMethodId, entries_[i].codeAddr_); + vm->SaveAOTFuncEntry(curFileHash, curMethodId, entries_[i].codeAddr_); } moduleFile.close(); - COMPILER_LOG(INFO) << "Load aot file success"; + LOG_COMPILER(INFO) << "Load aot file success"; return true; } @@ -249,9 +248,9 @@ bool ModulePackInfo::VerifyFilePath([[maybe_unused]] const std::string &filePath #endif } -void FileLoader::LoadStubFile(const std::string &fileName) +void FileLoader::LoadStubFile() { - if (!stubPackInfo_.Load(vm_, fileName)) { + if (!stubPackInfo_.Load(vm_)) { return; } auto stubs = stubPackInfo_.GetStubs(); @@ -278,42 +277,37 @@ void FileLoader::TryLoadSnapshotFile() bool FileLoader::hasLoaded(const JSPandaFile *jsPandaFile) { - auto fileHash = jsPandaFile->GetPandaFile()->GetFilenameHash(); + auto fileHash = jsPandaFile->GetFileUniqId(); return !(hashToEntryMap_.find(fileHash) == hashToEntryMap_.end()); } void FileLoader::UpdateJSMethods(JSHandle mainFunc, const JSPandaFile *jsPandaFile) { - // get generated const pool in execution phase - auto thread = vm_->GetAssociatedJSThread(); - JSHandle constPool(thread, mainFunc->GetConstantPool()); - ConstantPool *curPool = ConstantPool::Cast(constPool->GetTaggedObject()); - // get main func method auto mainFuncMethodId = jsPandaFile->GetMainMethodIndex(); - auto fileHash = jsPandaFile->GetPandaFile()->GetFilenameHash(); + auto fileHash = jsPandaFile->GetFileUniqId(); auto mainEntry = GetAOTFuncEntry(fileHash, mainFuncMethodId); - // 1 : default para number JSMethod *mainMethod = jsPandaFile->FindMethods(mainFuncMethodId); mainMethod->SetAotCodeBit(true); mainMethod->SetNativeBit(false); mainFunc->SetCodeEntry(reinterpret_cast(mainEntry)); +} - const CUnorderedMap &constpoolMap = jsPandaFile->GetConstpoolMap(); - for (const auto &it : constpoolMap) { - ConstPoolValue value(it.second); - if (value.GetConstpoolType() == ConstPoolType::BASE_FUNCTION || - value.GetConstpoolType() == ConstPoolType::NC_FUNCTION || - value.GetConstpoolType() == ConstPoolType::GENERATOR_FUNCTION || - value.GetConstpoolType() == ConstPoolType::ASYNC_FUNCTION || - value.GetConstpoolType() == ConstPoolType::METHOD) { - auto id = value.GetConstpoolIndex(); - auto codeEntry = GetAOTFuncEntry(fileHash, it.first); - JSMethod *curMethod = jsPandaFile->FindMethods(it.first); - curMethod->SetAotCodeBit(true); - curMethod->SetNativeBit(false); - auto curFunction = JSFunction::Cast(curPool->GetObjectFromCache(id).GetTaggedObject()); - curFunction->SetCodeEntry(reinterpret_cast(codeEntry)); +void FileLoader::SetAOTFuncEntry(const JSPandaFile *jsPandaFile, const JSHandle &func) +{ + auto codeEntry = GetAOTFuncEntry(jsPandaFile->GetFileUniqId(), jsPandaFile->GetUniqueMethod(func)); + func->SetCodeEntryAndMarkAOT(codeEntry); +} + +void FileLoader::SetAOTFuncEntryForLiteral(const JSPandaFile *jsPandaFile, const JSHandle &obj) +{ + JSThread *thread = vm_->GetJSThread(); + JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); + size_t elementsLen = obj->GetLength(); + for (size_t i = 0; i < elementsLen; i++) { + valueHandle.Update(obj->Get(i)); + if (valueHandle->IsJSFunction()) { + SetAOTFuncEntry(jsPandaFile, JSHandle(valueHandle)); } } } @@ -370,4 +364,59 @@ void FileLoader::InitializeStubEntries(const std::vectorGetJSOptions().GetAsmInterParsedOption(); AdjustBCStubAndDebuggerStubEntries(thread, stubs, asmInterOpt); } + +FileLoader::~FileLoader() +{ + if (stackMapParser_ != nullptr) { + delete stackMapParser_; + stackMapParser_ = nullptr; + } +} + +FileLoader::FileLoader(EcmaVM *vm) : vm_(vm), factory_(vm->GetFactory()) +{ + bool enableLog = vm->GetJSOptions().WasSetlogCompiledMethods(); + stackMapParser_ = new kungfu::LLVMStackMapParser(enableLog); +} + +bool FileLoader::GetAbsolutePath(const std::string &relativePath, std::string &absPath) +{ + if (relativePath.size() >= PATH_MAX) { + return false; + } + char buffer[PATH_MAX] = {0}; +#ifndef PANDA_TARGET_WINDOWS + auto path = realpath(relativePath.c_str(), buffer); + if (path == nullptr) { + return false; + } + absPath = std::string(path); + return true; +#else + auto path = _fullpath(buffer, relativePath.c_str(), sizeof(buffer) - 1); + if (path == nullptr) { + return false; + } + absPath = std::string(buffer); + return true; +#endif +} + +kungfu::LLVMStackMapParser* FileLoader::GetStackMapParser() +{ + return stackMapParser_; +} + +void BinaryBufferParser::ParseBuffer(void *dst, uint32_t count) +{ + if (count > 0 && count + offset_ <= length_) { + if (memcpy_s(dst, count, buffer_ + offset_, count) != EOK) { + LOG_FULL(FATAL) << "memcpy_s failed"; + return; + }; + offset_ = offset_ + count; + } else { + LOG_FULL(FATAL) << "parse buffer error, length is 0 or overflow"; + } +} } \ No newline at end of file diff --git a/ecmascript/file_loader.h b/ecmascript/file_loader.h index e4cc1c3cdc58977a6b50124439e51730dfcf25fa..463b620f26c77f4c8ecca973bbce8ea950ed9bc1 100644 --- a/ecmascript/file_loader.h +++ b/ecmascript/file_loader.h @@ -21,6 +21,9 @@ namespace panda::ecmascript { class JSpandafile; class JSThread; +namespace kungfu { + class LLVMStackMapParser; +}; struct ModuleSectionDes { uint64_t hostCodeSectionAddr_ {0}; @@ -207,7 +210,7 @@ public: StubModulePackInfo() = default; ~StubModulePackInfo() override = default; void Save(const std::string &filename); - bool Load(EcmaVM *vm, const std::string &filename); + bool Load(EcmaVM *vm); void AddModuleDes(ModuleSectionDes moduleDes) { @@ -220,9 +223,9 @@ class FileLoader { using CommonStubCSigns = kungfu::CommonStubCSigns; using BytecodeStubCSigns = kungfu::BytecodeStubCSigns; public: - explicit FileLoader(EcmaVM *vm) : vm_(vm), factory_(vm->GetFactory()) {} - ~FileLoader() = default; - void LoadStubFile(const std::string &fileName); + explicit FileLoader(EcmaVM *vm); + virtual ~FileLoader(); + void LoadStubFile(); void LoadAOTFile(const std::string &fileName); void AddAOTPackInfo(AOTModulePackInfo packInfo) { @@ -240,7 +243,7 @@ public: } } - void SetAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry) + void SaveAOTFuncEntry(uint32_t hash, uint32_t methodId, uint64_t funcEntry) { hashToEntryMap_[hash][methodId] = funcEntry; } @@ -257,17 +260,34 @@ public: void UpdateJSMethods(JSHandle mainFunc, const JSPandaFile *jsPandaFile); bool hasLoaded(const JSPandaFile *jsPandaFile); + void SetAOTFuncEntry(const JSPandaFile *jsPandaFile, const JSHandle &func); + void SetAOTFuncEntryForLiteral(const JSPandaFile *jsPandaFile, const JSHandle &obj); void TryLoadSnapshotFile(); + kungfu::LLVMStackMapParser* GetStackMapParser(); + static bool GetAbsolutePath(const std::string &relativePath, std::string &absPath); private: EcmaVM *vm_ {nullptr}; ObjectFactory *factory_ {nullptr}; StubModulePackInfo stubPackInfo_ {}; std::vector aotPackInfos_ {}; std::unordered_map> hashToEntryMap_ {}; + kungfu::LLVMStackMapParser *stackMapParser_ {nullptr}; void InitializeStubEntries(const std::vector& stubs); void AdjustBCStubAndDebuggerStubEntries(JSThread *thread, const std::vector &stubs, const AsmInterParsedOption &asmInterOpt); }; + +class BinaryBufferParser { +public: + BinaryBufferParser(uint8_t *buffer, uint32_t length) : buffer_(buffer), length_(length) {} + ~BinaryBufferParser() = default; + void ParseBuffer(void *dst, uint32_t count); + +private: + uint8_t *buffer_ {nullptr}; + uint32_t length_ {0}; + uint32_t offset_ {0}; +}; } #endif // ECMASCRIPT_COMPILER_FILE_LOADER_H \ No newline at end of file diff --git a/ecmascript/frames.cpp b/ecmascript/frames.cpp new file mode 100644 index 0000000000000000000000000000000000000000..916f9ff449a4c1f513d470e05526fddc80b2f0aa --- /dev/null +++ b/ecmascript/frames.cpp @@ -0,0 +1,502 @@ +/* + * Copyright (c) 2022-2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ecmascript/frames.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/file_loader.h" +#include "ecmascript/js_thread.h" +#include "ecmascript/llvm_stackmap_parser.h" +#include "ecmascript/interpreter/frame_handler.h" + +namespace panda::ecmascript { +JSTaggedType *OptimizedLeaveFrame::GetJsFuncFrameArgv(JSThread *thread) const +{ + auto current = GetPrevFrameFp(); + int delta = thread->GetEcmaVM()->GetFileLoader()->GetStackMapParser()->GetFuncFpDelta(returnAddr); + uintptr_t *preFrameSp = reinterpret_cast(const_cast(current)) + + delta / sizeof(uintptr_t); + JSTaggedType *argv = reinterpret_cast(preFrameSp + sizeof(uint64_t) / sizeof(uintptr_t)); + return argv; +} + +FrameIterator::FrameIterator(JSTaggedType *sp, const JSThread *thread) : current_(sp), thread_(thread) +{ + if (thread != nullptr) { + stackmapParser_ = thread->GetEcmaVM()->GetFileLoader()->GetStackMapParser(); + } +} + +int FrameIterator::ComputeDelta() const +{ + return stackmapParser_->GetFuncFpDelta(optimizedReturnAddr_); +} + +void FrameIterator::Advance() +{ + ASSERT(!Done()); + FrameType t = GetFrameType(); + switch (t) { + case FrameType::OPTIMIZED_FRAME : { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(optimizedReturnAddr_); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::OPTIMIZED_ENTRY_FRAME : { + auto frame = GetFrame(); + optimizedReturnAddr_ = 0; + optimizedCallSiteSp_ = 0; + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME: { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::OPTIMIZED_JS_FUNCTION_FRAME: { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(optimizedReturnAddr_); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::LEAVE_FRAME : { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::LEAVE_FRAME_WITH_ARGV : { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::BUILTIN_CALL_LEAVE_FRAME : { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::INTERPRETER_FRAME: + case FrameType::INTERPRETER_FAST_NEW_FRAME : { + auto frame = GetFrame(); + optimizedReturnAddr_ = 0; + optimizedCallSiteSp_ = 0; + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::INTERPRETER_BUILTIN_FRAME: { + auto frame = GetFrame(); + optimizedReturnAddr_ = 0; + optimizedCallSiteSp_ = 0; + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: + case FrameType::ASM_INTERPRETER_FRAME : { + auto frame = GetFrame(); + optimizedReturnAddr_ = 0; + optimizedCallSiteSp_ = 0; + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::BUILTIN_FRAME: + case FrameType::BUILTIN_ENTRY_FRAME : { + auto frame = GetFrame(); + optimizedReturnAddr_ = frame->GetReturnAddr(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::BUILTIN_FRAME_WITH_ARGV : { + auto frame = GetFrame(); + optimizedReturnAddr_ = frame->GetReturnAddr(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(); + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::INTERPRETER_ENTRY_FRAME : { + auto frame = GetFrame(); + optimizedReturnAddr_ = 0; + optimizedCallSiteSp_ = 0; + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::ASM_INTERPRETER_ENTRY_FRAME : { + auto frame = GetFrame(); + optimizedReturnAddr_ = 0; + optimizedCallSiteSp_ = 0; + current_ = frame->GetPrevFrameFp(); + break; + } + case FrameType::ASM_INTERPRETER_BRIDGE_FRAME : { + auto frame = GetFrame(); + optimizedCallSiteSp_ = GetPrevFrameCallSiteSp(optimizedReturnAddr_); + optimizedReturnAddr_ = frame->GetReturnAddr(); + current_ = frame->GetPrevFrameFp(); + break; + } + default: { + UNREACHABLE(); + } + } +} +uintptr_t FrameIterator::GetPrevFrameCallSiteSp(uintptr_t curPc) const +{ + if (Done()) { + return 0; + } + auto type = GetFrameType(); + switch (type) { + case FrameType::LEAVE_FRAME: { + auto frame = GetFrame(); + return frame->GetCallSiteSp(); + } + case FrameType::LEAVE_FRAME_WITH_ARGV: { + auto frame = GetFrame(); + return frame->GetCallSiteSp(); + } + case FrameType::BUILTIN_CALL_LEAVE_FRAME: { + auto frame = GetFrame(); + return frame->GetCallSiteSp(); + } + case FrameType::BUILTIN_FRAME_WITH_ARGV: { + auto frame = GetFrame(); + return frame->GetCallSiteSp(); + } + case FrameType::BUILTIN_FRAME: { + auto frame = GetFrame(); + return frame->GetCallSiteSp(); + } + case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: { + auto frame = GetFrame(); + return frame->GetCallSiteSp(); + } + case FrameType::OPTIMIZED_FRAME: + case FrameType::OPTIMIZED_JS_FUNCTION_FRAME: { + ASSERT(thread_ != nullptr); + auto callSiteSp = reinterpret_cast(current_) + + thread_->GetEcmaVM()->GetFileLoader()->GetStackMapParser()->GetFuncFpDelta(curPc); + return callSiteSp; + } + case FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME : { + auto callSiteSp = reinterpret_cast(current_) + sizeof(uintptr_t); + return callSiteSp; + } + case FrameType::BUILTIN_ENTRY_FRAME: + case FrameType::ASM_INTERPRETER_FRAME: + case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: + case FrameType::INTERPRETER_FRAME: + case FrameType::INTERPRETER_FAST_NEW_FRAME: + case FrameType::OPTIMIZED_ENTRY_FRAME: + case FrameType::INTERPRETER_ENTRY_FRAME: + case FrameType::ASM_INTERPRETER_ENTRY_FRAME: { + return 0; + } + default: { + UNREACHABLE(); + } + } +} + +uintptr_t FrameIterator::GetPrevFrame() const +{ + FrameType type = GetFrameType(); + uintptr_t end = 0U; + switch (type) { + case FrameType::INTERPRETER_FRAME: + case FrameType::INTERPRETER_FAST_NEW_FRAME: { + auto prevFrame = GetFrame(); + end = ToUintPtr(prevFrame); + break; + } + case FrameType::INTERPRETER_ENTRY_FRAME: { + auto prevFrame = GetFrame(); + end = ToUintPtr(prevFrame); + break; + } + case FrameType::INTERPRETER_BUILTIN_FRAME: { + auto prevFrame = GetFrame(); + end = ToUintPtr(prevFrame); + break; + } + default: { + LOG_ECMA(FATAL) << "frame type error!"; + UNREACHABLE(); + } + } + return end; +} + +bool FrameIterator::CollectGCSlots(std::set &baseSet, ChunkMap *data, + [[maybe_unused]] bool isVerifying) const +{ + return stackmapParser_->CollectGCSlots(optimizedReturnAddr_, reinterpret_cast(current_), + baseSet, data, isVerifying, optimizedCallSiteSp_); +} + +ARK_INLINE void OptimizedFrame::GCIterate(const FrameIterator &it, + const RootVisitor &v0, + [[maybe_unused]] const RootRangeVisitor &v1, + ChunkMap *derivedPointers, + bool isVerifying) const +{ + std::set slotAddrs; + bool ret = it.CollectGCSlots(slotAddrs, derivedPointers, isVerifying); + if (!ret) { +#ifndef NDEBUG + LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << it.GetOptimizedReturnAddr(); +#endif + return; + } + + for (const auto &slot : slotAddrs) { + v0(Root::ROOT_FRAME, ObjectSlot(slot)); + } +} + +ARK_INLINE JSTaggedType* OptimizedJSFunctionFrame::GetArgv(const FrameIterator &it) const +{ + uintptr_t *preFrameSp = ComputePrevFrameSp(it); + return GetArgv(preFrameSp); +} + +ARK_INLINE uintptr_t* OptimizedJSFunctionFrame::ComputePrevFrameSp(const FrameIterator &it) const +{ + const JSTaggedType *sp = it.GetSp(); + int delta = it.ComputeDelta(); + uintptr_t *preFrameSp = reinterpret_cast(const_cast(sp)) + + delta / sizeof(uintptr_t); + return preFrameSp; +} + +ARK_INLINE void OptimizedJSFunctionFrame::GCIterate(const FrameIterator &it, + const RootVisitor &v0, + const RootRangeVisitor &v1, + ChunkMap *derivedPointers, + bool isVerifying) const +{ + OptimizedJSFunctionFrame *frame = OptimizedJSFunctionFrame::GetFrameFromSp(it.GetSp()); + uintptr_t *envPtr = reinterpret_cast(frame); + uintptr_t envslot = ToUintPtr(envPtr); + v0(Root::ROOT_FRAME, ObjectSlot(envslot)); + + uintptr_t *preFrameSp = frame->ComputePrevFrameSp(it); + + auto argc = frame->GetArgc(preFrameSp); + JSTaggedType *argv = frame->GetArgv(reinterpret_cast(preFrameSp)); + if (argc > 0) { + uintptr_t start = ToUintPtr(argv); // argv + uintptr_t end = ToUintPtr(argv + argc); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + } + + std::set slotAddrs; + bool ret = it.CollectGCSlots(slotAddrs, derivedPointers, isVerifying); + if (!ret) { +#ifndef NDEBUG + LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << it.GetOptimizedReturnAddr(); +#endif + return; + } + + for (const auto &slot : slotAddrs) { + v0(Root::ROOT_FRAME, ObjectSlot(slot)); + } +} + +ARK_INLINE void AsmInterpretedFrame::GCIterate(const FrameIterator &it, + const RootVisitor &v0, + const RootRangeVisitor &v1, + ChunkMap *derivedPointers, + bool isVerifying) const +{ + AsmInterpretedFrame *frame = AsmInterpretedFrame::GetFrameFromSp(it.GetSp()); + uintptr_t start = ToUintPtr(it.GetSp()); + uintptr_t end = ToUintPtr(frame->GetCurrentFramePointer()); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->function))); + if (frame->pc != nullptr) { + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->acc))); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->env))); + } + + std::set slotAddrs; + bool ret = it.CollectGCSlots(slotAddrs, derivedPointers, isVerifying); + if (!ret) { +#ifndef NDEBUG + LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << it.GetOptimizedReturnAddr(); +#endif + return; + } + for (auto slot : slotAddrs) { + v0(Root::ROOT_FRAME, ObjectSlot(slot)); + } +} + +ARK_INLINE void InterpretedFrame::GCIterate(const FrameIterator &it, + const RootVisitor &v0, + const RootRangeVisitor &v1) const +{ + auto sp = it.GetSp(); + InterpretedFrame *frame = InterpretedFrame::GetFrameFromSp(sp); + if (frame->function == JSTaggedValue::Hole()) { + return; + } + + JSTaggedType *prevSp = frame->GetPrevFrameFp(); + uintptr_t start = ToUintPtr(sp); + const JSThread *thread = it.GetThread(); + FrameIterator prevIt(prevSp, thread); + uintptr_t end = prevIt.GetPrevFrame(); + + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->function))); + + // pc == nullptr, init InterpretedFrame & native InterpretedFrame. + if (frame->pc != nullptr) { + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->acc))); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->constpool))); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->env))); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->profileTypeInfo))); + } +} + +ARK_INLINE void InterpretedBuiltinFrame::GCIterate(const FrameIterator &it, + const RootVisitor &v0, + const RootRangeVisitor &v1) const +{ + auto sp = it.GetSp(); + InterpretedBuiltinFrame *frame = InterpretedBuiltinFrame::GetFrameFromSp(sp); + JSTaggedType *prevSp = frame->GetPrevFrameFp(); + const JSThread *thread = it.GetThread(); + FrameIterator prevIt(prevSp, thread); + + uintptr_t start = ToUintPtr(sp + 2); // 2: numArgs & thread. + uintptr_t end = prevIt.GetPrevFrame(); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->function))); +} + +ARK_INLINE void OptimizedLeaveFrame::GCIterate(const FrameIterator &it, + [[maybe_unused]] const RootVisitor &v0, + const RootRangeVisitor &v1, + [[maybe_unused]] ChunkMap *derivedPointers, + [[maybe_unused]] bool isVerifying) const +{ + const JSTaggedType *sp = it.GetSp(); + OptimizedLeaveFrame *frame = OptimizedLeaveFrame::GetFrameFromSp(sp); + if (frame->argc > 0) { + JSTaggedType *argv = reinterpret_cast(&frame->argc + 1); + uintptr_t start = ToUintPtr(argv); // argv + uintptr_t end = ToUintPtr(argv + frame->argc); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + } +} + +ARK_INLINE void OptimizedWithArgvLeaveFrame::GCIterate(const FrameIterator &it, + [[maybe_unused]] const RootVisitor &v0, + const RootRangeVisitor &v1, + [[maybe_unused]] ChunkMap *derivedPointers, + [[maybe_unused]] bool isVerifying) const +{ + const JSTaggedType *sp = it.GetSp(); + OptimizedWithArgvLeaveFrame *frame = OptimizedWithArgvLeaveFrame::GetFrameFromSp(sp); + if (frame->argc > 0) { + uintptr_t* argvPtr = reinterpret_cast(&frame->argc + 1); + JSTaggedType *argv = reinterpret_cast(*argvPtr); + uintptr_t start = ToUintPtr(argv); // argv + uintptr_t end = ToUintPtr(argv + frame->argc); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + } +} + +ARK_INLINE void OptimizedBuiltinLeaveFrame::GCIterate(const FrameIterator &it, + [[maybe_unused]] const RootVisitor &v0, + const RootRangeVisitor &v1, + [[maybe_unused]] ChunkMap *derivedPointers, + [[maybe_unused]] bool isVerifying) const +{ + const JSTaggedType *sp = it.GetSp(); + OptimizedBuiltinLeaveFrame *frame = OptimizedBuiltinLeaveFrame::GetFrameFromSp(sp); + if (frame->argc > 0) { + JSTaggedType *argv = reinterpret_cast(&frame->argc + 1); + uintptr_t start = ToUintPtr(argv); // argv + uintptr_t end = ToUintPtr(argv + frame->argc); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); + } +} + +ARK_INLINE void BuiltinWithArgvFrame::GCIterate(const FrameIterator &it, + [[maybe_unused]] const RootVisitor &v0, + const RootRangeVisitor &v1, + [[maybe_unused]] ChunkMap *derivedPointers, + [[maybe_unused]] bool isVerifying) const +{ + const JSTaggedType *sp = it.GetSp(); + auto frame = BuiltinWithArgvFrame::GetFrameFromSp(sp); + auto argc = frame->GetNumArgs() + NUM_MANDATORY_JSFUNC_ARGS; + JSTaggedType *argv = reinterpret_cast(frame->GetStackArgsAddress()); + uintptr_t start = ToUintPtr(argv); + uintptr_t end = ToUintPtr(argv + argc); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); +} + +ARK_INLINE void BuiltinFrame::GCIterate(const FrameIterator &it, + const RootVisitor &v0, + const RootRangeVisitor &v1, + [[maybe_unused]] ChunkMap *derivedPointers, + [[maybe_unused]] bool isVerifying) const +{ + const JSTaggedType *sp = it.GetSp(); + auto frame = BuiltinFrame::GetFrameFromSp(sp); + // no need to visit stack map for entry frame + if (frame->type == FrameType::BUILTIN_ENTRY_FRAME) { + // only visit function + v0(Root::ROOT_FRAME, ObjectSlot(frame->GetStackArgsAddress())); + return; + } + JSTaggedType *argv = reinterpret_cast(frame->GetStackArgsAddress()); + auto argc = frame->GetNumArgs(); + uintptr_t start = ToUintPtr(argv); + uintptr_t end = ToUintPtr(argv + argc); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); +} + +ARK_INLINE void InterpretedEntryFrame::GCIterate(const FrameIterator &it, + [[maybe_unused]] const RootVisitor &v0, + const RootRangeVisitor &v1) const +{ + const JSTaggedType* sp = it.GetSp(); + InterpretedEntryFrame *frame = InterpretedEntryFrame::GetFrameFromSp(sp); + JSTaggedType *prevSp = frame->GetPrevFrameFp(); + if (prevSp == nullptr) { + return; + } + + const JSThread *thread = it.GetThread(); + FrameIterator prevIt(prevSp, thread); + uintptr_t start = ToUintPtr(sp + 2); // 2: numArgs & thread. + uintptr_t end = prevIt.GetPrevFrame(); + v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); +} +} // namespace panda::ecmascript diff --git a/ecmascript/frames.h b/ecmascript/frames.h index 87c558e85dbc892963b68aadb55577d48cd1bbd5..ddb5a19cc0f8a3d5b4f58fb40b62540b3b0ac4f8 100644 --- a/ecmascript/frames.h +++ b/ecmascript/frames.h @@ -106,6 +106,19 @@ // | callSiteSp | v // +--------------------------+ +// Optimized JSFunction Frame Frame(alias OptimizedJSFunctionFrame) layout +// +--------------------------+ +// | calleesave registers | ^ +// |----------------------| | +// | returnaddress | Fixed +// |----------------------| OptimizedJSFunctionFrame +// | prevFp | | +// |----------------------| | +// | frameType | | +// |----------------------| | +// | lexEnv | v +// +--------------------------+ + // Optimized Entry Frame(alias OptimizedEntryFrame) layout // +--------------------------+ // | returnaddress | ^ @@ -194,12 +207,13 @@ // | calleesave registers | ^ ^ // |----------------------| | | // | returnaddress | Fixed | -// |----------------------| OptimizedFrame | +// |----------------------| OptimizedJSFunctionFrame | // | prevFp | | | // |----------------------| | baz's frame Header // | frameType | | | // |----------------------| | | -// | callsitesp | v V +// | lexEnv | | V +// +--------------------------+ // +--------------------------+---------------------------+ // | ............. | // +--------------------------+---------------------------+ @@ -233,24 +247,35 @@ #include "ecmascript/base/aligned_struct.h" +#include "ecmascript/mem/chunk_containers.h" +#include "ecmascript/mem/visitor.h" namespace panda::ecmascript { +class JSThread; +class EcmaVM; +class FrameIterator; +namespace kungfu { + class LLVMStackMapParser; +}; +using DerivedDataKey = std::pair; enum class FrameType: uintptr_t { OPTIMIZED_FRAME = 0, OPTIMIZED_ENTRY_FRAME = 1, OPTIMIZED_JS_FUNCTION_FRAME = 2, LEAVE_FRAME = 3, LEAVE_FRAME_WITH_ARGV = 4, - INTERPRETER_FRAME = 5, - ASM_INTERPRETER_FRAME = 6, - INTERPRETER_CONSTRUCTOR_FRAME = 7, - BUILTIN_FRAME = 8, - BUILTIN_FRAME_WITH_ARGV = 9, - BUILTIN_ENTRY_FRAME = 10, - INTERPRETER_FAST_NEW_FRAME = 11, - INTERPRETER_ENTRY_FRAME = 12, - ASM_INTERPRETER_ENTRY_FRAME = 13, - ASM_INTERPRETER_BRIDGE_FRAME = 14, - OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME = 15, + BUILTIN_CALL_LEAVE_FRAME = 5, + INTERPRETER_FRAME = 6, + ASM_INTERPRETER_FRAME = 7, + INTERPRETER_CONSTRUCTOR_FRAME = 8, + BUILTIN_FRAME = 9, + BUILTIN_FRAME_WITH_ARGV = 10, + BUILTIN_ENTRY_FRAME = 11, + INTERPRETER_BUILTIN_FRAME = 12, + INTERPRETER_FAST_NEW_FRAME = 13, + INTERPRETER_ENTRY_FRAME = 14, + ASM_INTERPRETER_ENTRY_FRAME = 15, + ASM_INTERPRETER_BRIDGE_FRAME = 16, + OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME = 17, INTERPRETER_BEGIN = INTERPRETER_FRAME, INTERPRETER_END = INTERPRETER_FAST_NEW_FRAME, @@ -260,7 +285,7 @@ enum class FrameType: uintptr_t { enum class ReservedSlots: int { OPTIMIZED_RESERVED_SLOT = 1, - OPTIMIZED_JS_FUNCTION_RESERVED_SLOT = 1, + OPTIMIZED_JS_FUNCTION_RESERVED_SLOT = 2, OPTIMIZED_ENTRY_RESERVED_SLOT = 2, }; @@ -286,6 +311,12 @@ struct OptimizedFrame : public base::AlignedStruct { public: + void GCIterate(const FrameIterator &it, + const RootVisitor &v0, + [[maybe_unused]] const RootRangeVisitor &v1, + ChunkMap *derivedPointers, + bool isVerifying) const; +private: enum class Index : size_t { TypeIndex = 0, PrevFpIndex, @@ -303,9 +334,14 @@ public: { return prevFp; } - alignas(EAS) FrameType type {0}; + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + [[maybe_unused]] alignas(EAS) FrameType type {0}; alignas(EAS) JSTaggedType *prevFp {nullptr}; alignas(EAS) uintptr_t returnAddr {0}; + friend class FrameIterator; }; STATIC_ASSERT_EQ_ARCH(sizeof(OptimizedFrame), OptimizedFrame::SizeArch32, OptimizedFrame::SizeArch64); @@ -313,7 +349,7 @@ STATIC_ASSERT_EQ_ARCH(sizeof(OptimizedFrame), OptimizedFrame::SizeArch32, Optimi struct OptimizedJSFunctionArgConfigFrame : public base::AlignedStruct { -public: +private: enum class Index : size_t { TypeIndex = 0, PrevFpIndex, @@ -330,47 +366,75 @@ public: { return prevFp; } - alignas(EAS) FrameType type {0}; + [[maybe_unused]] alignas(EAS) FrameType type {0}; alignas(EAS) JSTaggedType *prevFp {nullptr}; + friend class FrameIterator; }; STATIC_ASSERT_EQ_ARCH(sizeof(OptimizedJSFunctionArgConfigFrame), OptimizedJSFunctionArgConfigFrame::SizeArch32, OptimizedJSFunctionArgConfigFrame::SizeArch64); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) -struct OptimizedJSFunctionFrame : public base::AlignedStruct { public: + static constexpr size_t ENV_SLOT_DIFF = 2; enum class Index : size_t { - TypeIndex = 0, + EnvIndex = 0, + TypeIndex, PrevFpIndex, ReturnAddrIndex, NumOfMembers }; static_assert(static_cast(Index::NumOfMembers) == NumOfTypes); - static OptimizedJSFunctionFrame* GetFrameFromSp(const JSTaggedType *sp) - { - return reinterpret_cast(reinterpret_cast(sp) - - MEMBER_OFFSET(OptimizedJSFunctionFrame, prevFp)); - } inline JSTaggedType* GetPrevFrameFp() { return prevFp; } - uintptr_t* ComputePrevFrameSp(const JSTaggedType *sp, int delta) + uintptr_t* ComputePrevFrameSp(const FrameIterator &it) const; + + JSTaggedType* GetArgv(uintptr_t *preFrameSp) const + { + return reinterpret_cast(preFrameSp + ENV_SLOT_DIFF * sizeof(uint64_t) / sizeof(uintptr_t)); + } + + size_t GetArgc(uintptr_t *preFrameSp) const + { + return *(preFrameSp + sizeof(uint64_t) / sizeof(uintptr_t)); + } + + JSTaggedType* GetArgv(const FrameIterator &it) const; + + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + void GCIterate( + const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1, + ChunkMap *derivedPointers, bool isVerifying) const; + + inline JSTaggedValue GetEnv() const { - uintptr_t *preFrameSp = reinterpret_cast(const_cast(sp)) - + delta / sizeof(uintptr_t); - return preFrameSp; + return env; } - JSTaggedType* GetArgv(uintptr_t *preFrameSp) + inline void SetEnv(JSTaggedValue lexEnv) + { + env = lexEnv; + } + friend class FrameIterator; + +private: + static OptimizedJSFunctionFrame* GetFrameFromSp(const JSTaggedType *sp) { - return reinterpret_cast(preFrameSp + sizeof(uint64_t) / sizeof(uintptr_t)); + return reinterpret_cast(reinterpret_cast(sp) + - MEMBER_OFFSET(OptimizedJSFunctionFrame, prevFp)); } // dynamic callee saveregisters for x86-64 - alignas(EAS) FrameType type {0}; + alignas(EAS) JSTaggedValue env {JSTaggedValue::Hole()}; + [[maybe_unused]] alignas(EAS) FrameType type {0}; alignas(EAS) JSTaggedType *prevFp {nullptr}; alignas(EAS) uintptr_t returnAddr {0}; // dynamic callee saveregisters for arm64 @@ -387,14 +451,15 @@ public: OptimizedEntryFrame() = default; ~OptimizedEntryFrame() = default; JSTaggedType *preLeaveFrameFp; - FrameType type; + [[maybe_unused]] FrameType type; JSTaggedType *prevFp; inline JSTaggedType* GetPrevFrameFp() { return preLeaveFrameFp; } - + friend class FrameIterator; +private: static OptimizedEntryFrame* GetFrameFromSp(const JSTaggedType *sp) { return reinterpret_cast(reinterpret_cast(sp) - @@ -449,6 +514,7 @@ struct InterpretedFrame : public base::AlignedStruct { +public: enum class Index : size_t { ConstPoolIndex = 0, FunctionIndex, @@ -461,7 +527,7 @@ struct InterpretedFrame : public base::AlignedStruct(Index::NumOfMembers) == NumOfTypes); - inline JSTaggedType* GetPrevFrameFp() + inline JSTaggedType* GetPrevFrameFp() const { return base.prev; } @@ -470,10 +536,22 @@ struct InterpretedFrame : public base::AlignedStruct(const_cast(sp)) - 1; } + + inline const uint8_t *GetPc() const + { + return pc; + } + + inline JSTaggedValue GetEnv() const + { + return env; + } + static uint32_t NumOfMembers() { return sizeof(InterpretedFrame) / JSTaggedValue::TaggedTypeSize(); } + void GCIterate(const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1) const; alignas(EAS) JSTaggedValue constpool {JSTaggedValue::Hole()}; alignas(EAS) JSTaggedValue function {JSTaggedValue::Hole()}; @@ -482,9 +560,48 @@ struct InterpretedFrame : public base::AlignedStruct { + enum class Index : size_t { + FunctionIndex = 0, + PcIndex, + BaseIndex, + NumOfMembers + }; + static_assert(static_cast(Index::NumOfMembers) == NumOfTypes); + + inline JSTaggedType* GetPrevFrameFp() + { + return base.prev; + } + + static InterpretedBuiltinFrame* GetFrameFromSp(const JSTaggedType *sp) + { + return reinterpret_cast(const_cast(sp)) - 1; + } + + static uint32_t NumOfMembers() + { + return sizeof(InterpretedBuiltinFrame) / JSTaggedValue::TaggedTypeSize(); + } + + void GCIterate(const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1) const; + + alignas(EAS) JSTaggedValue function {JSTaggedValue::Hole()}; + alignas(EAS) const uint8_t *pc {nullptr}; + alignas(EAS) InterpretedFrameBase base; +}; +STATIC_ASSERT_EQ_ARCH(sizeof(InterpretedBuiltinFrame), + InterpretedBuiltinFrame::SizeArch32, + InterpretedBuiltinFrame::SizeArch64); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) struct AsmInterpretedFrame : public base::AlignedStruct *derivedPointers, bool isVerifying) const; + + JSTaggedValue GetEnv() const + { + return env; + } + + const uint8_t *GetPc() + { + return pc; + } alignas(EAS) JSTaggedValue function {JSTaggedValue::Hole()}; alignas(EAS) JSTaggedValue acc {JSTaggedValue::Hole()}; @@ -603,6 +732,13 @@ struct InterpretedEntryFrame : public base::AlignedStruct(const_cast(sp)) - 1; } + static uint32_t NumOfMembers() + { + return sizeof(InterpretedEntryFrame) / JSTaggedValue::TaggedTypeSize(); + } + + void GCIterate(const FrameIterator &it, const RootVisitor &v0, + const RootRangeVisitor &v1) const; alignas(EAS) const uint8_t *pc {nullptr}; alignas(EAS) InterpretedFrameBase base; }; @@ -651,7 +787,7 @@ struct AsmInterpretedBridgeFrame : public base::AlignedStruct(reinterpret_cast(sp) - MEMBER_OFFSET(AsmInterpretedBridgeFrame, returnAddr)); } - uintptr_t GetCallSiteSp() + uintptr_t GetCallSiteSp() const { return ToUintPtr(this) + sizeof(AsmInterpretedBridgeFrame); } @@ -662,6 +798,10 @@ struct AsmInterpretedBridgeFrame : public base::AlignedStruct(reinterpret_cast(sp) - MEMBER_OFFSET(OptimizedLeaveFrame, callsiteFp)); } - uintptr_t GetCallSiteSp() + uintptr_t GetCallSiteSp() const { #ifndef PANDA_TARGET_32 return ToUintPtr(this) + MEMBER_OFFSET(OptimizedLeaveFrame, argRuntimeId); @@ -686,10 +826,20 @@ struct OptimizedLeaveFrame { return ToUintPtr(this) + MEMBER_OFFSET(OptimizedLeaveFrame, argc) + argc * sizeof(JSTaggedType); #endif } - inline JSTaggedType* GetPrevFrameFp() + inline JSTaggedType* GetPrevFrameFp() const { return reinterpret_cast(callsiteFp); } + + JSTaggedType *GetJsFuncFrameArgv(JSThread *thread) const; + + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + void GCIterate( + const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1, + ChunkMap *derivedPointers, bool isVerifying) const; }; struct OptimizedWithArgvLeaveFrame { @@ -706,7 +856,7 @@ struct OptimizedWithArgvLeaveFrame { return reinterpret_cast(reinterpret_cast(sp) - MEMBER_OFFSET(OptimizedWithArgvLeaveFrame, callsiteFp)); } - uintptr_t GetCallSiteSp() + uintptr_t GetCallSiteSp() const { #ifndef PANDA_TARGET_32 return ToUintPtr(this) + MEMBER_OFFSET(OptimizedWithArgvLeaveFrame, argRuntimeId); @@ -718,6 +868,46 @@ struct OptimizedWithArgvLeaveFrame { { return reinterpret_cast(callsiteFp); } + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + void GCIterate( + const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1, + ChunkMap *derivedPointers, bool isVerifying) const; +}; + +struct OptimizedBuiltinLeaveFrame { +public: + static OptimizedBuiltinLeaveFrame* GetFrameFromSp(const JSTaggedType *sp) + { + return reinterpret_cast(reinterpret_cast(sp) - + MEMBER_OFFSET(OptimizedBuiltinLeaveFrame, callsiteFp)); + } + uintptr_t GetCallSiteSp() const + { + return ToUintPtr(this) + MEMBER_OFFSET(OptimizedBuiltinLeaveFrame, argRuntimeId); + } + inline JSTaggedType* GetPrevFrameFp() const + { + return reinterpret_cast(callsiteFp); + } + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + void GCIterate( + const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1, + ChunkMap *derivedPointers, bool isVerifying) const; + +private: + [[maybe_unused]] FrameType type; + uintptr_t callsiteFp; // thread sp set here + uintptr_t returnAddr; + [[maybe_unused]] uint64_t argRuntimeId; + JSTaggedValue env; + uint64_t argc; + // argv[0]...argv[argc-1] dynamic according to agc }; struct BuiltinFrame : public base::AlignedStruct(Index::NumOfMembers) == NumOfTypes); - static constexpr uint32_t RESERVED_CALL_ARGCOUNT = 3; - static BuiltinFrame* GetFrameFromSp(const JSTaggedType *sp) { return reinterpret_cast(reinterpret_cast(sp) - @@ -749,9 +937,9 @@ struct BuiltinFrame : public base::AlignedStruct(Index::NumArgsIndex)>(isArch32); return offset - GetPreFpOffset(isArch32); } - - static size_t GetNativeCodeToFpDelta(bool isArch32) - { - auto offset = GetOffset(Index::NativeCodeIndex)>(isArch32); - return offset - GetPreFpOffset(isArch32); - } static size_t GetStackArgsToFpDelta(bool isArch32) { auto offset = GetOffset(Index::StackArgsIndex)>(isArch32); @@ -782,16 +964,23 @@ struct BuiltinFrame : public base::AlignedStruct(GetStackArgsAddress()); return JSTaggedValue(*functionAddress); } - size_t GetNumArgs() + int32_t GetNumArgs() { - return numArgs & 0xFFFFFFFF; + return numArgs; } + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + void GCIterate( + const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1, + ChunkMap *derivedPointers, bool isVerifying) const; alignas(EAS) FrameType type; alignas(EAS) JSTaggedType *prevFp; alignas(EAS) uintptr_t returnAddr; - alignas(EAS) uintptr_t nativeCode; - alignas(EAS) uintptr_t numArgs; + alignas(EAS) uintptr_t thread; + alignas(EAS) int32_t numArgs; alignas(EAS) uintptr_t stackArgs; }; @@ -818,7 +1007,7 @@ struct BuiltinWithArgvFrame : public base::AlignedStruct(Index::StackArgsTopIndex) * sizeof(uintptr_t)); - auto numberArgs = GetNumArgs() + BuiltinFrame::RESERVED_CALL_ARGCOUNT; - return topAddress - numberArgs * sizeof(uintptr_t); + auto numberArgs = GetNumArgs() + NUM_MANDATORY_JSFUNC_ARGS; + return topAddress - static_cast(numberArgs) * sizeof(uintptr_t); } JSTaggedValue GetFunction() { auto functionAddress = reinterpret_cast(GetStackArgsAddress()); return JSTaggedValue(*functionAddress); } - size_t GetNumArgs() + int32_t GetNumArgs() { - auto argcAddress = reinterpret_cast( + auto argcAddress = reinterpret_cast( ToUintPtr(this) + (static_cast(Index::NumArgsIndex) * sizeof(uintptr_t))); return *argcAddress; } + uintptr_t GetReturnAddr() const + { + return returnAddr; + } + void GCIterate( + const FrameIterator &it, const RootVisitor &v0, const RootRangeVisitor &v1, + ChunkMap *derivedPointers, bool isVerifying) const; // argv(... this, new.target, function) // numargs alignas(EAS) FrameType type; alignas(EAS) JSTaggedType *prevFp; alignas(EAS) uintptr_t returnAddr; }; + +class FrameIterator { +public: + explicit FrameIterator(JSTaggedType *sp, const JSThread *thread = nullptr); + FrameType GetFrameType() const + { + ASSERT(current_ != nullptr); + FrameType *typeAddr = reinterpret_cast( + reinterpret_cast(current_) - sizeof(FrameType)); + return *typeAddr; + } + + template + T* GetFrame() + { + return T::GetFrameFromSp(current_); + } + + template + const T* GetFrame() const + { + return T::GetFrameFromSp(current_); + } + + bool Done() const + { + return current_ == nullptr; + } + JSTaggedType *GetSp() const + { + return current_; + } + JSTaggedType *GetSp() + { + return current_; + } + int ComputeDelta() const; + void Advance(); + uintptr_t GetPrevFrameCallSiteSp(uintptr_t curPc = 0) const; + uintptr_t GetPrevFrame() const; + uintptr_t GetCallSiteSp() const + { + return optimizedCallSiteSp_; + } + uintptr_t GetOptimizedReturnAddr() const + { + return optimizedReturnAddr_; + } + const JSThread *GetThread() const + { + return thread_; + } + bool CollectGCSlots(std::set &baseSet, ChunkMap *data, + bool isVerifying) const; +private: + JSTaggedType *current_ {nullptr}; + const JSThread *thread_ {nullptr}; + const kungfu::LLVMStackMapParser *stackmapParser_ {nullptr}; + uintptr_t optimizedCallSiteSp_ {0}; + uintptr_t optimizedReturnAddr_ {0}; +}; } // namespace panda::ecmascript -#endif // ECMASCRIPT_FRAMES_H +#endif // ECMASCRIPT_FRAMES_H \ No newline at end of file diff --git a/ecmascript/global_env.h b/ecmascript/global_env.h index 0b58dbe4041d126ee13dd93c5925e14a1c72658c..22966e4c36624b82983782821c1dff6e6ada730c 100644 --- a/ecmascript/global_env.h +++ b/ecmascript/global_env.h @@ -61,6 +61,7 @@ class JSThread; V(JSTaggedValue, RangeErrorFunction, RANGE_ERROR_FUNCTION_INDEX) \ V(JSTaggedValue, ReferenceErrorFunction, REFERENCE_ERROR_FUNCTION_INDEX) \ V(JSTaggedValue, TypeErrorFunction, TYPE_ERROR_FUNCTION_INDEX) \ + V(JSTaggedValue, AggregateErrorFunction, AGGREGATE_ERROR_FUNCTION_INDEX) \ V(JSTaggedValue, URIErrorFunction, URI_ERROR_FUNCTION_INDEX) \ V(JSTaggedValue, SyntaxErrorFunction, SYNTAX_ERROR_FUNCTION_INDEX) \ V(JSTaggedValue, EvalErrorFunction, EVAL_ERROR_FUNCTION_INDEX) \ @@ -137,6 +138,10 @@ class JSThread; V(JSTaggedValue, PromiseExecutorFunctionClass, PROMISE_EXECUTOR_FUNCTION_CLASS) \ V(JSTaggedValue, GeneratorFunctionClass, GENERATOR_FUNCTION_CLASS) \ V(JSTaggedValue, PromiseAllResolveElementFunctionClass, PROMISE_ALL_RESOLVE_ELEMENT_FUNC_CLASS) \ + V(JSTaggedValue, PromiseAnyRejectElementFunctionClass, PROMISE_ANY_REJECT_ELEMENT_FUNC_CLASS) \ + V(JSTaggedValue, PromiseAllSettledElementFunctionClass, PROMISE_ALL_SETTLED_ELEMENT_FUNC_CLASS) \ + V(JSTaggedValue, PromiseFinallyFunctionClass, PROMISE_FINALLY_FUNC_CLASS) \ + V(JSTaggedValue, PromiseValueThunkOrThrowerFunctionClass, PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION_CLASS) \ V(JSTaggedValue, ProxyRevocFunctionClass, PROXY_REVOC_FUNCTION_CLASS) \ V(JSTaggedValue, NativeErrorFunctionClass, NATIVE_ERROR_FUNCTION_CLASS) \ V(JSTaggedValue, SpecificTypedArrayFunctionClass, SPERCIFIC_TYPED_ARRAY_FUNCTION_CLASS) \ @@ -183,9 +188,8 @@ public: } void Init(JSThread *thread); - void InitGlobalObject(); - static GlobalEnv *Cast(ObjectHeader *object) + static GlobalEnv *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSGlobalEnv()); return reinterpret_cast(object); @@ -200,7 +204,7 @@ public: #define GLOBAL_ENV_SLOT(type, name, index) index, GLOBAL_ENV_FIELDS(GLOBAL_ENV_SLOT) #undef GLOBAL_ENV_SLOT - FINAL_INDEX + FINAL_INDEX }; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) diff --git a/ecmascript/global_env_constants.cpp b/ecmascript/global_env_constants.cpp index cdcdce5b584b1569fd347544a31910da3762c7a9..50df476a8b97d95a9cfbd2196175ca6cd6036187 100644 --- a/ecmascript/global_env_constants.cpp +++ b/ecmascript/global_env_constants.cpp @@ -29,6 +29,8 @@ #include "ecmascript/jobs/pending_job.h" #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list_iterator.h" #include "ecmascript/js_api_plain_array_iterator.h" @@ -79,72 +81,75 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl SetConstant(ConstantIndex::HCLASS_CLASS_INDEX, JSTaggedValue(dynClassClass)); SetConstant(ConstantIndex::FREE_OBJECT_WITH_NONE_FIELD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, FreeObject::NEXT_OFFSET, JSType::FREE_OBJECT_WITH_NONE_FIELD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, FreeObject::NEXT_OFFSET, JSType::FREE_OBJECT_WITH_NONE_FIELD)); SetConstant(ConstantIndex::FREE_OBJECT_WITH_ONE_FIELD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE_OFFSET, JSType::FREE_OBJECT_WITH_ONE_FIELD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, FreeObject::SIZE_OFFSET, JSType::FREE_OBJECT_WITH_ONE_FIELD)); SetConstant(ConstantIndex::FREE_OBJECT_WITH_TWO_FIELD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD)); - SetConstant(ConstantIndex::STRING_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::STRING)); - SetConstant(ConstantIndex::ARRAY_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, FreeObject::SIZE, JSType::FREE_OBJECT_WITH_TWO_FIELD)); + SetConstant(ConstantIndex::STRING_CLASS_INDEX, factory->NewEcmaReadOnlyDynClass(dynClassClass, 0, JSType::STRING)); + SetConstant(ConstantIndex::ARRAY_CLASS_INDEX, + factory->NewEcmaReadOnlyDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY)); InitGlobalConstantSpecial(thread); SetConstant(ConstantIndex::DICTIONARY_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_DICTIONARY)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, 0, JSType::TAGGED_DICTIONARY)); SetConstant(ConstantIndex::BIGINT_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, BigInt::SIZE, JSType::BIGINT)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, BigInt::SIZE, JSType::BIGINT)); SetConstant(ConstantIndex::JS_NATIVE_POINTER_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, JSNativePointer::SIZE, JSType::JS_NATIVE_POINTER)); - SetConstant(ConstantIndex::ENV_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, JSNativePointer::SIZE, JSType::JS_NATIVE_POINTER)); + SetConstant(ConstantIndex::ENV_CLASS_INDEX, + factory->NewEcmaReadOnlyDynClass(dynClassClass, 0, JSType::TAGGED_ARRAY)); SetConstant(ConstantIndex::SYMBOL_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, JSSymbol::SIZE, JSType::SYMBOL)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, JSSymbol::SIZE, JSType::SYMBOL)); SetConstant(ConstantIndex::ACCESSOR_DATA_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::ACCESSOR_DATA)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, AccessorData::SIZE, JSType::ACCESSOR_DATA)); SetConstant(ConstantIndex::INTERNAL_ACCESSOR_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, AccessorData::SIZE, JSType::INTERNAL_ACCESSOR)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, AccessorData::SIZE, JSType::INTERNAL_ACCESSOR)); SetConstant(ConstantIndex::JS_PROXY_ORDINARY_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY)); SetConstant(ConstantIndex::COMPLETION_RECORD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, CompletionRecord::SIZE, JSType::COMPLETION_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, CompletionRecord::SIZE, JSType::COMPLETION_RECORD)); SetConstant(ConstantIndex::GENERATOR_CONTEST_INDEX, - factory->NewEcmaDynClass(dynClassClass, GeneratorContext::SIZE, JSType::JS_GENERATOR_CONTEXT)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, GeneratorContext::SIZE, JSType::JS_GENERATOR_CONTEXT)); SetConstant(ConstantIndex::CAPABILITY_RECORD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, PromiseCapability::SIZE, JSType::PROMISE_CAPABILITY)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, PromiseCapability::SIZE, JSType::PROMISE_CAPABILITY)); SetConstant(ConstantIndex::REACTIONS_RECORD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, PromiseReaction::SIZE, JSType::PROMISE_REACTIONS)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, PromiseReaction::SIZE, JSType::PROMISE_REACTIONS)); SetConstant(ConstantIndex::PROMISE_ITERATOR_RECORD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, PromiseIteratorRecord::SIZE, JSType::PROMISE_ITERATOR_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, PromiseIteratorRecord::SIZE, + JSType::PROMISE_ITERATOR_RECORD)); SetConstant(ConstantIndex::PROMISE_RECORD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, PromiseRecord::SIZE, JSType::PROMISE_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, PromiseRecord::SIZE, JSType::PROMISE_RECORD)); SetConstant(ConstantIndex::PROMISE_RESOLVING_FUNCTIONS_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ResolvingFunctionsRecord::SIZE, - JSType::RESOLVING_FUNCTIONS_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ResolvingFunctionsRecord::SIZE, + JSType::RESOLVING_FUNCTIONS_RECORD)); SetConstant(ConstantIndex::MICRO_JOB_QUEUE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, job::MicroJobQueue::SIZE, JSType::MICRO_JOB_QUEUE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, job::MicroJobQueue::SIZE, JSType::MICRO_JOB_QUEUE)); SetConstant(ConstantIndex::PENDING_JOB_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, job::PendingJob::SIZE, JSType::PENDING_JOB)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, job::PendingJob::SIZE, JSType::PENDING_JOB)); SetConstant(ConstantIndex::PROTO_CHANGE_MARKER_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ProtoChangeMarker::SIZE, JSType::PROTO_CHANGE_MARKER)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ProtoChangeMarker::SIZE, JSType::PROTO_CHANGE_MARKER)); SetConstant(ConstantIndex::PROTO_CHANGE_DETAILS_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ProtoChangeDetails::SIZE, JSType::PROTOTYPE_INFO)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ProtoChangeDetails::SIZE, JSType::PROTOTYPE_INFO)); SetConstant(ConstantIndex::PROTOTYPE_HANDLER_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, PrototypeHandler::SIZE, JSType::PROTOTYPE_HANDLER)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, PrototypeHandler::SIZE, JSType::PROTOTYPE_HANDLER)); SetConstant(ConstantIndex::TRANSITION_HANDLER_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TransitionHandler::SIZE, JSType::TRANSITION_HANDLER)); SetConstant(ConstantIndex::PROPERTY_BOX_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, PropertyBox::SIZE, JSType::PROPERTY_BOX)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, PropertyBox::SIZE, JSType::PROPERTY_BOX)); SetConstant(ConstantIndex::PROGRAM_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, Program::SIZE, JSType::PROGRAM)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, Program::SIZE, JSType::PROGRAM)); SetConstant( ConstantIndex::IMPORT_ENTRY_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ImportEntry::SIZE, JSType::IMPORTENTRY_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ImportEntry::SIZE, JSType::IMPORTENTRY_RECORD)); SetConstant( ConstantIndex::EXPORT_ENTRY_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ExportEntry::SIZE, JSType::EXPORTENTRY_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ExportEntry::SIZE, JSType::EXPORTENTRY_RECORD)); SetConstant( ConstantIndex::SOURCE_TEXT_MODULE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, SourceTextModule::SIZE, JSType::SOURCE_TEXT_MODULE_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, SourceTextModule::SIZE, JSType::SOURCE_TEXT_MODULE_RECORD)); SetConstant( ConstantIndex::RESOLVED_BINDING_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ResolvedBinding::SIZE, JSType::RESOLVEDBINDING_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ResolvedBinding::SIZE, JSType::RESOLVEDBINDING_RECORD)); JSHClass *jsProxyCallableClass = *factory->NewEcmaDynClass(dynClassClass, JSProxy::SIZE, JSType::JS_PROXY); @@ -160,25 +165,27 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl SetConstant(ConstantIndex::JS_REALM_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, JSRealm::SIZE, JSType::JS_REALM)); SetConstant(ConstantIndex::MACHINE_CODE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, 0, JSType::MACHINE_CODE_OBJECT)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, 0, JSType::MACHINE_CODE_OBJECT)); SetConstant(ConstantIndex::CLASS_INFO_EXTRACTOR_HCLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, ClassInfoExtractor::SIZE, JSType::CLASS_INFO_EXTRACTOR)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, ClassInfoExtractor::SIZE, + JSType::CLASS_INFO_EXTRACTOR)); SetConstant(ConstantIndex::TS_OBJECT_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSObjectType::SIZE, JSType::TS_OBJECT_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSObjectType::SIZE, JSType::TS_OBJECT_TYPE)); SetConstant(ConstantIndex::TS_CLASS_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSClassType::SIZE, JSType::TS_CLASS_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSClassType::SIZE, JSType::TS_CLASS_TYPE)); SetConstant(ConstantIndex::TS_UNION_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSUnionType::SIZE, JSType::TS_UNION_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSUnionType::SIZE, JSType::TS_UNION_TYPE)); SetConstant(ConstantIndex::TS_INTERFACE_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSInterfaceType::SIZE, JSType::TS_INTERFACE_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSInterfaceType::SIZE, JSType::TS_INTERFACE_TYPE)); SetConstant(ConstantIndex::TS_CLASS_INSTANCE_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSClassInstanceType::SIZE, JSType::TS_CLASS_INSTANCE_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSClassInstanceType::SIZE, + JSType::TS_CLASS_INSTANCE_TYPE)); SetConstant(ConstantIndex::TS_IMPORT_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSImportType::SIZE, JSType::TS_IMPORT_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSImportType::SIZE, JSType::TS_IMPORT_TYPE)); SetConstant(ConstantIndex::TS_FUNCTION_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSFunctionType::SIZE, JSType::TS_FUNCTION_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSFunctionType::SIZE, JSType::TS_FUNCTION_TYPE)); SetConstant(ConstantIndex::TS_ARRAY_TYPE_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, TSArrayType::SIZE, JSType::TS_ARRAY_TYPE)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, TSArrayType::SIZE, JSType::TS_ARRAY_TYPE)); SetConstant(ConstantIndex::JS_REGEXP_ITERATOR_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, JSRegExpIterator::SIZE, JSType::JS_REG_EXP_ITERATOR)); SetConstant(ConstantIndex::JS_SET_ITERATOR_CLASS_INDEX, @@ -192,6 +199,12 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl factory->NewEcmaDynClass(dynClassClass, JSAPIArrayListIterator::SIZE, JSType::JS_API_ARRAYLIST_ITERATOR)); SetConstant(ConstantIndex::JS_API_DEQUE_ITERATOR_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, JSAPIDequeIterator::SIZE, JSType::JS_API_DEQUE_ITERATOR)); + SetConstant(ConstantIndex::JS_API_LIGHTWEIGHTMAP_ITERATOR_CLASS_INDEX, + factory->NewEcmaDynClass(dynClassClass, JSAPILightWeightMapIterator::SIZE, + JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR)); + SetConstant(ConstantIndex::JS_API_LIGHTWEIGHTSET_ITERATOR_CLASS_INDEX, + factory->NewEcmaDynClass(dynClassClass, JSAPILightWeightSetIterator::SIZE, + JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR)); SetConstant( ConstantIndex::JS_API_LINKED_LIST_ITERATOR_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, JSAPILinkedListIterator::SIZE, JSType::JS_API_LINKED_LIST_ITERATOR)); @@ -211,7 +224,7 @@ void GlobalEnvConstants::InitRootsClass([[maybe_unused]] JSThread *thread, JSHCl SetConstant(ConstantIndex::JS_API_TREE_SET_ITERATOR_CLASS_INDEX, factory->NewEcmaDynClass(dynClassClass, JSAPITreeSetIterator::SIZE, JSType::JS_API_TREESET_ITERATOR)); SetConstant(ConstantIndex::CELL_RECORD_CLASS_INDEX, - factory->NewEcmaDynClass(dynClassClass, CellRecord::SIZE, JSType::CELL_RECORD)); + factory->NewEcmaReadOnlyDynClass(dynClassClass, CellRecord::SIZE, JSType::CELL_RECORD)); SetConstant(ConstantIndex::OBJECT_DYN_CLASS_INDEX, factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT)); } @@ -244,7 +257,6 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread) SetConstant(ConstantIndex::CONFIGURABLE_STRING_INDEX, factory->NewFromASCIINonMovable("configurable")); /* non ECMA standard jsapi containers iterators, init to Undefined first */ InitJSAPIContainers(); - /* SymbolTable *RegisterSymbols */ SetConstant(ConstantIndex::NAME_STRING_INDEX, factory->NewFromASCIINonMovable("name")); SetConstant(ConstantIndex::GETPROTOTYPEOF_STRING_INDEX, factory->NewFromASCIINonMovable("getPrototypeOf")); @@ -284,6 +296,11 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread) SetConstant(ConstantIndex::PROXY_CALL_STRING_INDEX, factory->NewFromASCIINonMovable("call")); SetConstant(ConstantIndex::PROMISE_THEN_STRING_INDEX, factory->NewFromASCIINonMovable("then")); SetConstant(ConstantIndex::PROMISE_CATCH_STRING_INDEX, factory->NewFromASCIINonMovable("catch")); + SetConstant(ConstantIndex::PROMISE_FINALLY_STRING_INDEX, factory->NewFromASCII("finally")); + SetConstant(ConstantIndex::PROMISE_STATUS_STRING_INDEX, factory->NewFromASCII("status")); + SetConstant(ConstantIndex::PROMISE_FULFILLED_STRING_INDEX, factory->NewFromASCII("fulfilled")); + SetConstant(ConstantIndex::PROMISE_REJECTED_STRING_INDEX, factory->NewFromASCII("rejected")); + SetConstant(ConstantIndex::PROMISE_REASON_STRING_INDEX, factory->NewFromASCII("reason")); SetConstant(ConstantIndex::SCRIPT_JOB_STRING_INDEX, factory->NewFromASCIINonMovable("ScriptJobs")); SetConstant(ConstantIndex::PROMISE_STRING_INDEX, factory->NewFromASCIINonMovable("PrimiseJobs")); SetConstant(ConstantIndex::THROWER_STRING_INDEX, factory->NewFromASCIINonMovable("Thrower")); @@ -312,6 +329,8 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread) SetConstant(ConstantIndex::GLOBAL_STRING_INDEX, factory->NewFromASCIINonMovable("global")); SetConstant(ConstantIndex::MESSAGE_STRING_INDEX, factory->NewFromASCIINonMovable("message")); SetConstant(ConstantIndex::ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("Error")); + SetConstant(ConstantIndex::ERRORS_STRING_INDEX, factory->NewFromASCII("errors")); + SetConstant(ConstantIndex::AGGREGATE_ERROR_STRING_INDEX, factory->NewFromASCII("AggregateError")); SetConstant(ConstantIndex::RANGE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("RangeError")); SetConstant(ConstantIndex::REFERENCE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("ReferenceError")); SetConstant(ConstantIndex::TYPE_ERROR_STRING_INDEX, factory->NewFromASCIINonMovable("TypeError")); @@ -388,6 +407,7 @@ void GlobalEnvConstants::InitGlobalConstant(JSThread *thread) SetConstant(ConstantIndex::FRACTION_STRING_INDEX, factory->NewFromASCIINonMovable("fraction")); SetConstant(ConstantIndex::DECIMAL_STRING_INDEX, factory->NewFromASCIINonMovable("decimal")); SetConstant(ConstantIndex::GROUP_STRING_INDEX, factory->NewFromASCIINonMovable("group")); + SetConstant(ConstantIndex::GROUPS_STRING_INDEX, factory->NewFromASCIINonMovable("groups")); SetConstant(ConstantIndex::CURRENCY_STRING_INDEX, factory->NewFromASCIINonMovable("currency")); SetConstant(ConstantIndex::CURRENCY_SIGN_STRING_INDEX, factory->NewFromASCIINonMovable("currencySign")); SetConstant(ConstantIndex::CURRENCY_DISPLAY_STRING_INDEX, factory->NewFromASCIINonMovable("currencyDisplay")); diff --git a/ecmascript/global_env_constants.h b/ecmascript/global_env_constants.h index 72a64c5b5780825a028c2ba54d5146382cc14150..bbff81c96cab579159b5f5a13dc8a596b2ff0308 100644 --- a/ecmascript/global_env_constants.h +++ b/ecmascript/global_env_constants.h @@ -84,9 +84,11 @@ class JSThread; V(JSTaggedValue, JSArrayIteratorClass, JS_ARRAY_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPIArrayListIteratorClass, JS_API_ARRAYLIST_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPIDequeIteratorClass, JS_API_DEQUE_ITERATOR_CLASS_INDEX, ecma_roots_class) \ - V(JSTaggedValue, JSAPIPlainArrayIteratorClass, JS_API_PLAIN_ARRAY_ITERATOR_CLASS_INDEX, ecma_roots_class) \ + V(JSTaggedValue, JSAPILightWeightMapIteratorClass, JS_API_LIGHTWEIGHTMAP_ITERATOR_CLASS_INDEX, ecma_roots_class) \ + V(JSTaggedValue, JSAPILightWeightSetIteratorClass, JS_API_LIGHTWEIGHTSET_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPILinkedListIteratorClass, JS_API_LINKED_LIST_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPIListIteratorClass, JS_API_LIST_ITERATOR_CLASS_INDEX, ecma_roots_class) \ + V(JSTaggedValue, JSAPIPlainArrayIteratorClass, JS_API_PLAIN_ARRAY_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPIQueueIteratorClass, JS_API_QUEUE_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPIStackIteratorClass, JS_API_STACK_ITERATOR_CLASS_INDEX, ecma_roots_class) \ V(JSTaggedValue, JSAPIVectorIteratorClass, JS_API_VECTOR_ITERATOR_CLASS_INDEX, ecma_roots_class) \ @@ -119,6 +121,8 @@ class JSThread; /* non ECMA standard jsapi containers iterators */ \ V(JSTaggedValue, ArrayListFunction, ARRAYLIST_FUNCTION_INDEX, ArrayListFunction) \ V(JSTaggedValue, ArrayListIteratorPrototype, ARRAYLIST_ITERATOR_PROTOTYPE_INDEX, ArrayListIterator) \ + V(JSTaggedValue, LightWeightMapIteratorPrototype, LIGHTWEIGHTMAP_ITERATOR_PROTOTYPE_INDEX, LightWeightMapIterator) \ + V(JSTaggedValue, LightWeightSetIteratorPrototype, LIGHTWEIGHTSET_ITERATOR_PROTOTYPE_INDEX, LightWeightSetIterator) \ V(JSTaggedValue, TreeMapIteratorPrototype, TREEMAP_ITERATOR_PROTOTYPE_INDEX, TreeMapIterator) \ V(JSTaggedValue, TreeSetIteratorPrototype, TREESET_ITERATOR_PROTOTYPE_INDEX, TreeSetIterator) \ V(JSTaggedValue, VectorFunction, VECTOR_FUNCTION_INDEX, VectorFunction) \ @@ -169,6 +173,11 @@ class JSThread; V(JSTaggedValue, ProxyCallString, PROXY_CALL_STRING_INDEX, call) \ V(JSTaggedValue, PromiseThenString, PROMISE_THEN_STRING_INDEX, then) \ V(JSTaggedValue, PromiseCatchString, PROMISE_CATCH_STRING_INDEX, catch) \ + V(JSTaggedValue, PromiseFinallyString, PROMISE_FINALLY_STRING_INDEX, finally) \ + V(JSTaggedValue, PromiseStatusString, PROMISE_STATUS_STRING_INDEX, status) \ + V(JSTaggedValue, PromiseFulfilledString, PROMISE_FULFILLED_STRING_INDEX, fulfilled) \ + V(JSTaggedValue, PromiseRejectedString, PROMISE_REJECTED_STRING_INDEX, rejected) \ + V(JSTaggedValue, PromiseReasonString, PROMISE_REASON_STRING_INDEX, reason) \ V(JSTaggedValue, ScriptJobString, SCRIPT_JOB_STRING_INDEX, ScriptJobs) \ V(JSTaggedValue, PromiseString, PROMISE_STRING_INDEX, PrimiseJobs) \ V(JSTaggedValue, ThrowerString, THROWER_STRING_INDEX, Thrower) \ @@ -199,6 +208,8 @@ class JSThread; V(JSTaggedValue, RangeErrorString, RANGE_ERROR_STRING_INDEX, RangeError) \ V(JSTaggedValue, ReferenceErrorString, REFERENCE_ERROR_STRING_INDEX, ReferenceError) \ V(JSTaggedValue, TypeErrorString, TYPE_ERROR_STRING_INDEX, TypeError) \ + V(JSTaggedValue, ErrorsString, ERRORS_STRING_INDEX, Errors) \ + V(JSTaggedValue, AggregateErrorString, AGGREGATE_ERROR_STRING_INDEX, AggregateError) \ V(JSTaggedValue, URIErrorString, URI_ERROR_STRING_INDEX, URIError) \ V(JSTaggedValue, SyntaxErrorString, SYNTAX_ERROR_STRING_INDEX, SyntaxError) \ V(JSTaggedValue, EvalErrorString, EVAL_ERROR_STRING_INDEX, EvalError) \ @@ -269,6 +280,7 @@ class JSThread; V(JSTaggedValue, FractionString, FRACTION_STRING_INDEX, fraction) \ V(JSTaggedValue, DecimalString, DECIMAL_STRING_INDEX, decimal) \ V(JSTaggedValue, GroupString, GROUP_STRING_INDEX, group) \ + V(JSTaggedValue, GroupsString, GROUPS_STRING_INDEX, groups) \ V(JSTaggedValue, CurrencyString, CURRENCY_STRING_INDEX, currency) \ V(JSTaggedValue, CurrencySignString, CURRENCY_SIGN_STRING_INDEX, currencySign) \ V(JSTaggedValue, CurrencyDisplayString, CURRENCY_DISPLAY_STRING_INDEX, currencyDisplay) \ @@ -400,7 +412,6 @@ enum class ConstantIndex : size_t { READ_ONLY_CONSTATNT_END = CONSTATNT_END, JSAPI_CONTAINERS_BEGIN = ARRAYLIST_FUNCTION_INDEX, JSAPI_CONTAINERS_END = LINKED_LIST_ITERATOR_PROTOTYPE_INDEX, - HCLASS_END = CELL_RECORD_CLASS_INDEX, // ... }; // clang-format on @@ -456,11 +467,6 @@ public: return constants_[index]; } - size_t GetHClassEndIndex() const - { - return static_cast(ConstantIndex::HCLASS_END); - } - size_t GetConstantCount() const { return static_cast(ConstantIndex::CONSTATNT_COUNT); diff --git a/ecmascript/ic/ic_handler.h b/ecmascript/ic/ic_handler.h index 5e200ecfcde93535a944673eb7ee22cb8866aa50..f4e43ac9d64e698e511f8afe2e85566f2dbff36c 100644 --- a/ecmascript/ic/ic_handler.h +++ b/ecmascript/ic/ic_handler.h @@ -193,7 +193,7 @@ public: JSHandle handler = factory->NewTransitionHandler(); JSHandle handlerInfo = StoreHandler::StoreProperty(thread, op); handler->SetHandlerInfo(thread, handlerInfo); - auto hclass = JSObject::Cast(op.GetReceiver()->GetHeapObject())->GetJSHClass(); + auto hclass = JSObject::Cast(op.GetReceiver()->GetTaggedObject())->GetJSHClass(); handler->SetTransitionHClass(thread, JSTaggedValue(hclass)); return JSHandle::Cast(handler); } diff --git a/ecmascript/ic/ic_runtime.cpp b/ecmascript/ic/ic_runtime.cpp index 85f1921ab2611029f32c1b5134b242decd73b636..8bc27d14728abce62205c30414a9640821bb634f 100644 --- a/ecmascript/ic/ic_runtime.cpp +++ b/ecmascript/ic/ic_runtime.cpp @@ -122,11 +122,11 @@ void ICRuntime::TraceIC([[maybe_unused]] JSHandle receiver, auto kind = ICKindToString(GetICKind()); auto state = ProfileTypeAccessor::ICStateToString(icAccessor_.GetICState()); if (key->IsString()) { - LOG(ERROR, RUNTIME) << kind << " miss key is: " << JSHandle::Cast(key)->GetCString().get() + LOG_ECMA(ERROR) << kind << " miss key is: " << JSHandle::Cast(key)->GetCString().get() << ", receiver is " << receiver->GetTaggedObject()->GetClass()->IsDictionaryMode() << ", state is " << state; } else { - LOG(ERROR, RUNTIME) << kind << " miss " << ", state is " + LOG_ECMA(ERROR) << kind << " miss " << ", state is " << ", receiver is " << receiver->GetTaggedObject()->GetClass()->IsDictionaryMode() << state; } @@ -136,6 +136,7 @@ void ICRuntime::TraceIC([[maybe_unused]] JSHandle receiver, JSTaggedValue LoadICRuntime::LoadMiss(JSHandle receiver, JSHandle key) { if (receiver->IsTypedArray() || !receiver->IsJSObject() || receiver->IsSpecialContainer()) { + icAccessor_.SetAsMega(); return JSTaggedValue::GetProperty(thread_, receiver, key).GetValue().GetTaggedValue(); } @@ -174,7 +175,8 @@ JSTaggedValue LoadICRuntime::LoadMiss(JSHandle receiver, JSHandle JSTaggedValue StoreICRuntime::StoreMiss(JSHandle receiver, JSHandle key, JSHandle value) { - if (receiver->IsTypedArray() || !receiver->IsJSObject()) { + if (receiver->IsTypedArray() || !receiver->IsJSObject() || receiver->IsSpecialContainer()) { + icAccessor_.SetAsMega(); bool success = JSTaggedValue::SetProperty(GetThread(), receiver, key, value, true); return success ? JSTaggedValue::Undefined() : JSTaggedValue::Exception(); } diff --git a/ecmascript/ic/ic_runtime_stub-inl.h b/ecmascript/ic/ic_runtime_stub-inl.h index 72b048628cc822e9c52492323df9153481507fcf..c1f9606bda1da19078ac1bb83e5981879ab1e4f3 100644 --- a/ecmascript/ic/ic_runtime_stub-inl.h +++ b/ecmascript/ic/ic_runtime_stub-inl.h @@ -68,7 +68,7 @@ JSTaggedValue ICRuntimeStub::CheckPolyHClass(JSTaggedValue cachedValue, JSHClass { if (!cachedValue.IsWeak()) { ASSERT(cachedValue.IsTaggedArray()); - TaggedArray *array = TaggedArray::Cast(cachedValue.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(cachedValue.GetTaggedObject()); uint32_t length = array->GetLength(); for (uint32_t i = 0; i < length; i += 2) { // 2 means one ic, two slot auto result = array->Get(i); @@ -112,7 +112,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::TryLoadICByValue(JSThread *thread, JSTag auto hclass = receiver.GetTaggedObject()->GetClass(); if (firstValue.GetWeakReferentUnChecked() == hclass) { ASSERT(HandlerBase::IsElement(secondValue.GetInt())); - return LoadElement(JSObject::Cast(receiver.GetHeapObject()), key); + return LoadElement(JSObject::Cast(receiver.GetTaggedObject()), key); } // Check key if (firstValue == key) { @@ -140,7 +140,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::TryStoreICByValue(JSThread *thread, JSTa if (receiver.IsHeapObject()) { auto hclass = receiver.GetTaggedObject()->GetClass(); if (firstValue.GetWeakReferentUnChecked() == hclass) { - return StoreElement(thread, JSObject::Cast(receiver.GetHeapObject()), key, value, secondValue); + return StoreElement(thread, JSObject::Cast(receiver.GetTaggedObject()), key, value, secondValue); } // Check key if (firstValue == key) { @@ -196,15 +196,15 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::StoreICWithHandler(JSThread *thread, JST if (handler.IsInt()) { auto handlerInfo = static_cast(handler.GetInt()); if (HandlerBase::IsField(handlerInfo)) { - StoreField(thread, JSObject::Cast(receiver.GetHeapObject()), value, handlerInfo); + StoreField(thread, JSObject::Cast(receiver.GetTaggedObject()), value, handlerInfo); return JSTaggedValue::Undefined(); } ASSERT(HandlerBase::IsAccessor(handlerInfo) || HandlerBase::IsInternalAccessor(handlerInfo)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handlerInfo); + auto accessor = LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); return FastRuntimeStub::CallSetter(thread, JSTaggedValue(receiver), value, accessor); } if (handler.IsTransitionHandler()) { - StoreWithTransition(thread, JSObject::Cast(receiver.GetHeapObject()), value, handler); + StoreWithTransition(thread, JSObject::Cast(receiver.GetTaggedObject()), value, handler); return JSTaggedValue::Undefined(); } if (handler.IsPrototypeHandler()) { @@ -224,7 +224,7 @@ JSTaggedValue ICRuntimeStub::StorePrototype(JSThread *thread, JSTaggedValue rece PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); auto cellValue = prototypeHandler->GetProtoCell(); ASSERT(cellValue.IsProtoChangeMarker()); - ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetHeapObject()); + ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetTaggedObject()); if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } @@ -244,7 +244,7 @@ void ICRuntimeStub::StoreWithTransition(JSThread *thread, JSObject *receiver, JS ASSERT(HandlerBase::IsField(handlerInfo)); if (!HandlerBase::IsInlinedProps(handlerInfo)) { - TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetTaggedObject()); int capacity = static_cast(array->GetLength()); int index = HandlerBase::GetOffset(handlerInfo); if (index >= capacity) { @@ -278,7 +278,7 @@ ARK_INLINE void ICRuntimeStub::StoreField(JSThread *thread, JSObject *receiver, SET_VALUE_WITH_BARRIER(thread, receiver, static_cast(index) * JSTaggedValue::TaggedTypeSize(), value); return; } - TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(receiver->GetProperties().GetTaggedObject()); ASSERT(index < static_cast(array->GetLength())); array->Set(thread, index, value); } @@ -289,13 +289,13 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadFromField(JSObject *receiver, uint32 if (HandlerBase::IsInlinedProps(handlerInfo)) { return JSTaggedValue(GET_VALUE(receiver, static_cast(index) * JSTaggedValue::TaggedTypeSize())); } - return TaggedArray::Cast(receiver->GetProperties().GetHeapObject())->Get(index); + return TaggedArray::Cast(receiver->GetProperties().GetTaggedObject())->Get(index); } ARK_INLINE JSTaggedValue ICRuntimeStub::LoadGlobal(JSTaggedValue handler) { ASSERT(handler.IsPropertyBox()); - PropertyBox *cell = PropertyBox::Cast(handler.GetHeapObject()); + PropertyBox *cell = PropertyBox::Cast(handler.GetTaggedObject()); if (cell->IsInvalid()) { return JSTaggedValue::Hole(); } @@ -308,7 +308,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::StoreGlobal(JSThread *thread, JSTaggedVa { INTERPRETER_TRACE(thread, StoreGlobal); ASSERT(handler.IsPropertyBox()); - PropertyBox *cell = PropertyBox::Cast(handler.GetHeapObject()); + PropertyBox *cell = PropertyBox::Cast(handler.GetTaggedObject()); if (cell->IsInvalid()) { return JSTaggedValue::Hole(); } @@ -324,7 +324,7 @@ JSTaggedValue ICRuntimeStub::LoadPrototype(JSThread *thread, JSTaggedValue recei PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); auto cellValue = prototypeHandler->GetProtoCell(); ASSERT(cellValue.IsProtoChangeMarker()); - ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetHeapObject()); + ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetTaggedObject()); if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } @@ -340,13 +340,13 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadICWithHandler(JSThread *thread, JSTa if (LIKELY(handler.IsInt())) { auto handlerInfo = static_cast(handler.GetInt()); if (LIKELY(HandlerBase::IsField(handlerInfo))) { - return LoadFromField(JSObject::Cast(holder.GetHeapObject()), handlerInfo); + return LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); } if (HandlerBase::IsNonExist(handlerInfo)) { return JSTaggedValue::Undefined(); } ASSERT(HandlerBase::IsAccessor(handlerInfo) || HandlerBase::IsInternalAccessor(handlerInfo)); - auto accessor = LoadFromField(JSObject::Cast(holder.GetHeapObject()), handlerInfo); + auto accessor = LoadFromField(JSObject::Cast(holder.GetTaggedObject()), handlerInfo); return FastRuntimeStub::CallGetter(thread, receiver, holder, accessor); } @@ -364,7 +364,7 @@ ARK_INLINE JSTaggedValue ICRuntimeStub::LoadElement(JSObject *receiver, JSTagged return JSTaggedValue::Hole(); } uint32_t elementIndex = static_cast(index); - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetHeapObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); if (elements->GetLength() <= elementIndex) { return JSTaggedValue::Hole(); } @@ -392,7 +392,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, arr->SetArrayLength(thread, elementIndex + 1); } } - TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetHeapObject()); + TaggedArray *elements = TaggedArray::Cast(receiver->GetElements().GetTaggedObject()); uint32_t capacity = elements->GetLength(); if (elementIndex >= capacity) { if (JSObject::ShouldTransToDict(capacity, elementIndex)) { @@ -413,7 +413,7 @@ JSTaggedValue ICRuntimeStub::StoreElement(JSThread *thread, JSObject *receiver, PrototypeHandler *prototypeHandler = PrototypeHandler::Cast(handler.GetTaggedObject()); auto cellValue = prototypeHandler->GetProtoCell(); ASSERT(cellValue.IsProtoChangeMarker()); - ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetHeapObject()); + ProtoChangeMarker *cell = ProtoChangeMarker::Cast(cellValue.GetTaggedObject()); if (cell->GetHasChanged()) { return JSTaggedValue::Hole(); } diff --git a/ecmascript/ic/invoke_cache.cpp b/ecmascript/ic/invoke_cache.cpp index d8ee49029e31dc6ed087b08106a58fa679f9001d..85a6ac982f630fa3ed85d3cec18474dad49d73bd 100644 --- a/ecmascript/ic/invoke_cache.cpp +++ b/ecmascript/ic/invoke_cache.cpp @@ -62,7 +62,7 @@ bool InvokeCache::SetPolyConstuctCacheSlot(JSThread *thread, ProfileTypeInfo *pr JSTaggedValue InvokeCache::CheckPolyInvokeCache(JSTaggedValue cachedArray, JSTaggedValue func) { ASSERT(cachedArray.IsTaggedArray()); - TaggedArray *array = TaggedArray::Cast(cachedArray.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(cachedArray.GetTaggedObject()); uint32_t length = array->GetLength(); for (uint32_t index = 0; index < length; index += 2) { // 2: means one ic, two slot auto result = array->Get(index); @@ -104,14 +104,15 @@ JSTaggedValue InvokeCache::Construct(JSThread *thread, JSTaggedValue firstValue, ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj = factory->NewJSObject(instanceHClass); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(constructor), JSHandle(obj), JSHandle(newTgt), length); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); FrameHandler frameHandler(thread); for (size_t i = 0; i < length; i++) { - info.SetCallArg(i, frameHandler.GetVRegValue(firstArgIdx + i)); + info->SetCallArg(i, frameHandler.GetVRegValue(firstArgIdx + i)); } - EcmaInterpreter::Execute(&info); + EcmaInterpreter::Execute(info); return obj.GetTaggedValue(); } diff --git a/ecmascript/ic/profile_type_info.cpp b/ecmascript/ic/profile_type_info.cpp index cafcd559aa34650c664e5d7065f726c8f96b96b8..c5c3ef1253a5ba64275c380b0e45744310334aa6 100644 --- a/ecmascript/ic/profile_type_info.cpp +++ b/ecmascript/ic/profile_type_info.cpp @@ -259,11 +259,11 @@ ProfileTypeAccessor::ICState ProfileTypeAccessor::GetICState() const return ICState::MONO; } if (profileData.IsTaggedArray()) { - TaggedArray *array = TaggedArray::Cast(profileData.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(profileData.GetTaggedObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } profileData = profileTypeInfo_->Get(slotId_ + 1); - TaggedArray *array = TaggedArray::Cast(profileData.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(profileData.GetTaggedObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } case ICKind::NamedGlobalLoadIC: @@ -273,7 +273,7 @@ ProfileTypeAccessor::ICState ProfileTypeAccessor::GetICState() const case ICKind::GlobalLoadIC: case ICKind::GlobalStoreIC: { ASSERT(profileData.IsTaggedArray()); - TaggedArray *array = TaggedArray::Cast(profileData.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(profileData.GetTaggedObject()); return array->GetLength() == MONO_CASE_NUM ? ICState::MONO : ICState::POLY; // 2 : test case } default: diff --git a/ecmascript/ic/property_box.h b/ecmascript/ic/property_box.h index 9472e285d7fd2a8ac0f87450fbb5e627586bf85f..532e29ca146d41a8762d75da1cfc35c2e10a7c4a 100644 --- a/ecmascript/ic/property_box.h +++ b/ecmascript/ic/property_box.h @@ -27,7 +27,7 @@ namespace panda { namespace ecmascript { class PropertyBox : public TaggedObject { public: - static PropertyBox *Cast(ObjectHeader *object) + static PropertyBox *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsPropertyBox()); return static_cast(object); diff --git a/ecmascript/ic/proto_change_details.h b/ecmascript/ic/proto_change_details.h index 8ce9905be165eeb448a7cd0f50bdeb9fc83bda1d..a75fb39c8f76565da6e2b70f647bf231e7a2d6e7 100644 --- a/ecmascript/ic/proto_change_details.h +++ b/ecmascript/ic/proto_change_details.h @@ -25,7 +25,7 @@ namespace panda { namespace ecmascript { class ProtoChangeMarker : public TaggedObject { public: - static ProtoChangeMarker *Cast(ObjectHeader *object) + static ProtoChangeMarker *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsProtoChangeMarker()); return static_cast(object); @@ -45,7 +45,7 @@ public: class ProtoChangeDetails : public TaggedObject { public: static constexpr int UNREGISTERED = -1; - static ProtoChangeDetails *Cast(ObjectHeader *object) + static ProtoChangeDetails *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsProtoChangeDetails()); return static_cast(object); @@ -62,7 +62,7 @@ public: class ChangeListener : public WeakVector { public: - static ChangeListener *Cast(ObjectHeader *object) + static ChangeListener *Cast(TaggedObject *object) { return static_cast(object); } diff --git a/ecmascript/ic/tests/ic_compareop_test.cpp b/ecmascript/ic/tests/ic_compareop_test.cpp index 04e1646b58aa87e2a36b6a99258d7f566bd702bf..03039b450eec6c060e8fefcbd45ec4628b6c4185 100644 --- a/ecmascript/ic/tests/ic_compareop_test.cpp +++ b/ecmascript/ic/tests/ic_compareop_test.cpp @@ -81,7 +81,7 @@ HWTEST_F_L0(IcCompareOPTest, EqualWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::EqDyn(thread, arg1Handle.GetTaggedValue(), @@ -141,7 +141,7 @@ HWTEST_F_L0(IcCompareOPTest, NotEqualWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::NotEqDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); @@ -208,7 +208,7 @@ HWTEST_F_L0(IcCompareOPTest, LessDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::LessDyn(thread, arg1Handle.GetTaggedValue(), @@ -274,7 +274,7 @@ HWTEST_F_L0(IcCompareOPTest, LessEqDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(123))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::LessEqDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); @@ -343,7 +343,7 @@ HWTEST_F_L0(IcCompareOPTest, GreaterDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(1))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::GreaterDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); @@ -413,7 +413,7 @@ HWTEST_F_L0(IcCompareOPTest, GreaterEqDynWithIC) ecmaRuntimeCallInfo->SetThis(globalObject.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(0))); - JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo.get()); + JSTaggedValue booleanObj = builtins::BuiltinsBoolean::BooleanConstructor(ecmaRuntimeCallInfo); JSHandle booleanObjHandle(thread, booleanObj); JSTaggedValue resInSlowPath1 = SlowRuntimeStub::GreaterEqDyn(thread, arg1Handle.GetTaggedValue(), arg2Handle.GetTaggedValue()); diff --git a/ecmascript/ic/tests/ic_runtime_stub_test.cpp b/ecmascript/ic/tests/ic_runtime_stub_test.cpp index 6de3e636dbc5b4c25219aa121bbb1408efb774cc..b53295b09189c0e640536a5df9b7df590af4c356 100644 --- a/ecmascript/ic/tests/ic_runtime_stub_test.cpp +++ b/ecmascript/ic/tests/ic_runtime_stub_test.cpp @@ -102,7 +102,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreGlobalICByName) JSHandle globalValue(factory->NewJSObjectByConstructor(JSHandle(objFun), objFun)); JSTaggedValue handleValue(2); - uint32_t arrayLength = 2U; + uint32_t arrayLength = 2U; // 2 means ProfileTypeInfo length JSHandle handleTaggedArray = factory->NewTaggedArray(arrayLength); handleTaggedArray->Set(thread, 0, handleBoxValue.GetTaggedValue()); handleTaggedArray->Set(thread, 1, handleValue); @@ -152,7 +152,7 @@ HWTEST_F_L0(ICRuntimeStubTest, CheckPolyHClass) EXPECT_TRUE(resultValue.IsPropertyBox()); } -HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByName) +HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByName) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -176,7 +176,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByName) EXPECT_EQ(resultValue.GetInt(), 2); } -HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByValue) +HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByValue) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -187,7 +187,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreICAndLoadIC_ByValue) JSHandle handleKey(factory->NewFromASCII("key")); JSHandle handleStoreVal(factory->NewFromASCII("1")); - uint32_t arrayLength = 1U; + uint32_t arrayLength = 2U; // 2 means ProfileTypeInfo length JSHandle handleTaggedArray = factory->NewTaggedArray(arrayLength); JSHandle handleProfileTypeInfo = JSHandle::Cast(handleTaggedArray); // test receiver is typedArray @@ -237,7 +237,7 @@ HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByName) EXPECT_TRUE(resultValue2.IsHole()); } -HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByValue1) +HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByValue1) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -267,7 +267,7 @@ HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByValue1) EXPECT_EQ(resultValue.GetInt(), handleStoreVal.GetInt()); } -HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByValue2) +HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByValue2) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -302,7 +302,7 @@ HWTEST_F_L0(ICRuntimeStubTest, TryStoreICAndLoadIC_ByValue2) JSTaggedValue TestSetter(EcmaRuntimeCallInfo *argv) { // 2 : 2 arg value - if (argv->GetArgsNumber() == 1U && argv->GetCallArg(0).GetTaggedValue() == JSTaggedValue(2)) { + if (argv->GetArgsNumber() == 1 && argv->GetCallArg(0).GetTaggedValue() == JSTaggedValue(2)) { JSThread *thread = argv->GetThread(); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle obj(BuiltinsBase::GetThis(argv)); @@ -331,7 +331,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreICWithHandler) OffsetBit::Set(bitOffset, &handler); AccessorBit::Set(true, &handler); - array_size_t arrayLength = bitOffset + 1U; + uint32_t arrayLength = bitOffset + 1U; JSHandle handleHolder = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle handleTaggedArr = factory->NewTaggedArray(arrayLength); handleTaggedArr->Set(thread, bitOffset, handleAccessor.GetTaggedValue()); @@ -389,7 +389,7 @@ HWTEST_F_L0(ICRuntimeStubTest, LoadICWithHandler) OffsetBit::Set(bitOffset, &handler); AccessorBit::Set(true, &handler); - array_size_t arrayLength = bitOffset + 1U; + uint32_t arrayLength = bitOffset + 1U; JSHandle handleHolder = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle handleTaggedArr = factory->NewTaggedArray(arrayLength); handleTaggedArr->Set(thread, bitOffset, handleAccessor.GetTaggedValue()); @@ -428,7 +428,7 @@ HWTEST_F_L0(ICRuntimeStubTest, Prototype_StoreAndLoad) OffsetBit::Set(bitOffset, &handler); KindBit::Set(HandlerKind::FIELD, &handler); // test filed - array_size_t arrayLength = bitOffset + 1U; + uint32_t arrayLength = bitOffset + 1U; JSHandle handleObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle handleTaggedArr = factory->NewTaggedArray(arrayLength); handleObj->SetProperties(thread, handleTaggedArr.GetTaggedValue()); @@ -462,7 +462,7 @@ HWTEST_F_L0(ICRuntimeStubTest, StoreWithTransition_In_Filed) OffsetBit::Set(bitOffset, &handler); KindBit::Set(HandlerKind::FIELD, &handler); - array_size_t arrayLength = bitOffset + 1U; + uint32_t arrayLength = bitOffset + 1U; JSHandle handleTaggedArr = factory->NewTaggedArray(arrayLength); handleObj->SetProperties(thread, handleTaggedArr.GetTaggedValue()); @@ -487,7 +487,7 @@ HWTEST_F_L0(ICRuntimeStubTest, Field_StoreAndLoad) uint32_t bitOffset = 2U; OffsetBit::Set(bitOffset, &handler); - array_size_t arrayLength = bitOffset + 1U; + uint32_t arrayLength = bitOffset + 1U; JSHandle handleTaggedArr = factory->NewTaggedArray(arrayLength); handleTaggedArr->Set(thread, bitOffset, JSTaggedValue::Undefined()); @@ -533,7 +533,7 @@ HWTEST_F_L0(ICRuntimeStubTest, Element_StoreAndLoad) KindBit::Set(HandlerKind::ELEMENT, &handlerInfo); IsJSArrayBit::Set(true, &handlerInfo); - array_size_t arrayLength = 3U; + uint32_t arrayLength = 3U; JSArray *handleArr = JSArray::ArrayCreate(thread, JSTaggedNumber(arrayLength)).GetObject(); JSHandle handleArrObj(thread, handleArr); JSHandle handleTaggedArr = factory->NewTaggedArray(arrayLength); diff --git a/ecmascript/ic/tests/properties_cache_test.cpp b/ecmascript/ic/tests/properties_cache_test.cpp index aeba3058d0af613cc4a92c08e11a66a4ad2e46b2..720f652118a76f99c166e68ef05927a75b78fb4e 100644 --- a/ecmascript/ic/tests/properties_cache_test.cpp +++ b/ecmascript/ic/tests/properties_cache_test.cpp @@ -62,7 +62,7 @@ HWTEST_F_L0(PropertiesCacheTest, SetAndGet) JSHandle handleFunction(factory->NewJSFunction(env)); JSHandle handleSymbol(factory->NewJSSymbol()); JSHandle handleKey10(factory->NewFromASCII("10")); - JSHClass *FuncClass = JSObject::Cast(handleFunction->GetHeapObject())->GetJSHClass(); + JSHClass *FuncClass = JSObject::Cast(handleFunction->GetTaggedObject())->GetJSHClass(); PropertiesCache *handleProCache = thread->GetPropertiesCache(); // key is string @@ -98,7 +98,7 @@ HWTEST_F_L0(PropertiesCacheTest, Clear) JSHandle handleKey(factory->NewFromASCII("10")); JSHandle handleFunction(factory->NewJSFunction(env)); - JSHClass *FuncClass = JSObject::Cast(handleFunction->GetHeapObject())->GetJSHClass(); + JSHClass *FuncClass = JSObject::Cast(handleFunction->GetTaggedObject())->GetJSHClass(); PropertiesCache *handleProCache = thread->GetPropertiesCache(); handleProCache->Set(FuncClass, handleKey.GetTaggedValue(), 10); diff --git a/ecmascript/ic/tests/proto_change_details_test.cpp b/ecmascript/ic/tests/proto_change_details_test.cpp index 06234b933111e70800b91957c930a57e38723183..cec855986c312c716b507f725cd61e96fbb3f805 100644 --- a/ecmascript/ic/tests/proto_change_details_test.cpp +++ b/ecmascript/ic/tests/proto_change_details_test.cpp @@ -96,7 +96,7 @@ HWTEST_F_L0(ProtoChangeDetailsTest, SetChangeListener) ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle handleValue(thread, JSTaggedValue(1)); - array_size_t weakVectorCapacity = 100; + uint32_t weakVectorCapacity = 100; JSHandle weakVector = WeakVector::Create(thread, weakVectorCapacity); JSHandle handleChangeListener = JSHandle::Cast(weakVector); JSHandle handleChangeDetails = factory->NewProtoChangeDetails(); @@ -138,8 +138,8 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_001) JSHandle objFun = env->GetObjectFunction(); JSHandle handleObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle objDynclassVal(thread, handleObj->GetJSHClass()); - array_size_t weakVectorCapacity = 10; - array_size_t index = 2; + uint32_t weakVectorCapacity = 10; + uint32_t index = 2; JSHandle weakVector = WeakVector::Create(thread, weakVectorCapacity); for (int i = 0; i < 9; i++) { weakVector->PushBack(thread, JSTaggedValue(i)); @@ -169,8 +169,8 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_002) JSHandle objFun = env->GetObjectFunction(); JSHandle handleObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle objDynclassVal(thread, handleObj->GetJSHClass()); - array_size_t weakVectorCapacity = 10; - array_size_t index = 2; + uint32_t weakVectorCapacity = 10; + uint32_t index = 2; JSHandle weakVector = WeakVector::Create(thread, weakVectorCapacity); for (int i = 0; i < 10; i++) { weakVector->PushBack(thread, JSTaggedValue(i)); @@ -202,8 +202,8 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_003) JSHandle objFun = env->GetObjectFunction(); JSHandle handleObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle objDynclassVal(thread, handleObj->GetJSHClass()); - array_size_t weakVectorCapacity = 10; - array_size_t index = 2; + uint32_t weakVectorCapacity = 10; + uint32_t index = 2; JSHandle weakVector = WeakVector::Create(thread, weakVectorCapacity); for (int i = 0; i < 10; i++) { weakVector->PushBack(thread, JSTaggedValue(i)); @@ -229,7 +229,7 @@ HWTEST_F_L0(ProtoChangeDetailsTest, Add_003) */ HWTEST_F_L0(ProtoChangeDetailsTest, CheckHole) { - array_size_t weakVectorCapacity = 10; + uint32_t weakVectorCapacity = 10; JSHandle weakVector = WeakVector::Create(thread, weakVectorCapacity); for (int i = 0; i < 10; i++) { weakVector->PushBack(thread, JSTaggedValue(i)); // Set Value and End @@ -250,7 +250,7 @@ HWTEST_F_L0(ProtoChangeDetailsTest, CheckHole) */ HWTEST_F_L0(ProtoChangeDetailsTest, Get) { - array_size_t weakVectorCapacity = 3; + uint32_t weakVectorCapacity = 3; ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle objFun = env->GetObjectFunction(); diff --git a/ecmascript/interpreter/fast_runtime_stub-inl.h b/ecmascript/interpreter/fast_runtime_stub-inl.h index ccf68f35d0dabb9c43f8f4e913e180b88b4e972b..f6bcbe688fa4960f40eeb3f9df3189986c8242e4 100644 --- a/ecmascript/interpreter/fast_runtime_stub-inl.h +++ b/ecmascript/interpreter/fast_runtime_stub-inl.h @@ -45,24 +45,6 @@ namespace panda::ecmascript { return JSTaggedValue::Hole(); \ } -JSTaggedValue FastRuntimeStub::FastAdd(JSTaggedValue left, JSTaggedValue right) -{ - if (left.IsNumber() && right.IsNumber()) { - return JSTaggedValue(left.GetNumber() + right.GetNumber()); - } - - return JSTaggedValue::Hole(); -} - -JSTaggedValue FastRuntimeStub::FastSub(JSTaggedValue left, JSTaggedValue right) -{ - if (left.IsNumber() && right.IsNumber()) { - return JSTaggedValue(left.GetNumber() - right.GetNumber()); - } - - return JSTaggedValue::Hole(); -} - JSTaggedValue FastRuntimeStub::FastMul(JSTaggedValue left, JSTaggedValue right) { if (left.IsNumber() && right.IsNumber()) { @@ -801,593 +783,6 @@ JSTaggedValue FastRuntimeStub::NewLexicalEnvDyn(JSThread *thread, ObjectFactory return JSTaggedValue(newEnv); } -// Those interface below is discarded -bool FastRuntimeStub::IsSpecialIndexedObjForGet(JSTaggedValue obj) -{ - JSType jsType = obj.GetTaggedObject()->GetClass()->GetObjectType(); - return jsType > JSType::JS_ARRAY && jsType <= JSType::JS_PRIMITIVE_REF; -} - -bool FastRuntimeStub::IsSpecialIndexedObjForSet(JSTaggedValue obj) -{ - JSType jsType = obj.GetTaggedObject()->GetClass()->GetObjectType(); - return jsType >= JSType::JS_ARRAY && jsType <= JSType::JS_PRIMITIVE_REF; -} - -JSTaggedValue FastRuntimeStub::GetElement(JSTaggedValue receiver, uint32_t index) -{ - JSTaggedValue holder = receiver; - while (true) { - JSTaggedValue val = FindOwnElement(JSObject::Cast(holder), index); - if (!val.IsHole()) { - return val; - } - - holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); - if (!holder.IsHeapObject()) { - return JSTaggedValue::Undefined(); - } - } -} - -JSTaggedValue FastRuntimeStub::GetElementWithArray(JSTaggedValue receiver, uint32_t index) -{ - DISALLOW_GARBAGE_COLLECTION; - JSTaggedValue holder = receiver; - while (true) { - JSTaggedValue val = FindOwnElement(JSObject::Cast(holder), index); - if (!val.IsHole()) { - return val; - } - - holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); - if (!holder.IsHeapObject()) { - return val; - } - } -} - -bool FastRuntimeStub::SetElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value, - bool mayThrow) -{ - INTERPRETER_TRACE(thread, SetElement); - JSTaggedValue holder = receiver; - bool onPrototype = false; - - while (true) { - PropertyAttributes attr; - uint32_t indexOrEntry = 0; - TaggedArray *elements = TaggedArray::Cast(JSObject::Cast(holder)->GetElements().GetHeapObject()); - bool isDict = elements->IsDictionaryMode(); - JSTaggedValue val = FindOwnElement(elements, index, isDict, &attr, &indexOrEntry); - if (!val.IsHole()) { - if (UNLIKELY(onPrototype)) { - if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); - } - return false; - } - - return JSObject::AddElementInternal(thread, JSHandle(thread, receiver), index, - JSHandle(thread, value), - PropertyAttributes::Default()); - } - if (!attr.IsAccessor()) { - if (attr.IsWritable()) { - elements = TaggedArray::Cast(JSObject::Cast(receiver)->GetElements().GetHeapObject()); - if (!isDict) { - elements->Set(thread, indexOrEntry, value); - JSObject::Cast(receiver)->GetJSHClass()->UpdateRepresentation(value); - return true; - } - NumberDictionary::Cast(elements)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); - return true; - } - - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", false); - } - return false; - } - - // Accessor - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle objHandle(thread, receiver); - JSHandle valueHandle(thread, value); - AccessorData *access = AccessorData::Cast(val.GetHeapObject()); - return JSObject::CallSetter(thread, *access, objHandle, valueHandle, mayThrow); - } - - holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); - if (!holder.IsHeapObject()) { - if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); - } - return false; - } - - return JSObject::AddElementInternal(thread, JSHandle(thread, receiver), index, - JSHandle(thread, value), PropertyAttributes::Default()); - } - if (holder.IsJSProxy()) { - return JSProxy::SetProperty( - thread, JSHandle(thread, holder), JSHandle(thread, JSTaggedValue(index)), - JSHandle(thread, value), JSHandle(thread, receiver), mayThrow); - } - onPrototype = true; - } -} - -bool FastRuntimeStub::SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool mayThrow) -{ - INTERPRETER_TRACE(thread, SetPropertyByName); - // property - JSTaggedValue holder = receiver; - bool onPrototype = false; - - while (true) { - TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(holder)->GetProperties().GetHeapObject()); - PropertyAttributes attr; - uint32_t indexOrEntry = 0; - JSTaggedValue val = FindOwnProperty(thread, JSObject::Cast(holder), properties, key, &attr, &indexOrEntry); - if (!val.IsHole()) { - if (!attr.IsAccessor()) { - if (UNLIKELY(onPrototype)) { - if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible() || !attr.IsWritable())) { - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); - } - return false; - } - [[maybe_unused]] EcmaHandleScope handleScope(thread); - ObjectOperator::FastAdd(thread, receiver, key, JSHandle(thread, value), - PropertyAttributes::Default()); - - return true; - } - - if (attr.IsWritable()) { - properties = TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetHeapObject()); - if (!properties->IsDictionaryMode()) { - Representation representation = - PropertyAttributes::UpdateRepresentation(attr.GetRepresentation(), value); - if (attr.GetRepresentation() != representation) { - attr.SetRepresentation(representation); - } - - JSObject::Cast(receiver)->GetJSHClass()->UpdatePropertyMetaData(thread, key, attr); - if (UNLIKELY(val.IsInternalAccessor())) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); - AccessorData::Cast(val.GetHeapObject()) - ->CallInternalSet(thread, JSHandle(thread, receiver), - JSHandle(thread, value), mayThrow); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return true; - } - - if (attr.IsInlinedProps()) { - JSObject::Cast(receiver)->SetPropertyInlinedProps(thread, indexOrEntry, value); - } else { - properties->Set(thread, indexOrEntry, value); - } - return true; - } - - if (receiver.IsJSGlobalObject()) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle dictHandle(thread, properties); - // globalobj have no internal accessor - GlobalDictionary::InvalidatePropertyBox(thread, dictHandle, indexOrEntry, attr); - return true; - } - - if (UNLIKELY(val.IsInternalAccessor())) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); - AccessorData::Cast(val.GetHeapObject()) - ->CallInternalSet(thread, JSHandle(thread, receiver), - JSHandle(thread, value), mayThrow); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return true; - } - - NameDictionary::Cast(properties)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); - return true; - } - - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set readonly property", false); - } - return false; - } - - // Accessor - [[maybe_unused]] EcmaHandleScope handleScope(thread); - JSHandle objHandle(thread, receiver); - JSHandle valueHandle(thread, value); - AccessorData *access = AccessorData::Cast(val.GetHeapObject()); - return JSObject::CallSetter(thread, *access, objHandle, valueHandle, mayThrow); - } - - if (holder.IsTypedArray()) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); - return JSTypedArray::SetProperty(thread, JSHandle(thread, holder), - JSTypedArray::ToPropKey(thread, JSHandle(thread, key)), - JSHandle(thread, value), - JSHandle(thread, receiver), mayThrow); - } - - holder = JSObject::Cast(holder)->GetJSHClass()->GetPrototype(); - if (!holder.IsHeapObject()) { - if (UNLIKELY(!JSObject::Cast(receiver)->IsExtensible())) { - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot add property in prevent extensions ", false); - } - return false; - } - [[maybe_unused]] EcmaHandleScope handleScope(thread); - ObjectOperator::FastAdd(thread, receiver, key, JSHandle(thread, value), - PropertyAttributes::Default()); - - return true; - } - if (holder.IsJSProxy()) { - [[maybe_unused]] EcmaHandleScope handleScope(thread); - return JSProxy::SetProperty(thread, JSHandle(thread, holder), JSHandle(thread, key), - JSHandle(thread, value), - JSHandle(thread, receiver), mayThrow); - } - onPrototype = true; - } -} - -bool FastRuntimeStub::SetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool mayThrow) -{ - INTERPRETER_TRACE(thread, SetGlobalOwnProperty); - uint32_t index = 0; - if (JSTaggedValue::ToElementIndex(key, &index)) { - return SetElement(thread, receiver, index, value, mayThrow); - } - - JSObject *obj = JSObject::Cast(receiver); - GlobalDictionary *dict = GlobalDictionary::Cast(obj->GetProperties().GetTaggedObject()); - PropertyAttributes attr = PropertyAttributes::Default(); - if (UNLIKELY(dict->GetLength() == 0)) { - JSHandle keyHandle(thread, key); - JSHandle valHandle(thread, value); - JSHandle objHandle(thread, obj); - JSHandle dictHandle(GlobalDictionary::Create(thread)); - - // Add PropertyBox to global dictionary - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle boxHandle = factory->NewPropertyBox(valHandle); - boxHandle->SetValue(thread, valHandle.GetTaggedValue()); - PropertyBoxType boxType = valHandle->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; - attr.SetBoxType(boxType); - - JSHandle properties = - GlobalDictionary::PutIfAbsent(thread, dictHandle, keyHandle, JSHandle(boxHandle), attr); - objHandle->SetProperties(thread, properties); - return true; - } - - int entry = dict->FindEntry(key); - if (entry != -1) { - attr = dict->GetAttributes(entry); - JSTaggedValue val = dict->GetValue(entry); - if (!attr.IsAccessor()) { - if (attr.IsWritable()) { - // globalobj have no internal accessor - JSHandle dictHandle(thread, dict); - GlobalDictionary::InvalidatePropertyBox(thread, dictHandle, entry, attr); - return true; - } - } - - // Accessor - JSTaggedValue setter = AccessorData::Cast(val.GetHeapObject())->GetSetter(); - if (setter.IsUndefined()) { - if (mayThrow) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property when setter is undefined", false); - } - return false; - } - - JSHandle objHandle(thread, receiver); - JSHandle setFunc(thread, setter); - JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, setFunc, objHandle, undefined, 1); - info.SetCallArg(value); - JSFunction::Call(&info); - // 10. ReturnIfAbrupt(setterResult). - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); - return true; - } - - JSHandle keyHandle(thread, key); - JSHandle valHandle(thread, value); - JSHandle objHandle(thread, obj); - JSHandle dictHandle(thread, dict); - - // Add PropertyBox to global dictionary - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle boxHandle = factory->NewPropertyBox(keyHandle); - boxHandle->SetValue(thread, valHandle.GetTaggedValue()); - PropertyBoxType boxType = valHandle->IsUndefined() ? PropertyBoxType::UNDEFINED : PropertyBoxType::CONSTANT; - attr.SetBoxType(boxType); - - JSHandle properties = - GlobalDictionary::PutIfAbsent(thread, dictHandle, keyHandle, JSHandle(boxHandle), attr); - objHandle->SetProperties(thread, properties); - return true; -} - -// set property that is not accessor and is writable -void FastRuntimeStub::SetOwnPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value) -{ - INTERPRETER_TRACE(thread, SetOwnPropertyByName); - TaggedArray *properties = TaggedArray::Cast(JSObject::Cast(receiver)->GetProperties().GetHeapObject()); - PropertyAttributes attr; - uint32_t indexOrEntry; - JSTaggedValue val = FindOwnProperty(thread, JSObject::Cast(receiver), properties, key, &attr, &indexOrEntry); - if (!val.IsHole()) { - ASSERT(!attr.IsAccessor() && attr.IsWritable()); - if (!properties->IsDictionaryMode()) { - Representation representation = PropertyAttributes::UpdateRepresentation(attr.GetRepresentation(), value); - if (attr.GetRepresentation() != representation) { - attr.SetRepresentation(representation); - } - - JSObject::Cast(receiver)->GetJSHClass()->UpdatePropertyMetaData(thread, key, attr); - - if (attr.IsInlinedProps()) { - JSObject::Cast(receiver)->SetPropertyInlinedProps(thread, indexOrEntry, value); - } else { - properties->Set(thread, indexOrEntry, value); - } - return; - } - - NameDictionary::Cast(properties)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); - return; - } - [[maybe_unused]] EcmaHandleScope handleScope(thread); - - ObjectOperator::FastAdd(thread, receiver, key, JSHandle(thread, value), - PropertyAttributes::Default()); -} - -// set element that is not accessor and is writable -bool FastRuntimeStub::SetOwnElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value) -{ - INTERPRETER_TRACE(thread, SetOwnElement); - PropertyAttributes attr; - uint32_t indexOrEntry; - TaggedArray *elements = TaggedArray::Cast(JSObject::Cast(receiver)->GetElements().GetHeapObject()); - bool isDict = elements->IsDictionaryMode(); - [[maybe_unused]] JSTaggedValue val = FindOwnElement(elements, index, isDict, &attr, &indexOrEntry); - if (!val.IsHole()) { - ASSERT(!attr.IsAccessor() && attr.IsWritable()); - if (!isDict) { - elements->Set(thread, indexOrEntry, value); - JSObject::Cast(receiver)->GetJSHClass()->UpdateRepresentation(value); - return true; - } - NumberDictionary::Cast(elements)->UpdateValueAndAttributes(thread, indexOrEntry, value, attr); - return true; - } - - return JSObject::AddElementInternal(thread, JSHandle(thread, receiver), index, - JSHandle(thread, value), PropertyAttributes::Default()); -} - -bool FastRuntimeStub::FastSetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value, - bool mayThrow) -{ - INTERPRETER_TRACE(thread, FastSetProperty); - if (receiver.IsJSObject() && !receiver.IsTypedArray() && (key.IsStringOrSymbol())) { - uint32_t index = 0; - if (UNLIKELY(JSTaggedValue::ToElementIndex(key, &index))) { - if (!FastRuntimeStub::IsSpecialIndexedObjForSet(receiver)) { - return FastRuntimeStub::SetElement(thread, receiver, index, value, true); - } - return JSTaggedValue::SetProperty(thread, JSHandle(thread, receiver), - JSHandle(thread, key), - JSHandle(thread, value), mayThrow); - } - if (key.IsString()) { - key = JSTaggedValue(thread->GetEcmaVM()->GetFactory()->InternString(JSHandle(thread, key))); - } - return FastRuntimeStub::SetPropertyByName(thread, receiver, key, value, mayThrow); - } - return JSTaggedValue::SetProperty(thread, JSHandle(thread, receiver), - JSHandle(thread, key), JSHandle(thread, value), - mayThrow); -} - -JSTaggedValue FastRuntimeStub::FastGetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key) -{ - INTERPRETER_TRACE(thread, FastGetProperty); - JSTaggedValue result = JSTaggedValue::Hole(); - if (receiver.IsJSObject() && !receiver.IsTypedArray() && (key.IsStringOrSymbol())) { - uint32_t index = 0; - if (UNLIKELY(JSTaggedValue::ToElementIndex(key, &index))) { - if (FastRuntimeStub::IsSpecialIndexedObjForSet(receiver)) { - result = JSTaggedValue::Hole(); - } else { - result = FastRuntimeStub::GetElement(receiver, index); - } - } else { - if (key.IsString()) { - key = JSTaggedValue( - thread->GetEcmaVM()->GetFactory()->InternString(JSHandle(thread, key))); - } - result = FastRuntimeStub::GetPropertyByName(thread, receiver, key); - } - } - if (!result.IsHole()) { - if (UNLIKELY(result.IsAccessor())) { - return JSObject::CallGetter(thread, AccessorData::Cast(result.GetHeapObject()), - JSHandle(thread, receiver)); - } - return result; - } - return JSTaggedValue::GetProperty(thread, JSHandle(thread, receiver), - JSHandle(thread, key)) - .GetValue() - .GetTaggedValue(); -} - -JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, TaggedArray *properties, - JSTaggedValue key, PropertyAttributes *attr, uint32_t *indexOrEntry) -{ - INTERPRETER_TRACE(thread, FindOwnProperty); - if (!properties->IsDictionaryMode()) { - JSHClass *cls = obj->GetJSHClass(); - JSTaggedValue attrs = cls->GetLayout(); - if (!attrs.IsNull()) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetHeapObject()); - uint32_t propNumber = cls->NumberOfProps(); - int entry = layoutInfo->FindElementWithCache(thread, cls, key, propNumber); - if (entry != -1) { - *attr = layoutInfo->GetAttr(entry); - ASSERT(entry == static_cast(attr->GetOffset())); - *indexOrEntry = entry; - if (attr->IsInlinedProps()) { - return obj->GetPropertyInlinedProps(entry); - } - *indexOrEntry -= cls->GetInlinedProperties(); - return properties->Get(*indexOrEntry); - } - } - return JSTaggedValue::Hole(); // properties == empty properties will return here. - } - - if (obj->IsJSGlobalObject()) { - GlobalDictionary *dict = GlobalDictionary::Cast(properties); - int entry = dict->FindEntry(key); - if (entry != -1) { - *indexOrEntry = entry; - *attr = dict->GetAttributes(entry); - return dict->GetValue(entry); - } - return JSTaggedValue::Hole(); - } - - NameDictionary *dict = NameDictionary::Cast(properties); - int entry = dict->FindEntry(key); - if (entry != -1) { - *indexOrEntry = entry; - *attr = dict->GetAttributes(entry); - return dict->GetValue(entry); - } - - return JSTaggedValue::Hole(); -} - -JSTaggedValue FastRuntimeStub::FindOwnElement(TaggedArray *elements, uint32_t index, bool isDict, - PropertyAttributes *attr, uint32_t *indexOrEntry) -{ - if (!isDict) { - if (elements->GetLength() <= index) { - return JSTaggedValue::Hole(); - } - - JSTaggedValue value = elements->Get(index); - if (!value.IsHole()) { - *attr = PropertyAttributes::Default(); - *indexOrEntry = index; - return value; - } - } else { - NumberDictionary *dict = NumberDictionary::Cast(elements); - int entry = dict->FindEntry(JSTaggedValue(static_cast(index))); - if (entry != -1) { - *indexOrEntry = entry; - *attr = dict->GetAttributes(entry); - return dict->GetValue(entry); - } - } - return JSTaggedValue::Hole(); -} - -JSTaggedValue FastRuntimeStub::FindOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key) -{ - INTERPRETER_TRACE(thread, FindOwnProperty); - TaggedArray *array = TaggedArray::Cast(obj->GetProperties().GetHeapObject()); - if (!array->IsDictionaryMode()) { - JSHClass *cls = obj->GetJSHClass(); - JSTaggedValue attrs = cls->GetLayout(); - if (!attrs.IsNull()) { - LayoutInfo *layoutInfo = LayoutInfo::Cast(attrs.GetHeapObject()); - uint32_t propsNumber = cls->NumberOfProps(); - int entry = layoutInfo->FindElementWithCache(thread, cls, key, propsNumber); - if (entry != -1) { - PropertyAttributes attr(layoutInfo->GetAttr(entry)); - ASSERT(static_cast(attr.GetOffset()) == entry); - return attr.IsInlinedProps() ? obj->GetPropertyInlinedProps(entry) - : array->Get(static_cast(entry) - cls->GetInlinedProperties()); - } - } - return JSTaggedValue::Hole(); // array == empty array will return here. - } - - if (obj->IsJSGlobalObject()) { - GlobalDictionary *dict = GlobalDictionary::Cast(array); - int entry = dict->FindEntry(key); - if (entry != -1) { - return dict->GetValue(entry); - } - return JSTaggedValue::Hole(); - } - - NameDictionary *dict = NameDictionary::Cast(array); - int entry = dict->FindEntry(key); - if (entry != -1) { - return dict->GetValue(entry); - } - - return JSTaggedValue::Hole(); -} - -JSTaggedValue FastRuntimeStub::FindOwnElement(JSObject *obj, uint32_t index) -{ - TaggedArray *elements = TaggedArray::Cast(JSObject::Cast(obj)->GetElements().GetHeapObject()); - - if (!elements->IsDictionaryMode()) { - if (elements->GetLength() <= index) { - return JSTaggedValue::Hole(); - } - - JSTaggedValue value = elements->Get(index); - if (!value.IsHole()) { - return value; - } - } else { - NumberDictionary *dict = NumberDictionary::Cast(elements); - int entry = dict->FindEntry(JSTaggedValue(static_cast(index))); - if (entry != -1) { - return dict->GetValue(entry); - } - } - return JSTaggedValue::Hole(); -} - -JSTaggedValue FastRuntimeStub::HasOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key) -{ - INTERPRETER_TRACE(thread, HasOwnProperty); - uint32_t index = 0; - if (UNLIKELY(JSTaggedValue::ToElementIndex(key, &index))) { - return FastRuntimeStub::FindOwnElement(obj, index); - } - - return FastRuntimeStub::FindOwnProperty(thread, obj, key); -} - JSTaggedValue FastRuntimeStub::GetContainerProperty(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSType jsType) { @@ -1487,23 +882,6 @@ JSTaggedValue FastRuntimeStub::NewThisObject(JSThread *thread, JSTaggedValue cto return obj.GetTaggedValue(); } -JSTaggedValue FastRuntimeStub::NewThisObject(JSThread *thread, JSTaggedValue ctor, JSTaggedValue newTarget, - AsmInterpretedFrame *state) -{ - [[maybe_unused]] EcmaHandleScope handleScope(thread); - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - - JSHandle ctorHandle(thread, ctor); - JSHandle newTargetHandle(thread, newTarget); - JSHandle obj = factory->NewJSObjectByConstructor(ctorHandle, newTargetHandle); - RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); - - state->function = ctorHandle.GetTaggedValue(); - state->env = ctorHandle->GetLexicalEnv(); - - return obj.GetTaggedValue(); -} - bool FastRuntimeStub::TryStringOrSymbolToIndex(JSTaggedValue key, uint32_t *output) { if (key.IsSymbol()) { diff --git a/ecmascript/interpreter/fast_runtime_stub.h b/ecmascript/interpreter/fast_runtime_stub.h index 1d8a4b3dd0de60bae407d8de7e5e01fc11a99dc6..879a0d235a997ab6145bb13dee014ca449221ead 100644 --- a/ecmascript/interpreter/fast_runtime_stub.h +++ b/ecmascript/interpreter/fast_runtime_stub.h @@ -26,9 +26,6 @@ class PropertyAttributes; class FastRuntimeStub { public: - /* -------------- Common API Begin, Don't change those interface!!! ----------------- */ - static inline JSTaggedValue FastAdd(JSTaggedValue left, JSTaggedValue right); - static inline JSTaggedValue FastSub(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue FastMul(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue FastDiv(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue FastMod(JSTaggedValue left, JSTaggedValue right); @@ -37,38 +34,6 @@ public: static inline bool FastStrictEqual(JSTaggedValue left, JSTaggedValue right); static inline JSTaggedValue NewLexicalEnvDyn(JSThread *thread, ObjectFactory *factory, uint16_t numVars); static inline JSTaggedValue GetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); - /* -------------- Special API For Multi-Language VM Begin ----------------- */ - static inline bool IsSpecialIndexedObjForGet(JSTaggedValue obj); - static inline bool IsSpecialIndexedObjForSet(JSTaggedValue obj); - static inline JSTaggedValue GetElement(JSTaggedValue receiver, uint32_t index); - static inline JSTaggedValue GetElementWithArray(JSTaggedValue receiver, uint32_t index); - static inline bool SetElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value, - bool mayThrow); - static inline bool SetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool mayThrow); - static inline bool SetGlobalOwnProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value, bool mayThrow); - - // set property that is not accessor and is writable - static inline void SetOwnPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, - JSTaggedValue value); - // set element that is not accessor and is writable - static inline bool SetOwnElement(JSThread *thread, JSTaggedValue receiver, uint32_t index, JSTaggedValue value); - static inline bool FastSetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key, JSTaggedValue value, - bool mayThrow); - static inline JSTaggedValue FastGetProperty(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); - static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, TaggedArray *properties, - JSTaggedValue key, PropertyAttributes *attr, uint32_t *indexOrEntry); - static inline JSTaggedValue FindOwnElement(TaggedArray *elements, uint32_t index, bool isDict, - PropertyAttributes *attr, uint32_t *indexOrEntry); - static inline JSTaggedValue FindOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key); - - static inline JSTaggedValue FindOwnElement(JSObject *obj, uint32_t index); - - static inline JSTaggedValue HasOwnProperty(JSThread *thread, JSObject *obj, JSTaggedValue key); - /* -------------- Special API For Multi-Language VM End ----------------- */ - /* -------------- Common API End, Don't change those interface!!! ----------------- */ - template static inline JSTaggedValue GetPropertyByName(JSThread *thread, JSTaggedValue receiver, JSTaggedValue key); template @@ -100,8 +65,6 @@ public: static inline JSTaggedValue NewThisObject(JSThread *thread, JSTaggedValue ctor, JSTaggedValue newTarget, InterpretedFrame* state); - static inline JSTaggedValue NewThisObject(JSThread *thread, JSTaggedValue ctor, JSTaggedValue newTarget, - AsmInterpretedFrame* state); private: friend class ICRuntimeStub; diff --git a/ecmascript/interpreter/frame_handler.cpp b/ecmascript/interpreter/frame_handler.cpp index 41724f385d2f517b83ca69bde18ff7449d0029ae..51b845ff81688cbae7283587496cd9d5270091e5 100644 --- a/ecmascript/interpreter/frame_handler.cpp +++ b/ecmascript/interpreter/frame_handler.cpp @@ -16,7 +16,8 @@ #include "ecmascript/interpreter/frame_handler.h" -#include "ecmascript/compiler/llvm/llvm_stackmap_parser.h" +#include "ecmascript/file_loader.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "ecmascript/js_function.h" #include "ecmascript/js_thread.h" #include "ecmascript/mem/heap.h" @@ -24,158 +25,46 @@ #include "libpandafile/bytecode_instruction-inl.h" namespace panda::ecmascript { -void FrameHandler::PrevFrame() +FrameHandler::FrameHandler(const JSThread *thread) + : sp_(const_cast(thread->GetCurrentFrame())), thread_(thread) { - auto type = GetFrameType(); - switch (type) { - case FrameType::OPTIMIZED_FRAME: { - auto frame = OptimizedFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME: { - auto frame = OptimizedJSFunctionArgConfigFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::OPTIMIZED_JS_FUNCTION_FRAME: { - auto frame = OptimizedJSFunctionFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::OPTIMIZED_ENTRY_FRAME: { - auto frame = OptimizedEntryFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::ASM_INTERPRETER_FRAME: { - auto frame = AsmInterpretedFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - if (thread_->IsAsmInterpreter()) { - fp_ = frame->GetCurrentFramePointer(); - } - break; - } - case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: { - auto frame = AsmInterpretedFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::INTERPRETER_FRAME: - case FrameType::INTERPRETER_FAST_NEW_FRAME: { - auto frame = InterpretedFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::LEAVE_FRAME: { - auto frame = OptimizedWithArgvLeaveFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::LEAVE_FRAME_WITH_ARGV: { - auto frame = OptimizedLeaveFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::BUILTIN_FRAME_WITH_ARGV: { - auto frame = BuiltinWithArgvFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::BUILTIN_ENTRY_FRAME: - case FrameType::BUILTIN_FRAME: { - auto frame = BuiltinFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::INTERPRETER_ENTRY_FRAME: { - auto frame = InterpretedEntryFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::ASM_INTERPRETER_ENTRY_FRAME: { - auto frame = AsmInterpretedEntryFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: { - auto frame = AsmInterpretedBridgeFrame::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); - break; - } - default: { - LOG_ECMA(FATAL) << "frame type error!"; - UNREACHABLE(); - } - } -} - -uintptr_t FrameHandler::GetPrevFrameCallSiteSp(const JSTaggedType *sp, uintptr_t curPc) -{ - if (sp == nullptr) { - return 0U; - } - - auto type = GetFrameType(sp); - switch (type) { - case FrameType::LEAVE_FRAME: { - auto frame = OptimizedLeaveFrame::GetFrameFromSp(sp); - return frame->GetCallSiteSp(); - } - case FrameType::LEAVE_FRAME_WITH_ARGV: { - auto frame = OptimizedWithArgvLeaveFrame::GetFrameFromSp(sp); - return frame->GetCallSiteSp(); - } - case FrameType::BUILTIN_FRAME_WITH_ARGV: { - auto frame = BuiltinWithArgvFrame::GetFrameFromSp(sp); - return frame->GetCallSiteSp(); - } - case FrameType::BUILTIN_FRAME: { - auto frame = BuiltinFrame::GetFrameFromSp(sp); - return frame->GetCallSiteSp(); - } - case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: { - auto frame = AsmInterpretedBridgeFrame::GetFrameFromSp(sp); - return frame->GetCallSiteSp(); - } - case FrameType::OPTIMIZED_FRAME: - case FrameType::OPTIMIZED_JS_FUNCTION_FRAME: { - auto callSiteSp = reinterpret_cast(sp) + - kungfu::LLVMStackMapParser::GetInstance().GetFuncFpDelta(curPc); - return callSiteSp; - } - case FrameType::BUILTIN_ENTRY_FRAME: - case FrameType::ASM_INTERPRETER_FRAME: - case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: - case FrameType::INTERPRETER_FRAME: - case FrameType::INTERPRETER_FAST_NEW_FRAME: - case FrameType::OPTIMIZED_ENTRY_FRAME: - case FrameType::INTERPRETER_ENTRY_FRAME: - case FrameType::ASM_INTERPRETER_ENTRY_FRAME: - default: { - LOG_ECMA(FATAL) << "frame type error!"; - UNREACHABLE(); - } - } + stackmapParser_ = thread->GetEcmaVM()->GetFileLoader()->GetStackMapParser(); + AdvanceToInterpretedFrame(); } - ARK_INLINE void FrameHandler::AdvanceToInterpretedFrame() { if (!thread_->IsAsmInterpreter()) { return; } - for (; HasFrame() && !(IsInterpretedFrame() || IsInterpretedEntryFrame()); PrevFrame()); + FrameIterator it(sp_, thread_); + for (; !it.Done(); it.Advance()) { + FrameType t = it.GetFrameType(); + if (IsInterpretedFrame(t) || IsInterpretedEntryFrame(t)) { + break; + } + } + sp_ = it.GetSp(); } ARK_INLINE void FrameHandler::PrevInterpretedFrame() { if (!thread_->IsAsmInterpreter()) { - auto frame = InterpretedFrameBase::GetFrameFromSp(sp_); - sp_ = frame->GetPrevFrameFp(); + FrameIterator it(sp_, thread_); + it.Advance(); + sp_ = it.GetSp(); return; } AdvanceToInterpretedFrame(); - PrevFrame(); + FrameIterator it(sp_, thread_); + FrameType t = it.GetFrameType(); + if (t == FrameType::ASM_INTERPRETER_FRAME) { + auto frame = it.GetFrame(); + if (thread_->IsAsmInterpreter()) { + fp_ = frame->GetCurrentFramePointer(); + } + } + it.Advance(); + sp_ = it.GetSp(); AdvanceToInterpretedFrame(); } @@ -193,11 +82,12 @@ uint32_t FrameHandler::GetNumberArgs() } ASSERT(IsInterpretedFrame()); JSTaggedType *prevSp = nullptr; + FrameIterator it(sp_, thread_); if (IsAsmInterpretedFrame()) { - auto *frame = AsmInterpretedFrame::GetFrameFromSp(sp_); + auto *frame = it.GetFrame(); prevSp = frame->GetPrevFrameFp(); } else { - auto *frame = InterpretedFrame::GetFrameFromSp(sp_); + auto *frame = it.GetFrame(); prevSp = frame->GetPrevFrameFp(); } auto prevSpEnd = reinterpret_cast(GetInterpretedFrameEnd(prevSp)); @@ -221,11 +111,12 @@ void FrameHandler::SetVRegValue(size_t index, JSTaggedValue value) JSTaggedValue FrameHandler::GetAcc() const { ASSERT(IsInterpretedFrame()); + FrameIterator it(sp_, thread_); if (IsAsmInterpretedFrame()) { - auto *frame = AsmInterpretedFrame::GetFrameFromSp(sp_); + auto *frame = it.GetFrame(); return frame->acc; } else { - auto *frame = InterpretedFrame::GetFrameFromSp(sp_); + auto *frame = it.GetFrame(); return frame->acc; } } @@ -280,30 +171,39 @@ JSTaggedValue FrameHandler::GetFunction() const case FrameType::INTERPRETER_ENTRY_FRAME: case FrameType::ASM_INTERPRETER_ENTRY_FRAME: case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: + case FrameType::INTERPRETER_BUILTIN_FRAME: case FrameType::OPTIMIZED_FRAME: case FrameType::LEAVE_FRAME: case FrameType::LEAVE_FRAME_WITH_ARGV: + case FrameType::BUILTIN_CALL_LEAVE_FRAME: case FrameType::OPTIMIZED_ENTRY_FRAME: default: { - LOG_ECMA(FATAL) << "frame type error!"; + LOG_FULL(FATAL) << "frame type error!"; UNREACHABLE(); } } } else { - auto *frame = InterpretedFrame::GetFrameFromSp(sp_); - return frame->function; + FrameType type = GetFrameType(); + if (type == FrameType::INTERPRETER_FRAME || type == FrameType::INTERPRETER_FAST_NEW_FRAME) { + auto *frame = InterpretedFrame::GetFrameFromSp(sp_); + return frame->function; + } else { + auto *frame = InterpretedBuiltinFrame::GetFrameFromSp(sp_); + return frame->function; + } } } const uint8_t *FrameHandler::GetPc() const { ASSERT(IsInterpretedFrame()); + FrameIterator it(sp_, thread_); if (IsAsmInterpretedFrame()) { - auto *frame = AsmInterpretedFrame::GetFrameFromSp(sp_); - return frame->pc; + auto *frame = it.GetFrame(); + return frame->GetPc(); } else { - auto *frame = InterpretedFrame::GetFrameFromSp(sp_); - return frame->pc; + auto *frame = it.GetFrame(); + return frame->GetPc(); } } @@ -318,11 +218,12 @@ ConstantPool *FrameHandler::GetConstpool() const JSTaggedValue FrameHandler::GetEnv() const { ASSERT(IsInterpretedFrame()); + FrameIterator it(sp_, thread_); if (IsAsmInterpretedFrame()) { - auto *frame = AsmInterpretedFrame::GetFrameFromSp(sp_); - return frame->env; + auto *frame = it.GetFrame(); + return frame->GetEnv(); } else { - auto *frame = InterpretedFrame::GetFrameFromSp(sp_); + auto *frame = it.GetFrame(); return frame->env; } } @@ -350,333 +251,49 @@ void FrameHandler::DumpPC(std::ostream &os, const uint8_t *pc) const ARK_INLINE uintptr_t FrameHandler::GetInterpretedFrameEnd(JSTaggedType *prevSp) const { uintptr_t end = 0U; - FrameType type = FrameHandler::GetFrameType(prevSp); + FrameIterator it(prevSp, thread_); + FrameType type = it.GetFrameType(); switch (type) { case FrameType::ASM_INTERPRETER_FRAME: case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: { - auto frame = AsmInterpretedFrame::GetFrameFromSp(prevSp); + auto frame = it.GetFrame(); end = ToUintPtr(frame); break; } case FrameType::INTERPRETER_FRAME: case FrameType::INTERPRETER_FAST_NEW_FRAME: { - auto frame = InterpretedFrame::GetFrameFromSp(prevSp); + auto frame = it.GetFrame(); + end = ToUintPtr(frame); + break; + } + case FrameType::INTERPRETER_ENTRY_FRAME: { + auto frame = it.GetFrame(); end = ToUintPtr(frame); break; } - case FrameType::INTERPRETER_ENTRY_FRAME: - end = ToUintPtr(GetInterpretedEntryFrameStart(prevSp)); + case FrameType::INTERPRETER_BUILTIN_FRAME: { + auto frame = it.GetFrame(); + end = ToUintPtr(frame); break; + } case FrameType::BUILTIN_FRAME_WITH_ARGV: case FrameType::BUILTIN_ENTRY_FRAME: case FrameType::BUILTIN_FRAME: case FrameType::OPTIMIZED_FRAME: case FrameType::LEAVE_FRAME: case FrameType::LEAVE_FRAME_WITH_ARGV: + case FrameType::BUILTIN_CALL_LEAVE_FRAME: case FrameType::OPTIMIZED_ENTRY_FRAME: case FrameType::ASM_INTERPRETER_ENTRY_FRAME: case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: default: { - LOG_ECMA(FATAL) << "frame type error!"; + LOG_FULL(FATAL) << "frame type error!"; UNREACHABLE(); } } return end; } -ARK_INLINE void FrameHandler::InterpretedFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - const RootRangeVisitor &v1) const -{ - InterpretedFrame *frame = InterpretedFrame::GetFrameFromSp(sp); - if (frame->function == JSTaggedValue::Hole()) { - return; - } - JSTaggedType *prevSp = frame->GetPrevFrameFp(); - uintptr_t start = ToUintPtr(sp); - uintptr_t end = 0U; - FrameType type = FrameHandler::GetFrameType(prevSp); - if (type == FrameType::INTERPRETER_FRAME || type == FrameType::INTERPRETER_FAST_NEW_FRAME) { - auto prevFrame = InterpretedFrame::GetFrameFromSp(prevSp); - end = ToUintPtr(prevFrame); - } else if (type == FrameType::INTERPRETER_ENTRY_FRAME) { - end = ToUintPtr(GetInterpretedEntryFrameStart(prevSp)); - } else { - LOG_ECMA(FATAL) << "frame type error!"; - } - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->function))); - - // pc == nullptr, init InterpretedFrame & native InterpretedFrame. - if (frame->pc != nullptr) { - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->acc))); - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->constpool))); - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->env))); - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->profileTypeInfo))); - } -} - -ARK_INLINE void FrameHandler::AsmInterpretedFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - const RootRangeVisitor &v1) const -{ - AsmInterpretedFrame *frame = AsmInterpretedFrame::GetFrameFromSp(sp); - uintptr_t start = ToUintPtr(sp); - uintptr_t end = ToUintPtr(frame->GetCurrentFramePointer()); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->function))); - if (frame->pc != nullptr) { - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->acc))); - v0(Root::ROOT_FRAME, ObjectSlot(ToUintPtr(&frame->env))); - } -} - -ARK_INLINE void FrameHandler::AsmInterpretedBridgeFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - [[maybe_unused]] const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) const -{ - auto frame = AsmInterpretedBridgeFrame::GetFrameFromSp(sp); - std::set slotAddrs; - bool ret = kungfu::LLVMStackMapParser::GetInstance().CollectStackMapSlots( - frame->returnAddr, reinterpret_cast(sp), slotAddrs, - derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { -#ifndef NDEBUG - LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << frame->returnAddr; -#endif - return; - } - - for (auto slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE void FrameHandler::BuiltinFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) const -{ - auto frame = BuiltinFrame::GetFrameFromSp(sp); - // no need to visit stack map for entry frame - if (frame->type == FrameType::BUILTIN_ENTRY_FRAME) { - // only visit function - v0(Root::ROOT_FRAME, ObjectSlot(frame->GetStackArgsAddress())); - return; - } - JSTaggedType *argv = reinterpret_cast(frame->GetStackArgsAddress()); - auto argc = frame->GetNumArgs() + BuiltinFrame::RESERVED_CALL_ARGCOUNT; - uintptr_t start = ToUintPtr(argv); - uintptr_t end = ToUintPtr(argv + argc); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - - std::set slotAddrs; - bool ret = kungfu::LLVMStackMapParser::GetInstance().CollectStackMapSlots( - frame->returnAddr, reinterpret_cast(sp), slotAddrs, derivedPointers, isVerifying, - optimizedReturnAddr_); - if (!ret) { -#ifndef NDEBUG - LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << frame->returnAddr; -#endif - return; - } - - for (auto slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE void FrameHandler::BuiltinWithArgvFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) const -{ - auto frame = BuiltinWithArgvFrame::GetFrameFromSp(sp); - auto argc = frame->GetNumArgs() + BuiltinFrame::RESERVED_CALL_ARGCOUNT; - JSTaggedType *argv = reinterpret_cast(frame->GetStackArgsAddress()); - uintptr_t start = ToUintPtr(argv); - uintptr_t end = ToUintPtr(argv + argc); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - - std::set slotAddrs; - bool ret = kungfu::LLVMStackMapParser::GetInstance().CollectStackMapSlots( - frame->returnAddr, reinterpret_cast(sp), slotAddrs, - derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { -#ifndef NDEBUG - LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << frame->returnAddr; -#endif - return; - } - - for (auto slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE JSTaggedType *FrameHandler::GetInterpretedEntryFrameStart(const JSTaggedType *sp) -{ - ASSERT(FrameHandler::GetFrameType(sp) == FrameType::INTERPRETER_ENTRY_FRAME); - JSTaggedType *argcSp = const_cast(sp) - INTERPRETER_ENTRY_FRAME_STATE_SIZE - 1; - uint32_t argc = argcSp[0]; - return argcSp - argc - RESERVED_CALL_ARGCOUNT; -} - -ARK_INLINE void FrameHandler::InterpretedEntryFrameIterate(const JSTaggedType *sp, - [[maybe_unused]] const RootVisitor &v0, - const RootRangeVisitor &v1) const -{ - uintptr_t start = ToUintPtr(GetInterpretedEntryFrameStart(sp)); - uintptr_t end = ToUintPtr(sp - INTERPRETER_ENTRY_FRAME_STATE_SIZE); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); -} - -ARK_INLINE void FrameHandler::OptimizedFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - [[maybe_unused]] const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) const -{ - std::set slotAddrs; - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto returnAddr = - reinterpret_cast(*(reinterpret_cast(const_cast(sp)) + 1)); - bool enableCompilerLog = thread_->GetEcmaVM()->GetJSOptions().WasSetlogCompiledMethods(); - bool ret = kungfu::LLVMStackMapParser::GetInstance(enableCompilerLog).CollectStackMapSlots( - returnAddr, reinterpret_cast(sp), slotAddrs, derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { -#ifndef NDEBUG - LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << returnAddr; -#endif - return; - } - - for (const auto &slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE void FrameHandler::OptimizedJSFunctionFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - [[maybe_unused]] const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) -{ - OptimizedJSFunctionFrame *frame = OptimizedJSFunctionFrame::GetFrameFromSp(sp); - auto currentPc = optimizedReturnAddr_; - optimizedReturnAddr_ = frame->returnAddr; - int delta = kungfu::LLVMStackMapParser::GetInstance().GetFuncFpDelta(currentPc); - uintptr_t *preFrameSp = frame->ComputePrevFrameSp(sp, delta); - - auto argc = *(reinterpret_cast(preFrameSp)); - JSTaggedType *argv = frame->GetArgv(preFrameSp); - if (argc > 0) { - uintptr_t start = ToUintPtr(argv); // argv - uintptr_t end = ToUintPtr(argv + argc); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - } - std::set slotAddrs; - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto returnAddr = - reinterpret_cast(*(reinterpret_cast(const_cast(sp)) + 1)); - bool enableCompilerLog = thread_->GetEcmaVM()->GetJSOptions().WasSetlogCompiledMethods(); - bool ret = kungfu::LLVMStackMapParser::GetInstance(enableCompilerLog).CollectStackMapSlots( - returnAddr, reinterpret_cast(sp), slotAddrs, derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { -#ifndef NDEBUG - LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << returnAddr; -#endif - return; - } - - for (const auto &slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE void FrameHandler::OptimizedEntryFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - [[maybe_unused]] const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) -{ - std::set slotAddrs; - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - auto returnAddr = reinterpret_cast(*(reinterpret_cast(const_cast(sp)) + 1)); - bool enableCompilerLog = thread_->GetEcmaVM()->GetJSOptions().WasSetlogCompiledMethods(); - bool ret = kungfu::LLVMStackMapParser::GetInstance(enableCompilerLog).CollectStackMapSlots( - returnAddr, reinterpret_cast(sp), slotAddrs, derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { -#ifndef NDEBUG - LOG_ECMA(DEBUG) << " stackmap don't found returnAddr " << returnAddr; -#endif - return; - } - - for (const auto &slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE void FrameHandler::OptimizedLeaveFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - [[maybe_unused]] const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) -{ - OptimizedLeaveFrame *frame = OptimizedLeaveFrame::GetFrameFromSp(sp); - if (frame->argc > 0) { - JSTaggedType *argv = reinterpret_cast(&frame->argc + 1); - uintptr_t start = ToUintPtr(argv); // argv - uintptr_t end = ToUintPtr(argv + frame->argc); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - } - - std::set slotAddrs; - bool ret = kungfu::LLVMStackMapParser::GetInstance().CollectStackMapSlots( - frame->returnAddr, reinterpret_cast(sp), slotAddrs, - derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { - return; - } - - for (auto slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - -ARK_INLINE void FrameHandler::OptimizedWithArgvLeaveFrameIterate(const JSTaggedType *sp, - const RootVisitor &v0, - [[maybe_unused]] const RootRangeVisitor &v1, - ChunkMap *derivedPointers, - bool isVerifying) -{ - OptimizedLeaveFrame *frame = OptimizedLeaveFrame::GetFrameFromSp(sp); - if (frame->argc > 0) { - uintptr_t* argvPtr = reinterpret_cast(&frame->argc + 1); - JSTaggedType *argv = reinterpret_cast(*argvPtr); - uintptr_t start = ToUintPtr(argv); // argv - uintptr_t end = ToUintPtr(argv + frame->argc); - v1(Root::ROOT_FRAME, ObjectSlot(start), ObjectSlot(end)); - } - - std::set slotAddrs; - bool ret = kungfu::LLVMStackMapParser::GetInstance().CollectStackMapSlots( - frame->returnAddr, reinterpret_cast(sp), slotAddrs, - derivedPointers, isVerifying, optimizedReturnAddr_); - if (!ret) { - return; - } - - for (auto slot : slotAddrs) { - v0(Root::ROOT_FRAME, ObjectSlot(slot)); - } -} - void FrameHandler::IterateRsp(const RootVisitor &v0, const RootRangeVisitor &v1) { JSTaggedType *current = const_cast(thread_->GetLastLeaveFrame()); @@ -686,12 +303,11 @@ void FrameHandler::IterateRsp(const RootVisitor &v0, const RootRangeVisitor &v1) void FrameHandler::IterateSp(const RootVisitor &v0, const RootRangeVisitor &v1) { JSTaggedType *current = const_cast(thread_->GetCurrentSPFrame()); - while (current) { + for (FrameIterator it(current, thread_); !it.Done(); it.Advance()) { // only interpreter entry frame is on thread sp when rsp is enable - ASSERT(FrameHandler::GetFrameType(current) == FrameType::INTERPRETER_ENTRY_FRAME); - InterpretedEntryFrame *frame = InterpretedEntryFrame::GetFrameFromSp(current); - InterpretedEntryFrameIterate(current, v0, v1); - current = frame->GetPrevFrameFp(); + ASSERT(it.GetFrameType() == FrameType::INTERPRETER_ENTRY_FRAME); + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1); } } @@ -713,7 +329,7 @@ void FrameHandler::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) IterateFrameChain(current, v0, v1); } -void FrameHandler::IterateFrameChain(JSTaggedType *start, const RootVisitor &v0, const RootRangeVisitor &v1) +void FrameHandler::IterateFrameChain(JSTaggedType *start, const RootVisitor &v0, const RootRangeVisitor &v1) const { ChunkMap *derivedPointers = thread_->GetEcmaVM()->GetHeap()->GetDerivedPointers(); bool isVerifying = false; @@ -722,114 +338,84 @@ void FrameHandler::IterateFrameChain(JSTaggedType *start, const RootVisitor &v0, isVerifying = thread_->GetEcmaVM()->GetHeap()->IsVerifying(); #endif JSTaggedType *current = start; - while (current) { - FrameType type = FrameHandler::GetFrameType(current); + for (FrameIterator it(current, thread_); !it.Done(); it.Advance()) { + FrameType type = it.GetFrameType(); switch (type) { case FrameType::OPTIMIZED_FRAME: { - auto frame = OptimizedFrame::GetFrameFromSp(current); - auto prevFrame = frame->GetPrevFrameFp(); - OptimizedFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = prevFrame; - optimizedReturnAddr_ = frame->returnAddr; - break; - } - case FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME: { - OptimizedJSFunctionFrame *frame = OptimizedJSFunctionFrame::GetFrameFromSp(current); - optimizedReturnAddr_ = frame->returnAddr; - current = frame->GetPrevFrameFp(); + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::OPTIMIZED_JS_FUNCTION_FRAME: { - auto frame = OptimizedJSFunctionFrame::GetFrameFromSp(current); - auto prevFrame = frame->GetPrevFrameFp(); - OptimizedJSFunctionFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = prevFrame; - optimizedReturnAddr_ = frame->returnAddr; - break; - } - case FrameType::OPTIMIZED_ENTRY_FRAME: { - auto frame = OptimizedEntryFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = 0; - break; - } - case FrameType::ASM_INTERPRETER_ENTRY_FRAME: { - auto frame = AsmInterpretedEntryFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = 0; - break; - } - case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: { - auto frame = AsmInterpretedBridgeFrame::GetFrameFromSp(current); - AsmInterpretedBridgeFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = frame->returnAddr; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::ASM_INTERPRETER_FRAME: case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: { - auto frame = AsmInterpretedFrame::GetFrameFromSp(current); - AsmInterpretedFrameIterate(current, v0, v1); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = 0; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::INTERPRETER_FRAME: case FrameType::INTERPRETER_FAST_NEW_FRAME: { - auto frame = InterpretedFrame::GetFrameFromSp(current); - InterpretedFrameIterate(current, v0, v1); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = 0; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1); + break; + } + case FrameType::INTERPRETER_BUILTIN_FRAME: { + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1); break; } case FrameType::LEAVE_FRAME: { - auto frame = OptimizedLeaveFrame::GetFrameFromSp(current); - OptimizedLeaveFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = frame->returnAddr; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::LEAVE_FRAME_WITH_ARGV: { - auto frame = OptimizedLeaveFrame::GetFrameFromSp(current); - OptimizedWithArgvLeaveFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = frame->returnAddr; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); + break; + } + case FrameType::BUILTIN_CALL_LEAVE_FRAME: { + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::BUILTIN_FRAME_WITH_ARGV: { - auto frame = BuiltinWithArgvFrame::GetFrameFromSp(current); - BuiltinWithArgvFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = frame->returnAddr; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::BUILTIN_ENTRY_FRAME: case FrameType::BUILTIN_FRAME: { - auto frame = BuiltinFrame::GetFrameFromSp(current); - BuiltinFrameIterate(current, v0, v1, derivedPointers, isVerifying); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = frame->returnAddr; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1, derivedPointers, isVerifying); break; } case FrameType::INTERPRETER_ENTRY_FRAME: { - auto frame = InterpretedEntryFrame::GetFrameFromSp(current); - InterpretedEntryFrameIterate(current, v0, v1); - current = frame->GetPrevFrameFp(); - optimizedReturnAddr_ = 0; + auto frame = it.GetFrame(); + frame->GCIterate(it, v0, v1); + break; + } + case FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME: + case FrameType::OPTIMIZED_ENTRY_FRAME: + case FrameType::ASM_INTERPRETER_ENTRY_FRAME: + case FrameType::ASM_INTERPRETER_BRIDGE_FRAME: { break; } default: { - LOG_ECMA(FATAL) << "frame type error!"; + LOG_FULL(FATAL) << "frame type error!"; UNREACHABLE(); } } } } -std::string FrameHandler::GetAotExceptionFuncName(JSTaggedType* fp) const +std::string FrameHandler::GetAotExceptionFuncName(JSTaggedType* argv) const { - ASSERT(FrameHandler::GetFrameType(fp) == FrameType::OPTIMIZED_JS_FUNCTION_FRAME); - JSTaggedValue func = JSTaggedValue(*(fp + 3)); // 3: skip returnaddr and argc + JSTaggedValue func = JSTaggedValue(*(argv)); // 3: skip returnaddr and argc JSMethod *method = JSFunction::Cast(func.GetTaggedObject())->GetMethod(); return method->GetMethodName(); } @@ -838,90 +424,52 @@ void FrameHandler::CollectBCOffsetInfo() { thread_->GetEcmaVM()->ClearExceptionBCList(); JSTaggedType *current = const_cast(thread_->GetLastLeaveFrame()); - while (current) { - FrameType type = FrameHandler::GetFrameType(current); + FrameIterator it(current, thread_); + ASSERT(it.GetFrameType() == FrameType::BUILTIN_CALL_LEAVE_FRAME); + auto leaveFrame = it.GetFrame(); + auto returnAddr = leaveFrame->GetReturnAddr(); + // skip native function, need to fixit later. + it.Advance(); + + for (; !it.Done(); it.Advance()) { + FrameType type = it.GetFrameType(); switch (type) { - case FrameType::OPTIMIZED_FRAME: { - auto frame = OptimizedFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - break; - } case FrameType::OPTIMIZED_JS_FUNCTION_ARGS_CONFIG_FRAME: case FrameType::OPTIMIZED_JS_FUNCTION_FRAME: { - auto frame = OptimizedJSFunctionFrame::GetFrameFromSp(current); - auto returnAddr = reinterpret_cast( - *(reinterpret_cast(const_cast(current)) + 1)); - bool enableCompilerLog = thread_->GetEcmaVM()->GetJSOptions().WasSetlogCompiledMethods(); - auto constInfo = kungfu::LLVMStackMapParser::GetInstance(enableCompilerLog).GetConstInfo(returnAddr); + auto frame = it.GetFrame(); + auto constInfo = stackmapParser_->GetConstInfo(returnAddr); if (!constInfo.empty()) { - auto prevFp = frame->GetPrevFrameFp(); - auto name = GetAotExceptionFuncName(prevFp); + auto name = GetAotExceptionFuncName(frame->GetArgv(it)); thread_->GetEcmaVM()->StoreBCOffsetInfo(name, constInfo[0]); } - current = frame->GetPrevFrameFp(); - break; - } - case FrameType::OPTIMIZED_ENTRY_FRAME: { - auto frame = OptimizedEntryFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); + returnAddr = frame->GetReturnAddr(); break; } - case FrameType::ASM_INTERPRETER_ENTRY_FRAME: { - auto frame = AsmInterpretedEntryFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); + case FrameType::BUILTIN_CALL_LEAVE_FRAME: { + auto frame = it.GetFrame(); + returnAddr = frame->GetReturnAddr(); break; } + case FrameType::LEAVE_FRAME: + case FrameType::OPTIMIZED_ENTRY_FRAME: + case FrameType::ASM_INTERPRETER_ENTRY_FRAME: case FrameType::ASM_INTERPRETER_FRAME: - case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: { - auto frame = AsmInterpretedFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - break; - } + case FrameType::INTERPRETER_CONSTRUCTOR_FRAME: case FrameType::INTERPRETER_FRAME: - case FrameType::INTERPRETER_FAST_NEW_FRAME: { - auto frame = InterpretedFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - break; - } - case FrameType::LEAVE_FRAME: { - auto frame = OptimizedLeaveFrame::GetFrameFromSp(current); - auto returnAddr = frame->returnAddr; - bool enableCompilerLog = thread_->GetEcmaVM()->GetJSOptions().WasSetlogCompiledMethods(); - auto constInfo = kungfu::LLVMStackMapParser::GetInstance(enableCompilerLog).GetConstInfo(returnAddr); - if (!constInfo.empty()) { - auto prevFp = frame->GetPrevFrameFp(); - auto name = GetAotExceptionFuncName(prevFp); - thread_->GetEcmaVM()->StoreBCOffsetInfo(name, constInfo[0]); - } - current = frame->GetPrevFrameFp(); - break; - } - case FrameType::LEAVE_FRAME_WITH_ARGV: { - auto frame = OptimizedLeaveFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - break; - } - case FrameType::BUILTIN_FRAME_WITH_ARGV: { - auto frame = BuiltinWithArgvFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - break; - } + case FrameType::INTERPRETER_FAST_NEW_FRAME: + case FrameType::OPTIMIZED_FRAME: + case FrameType::LEAVE_FRAME_WITH_ARGV: + case FrameType::BUILTIN_FRAME_WITH_ARGV: case FrameType::BUILTIN_ENTRY_FRAME: - case FrameType::BUILTIN_FRAME: { - auto frame = BuiltinFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); - break; - } + case FrameType::BUILTIN_FRAME: case FrameType::INTERPRETER_ENTRY_FRAME: { - auto frame = InterpretedEntryFrame::GetFrameFromSp(current); - current = frame->GetPrevFrameFp(); break; } default: { - LOG_ECMA(FATAL) << "frame type error!"; + LOG_FULL(FATAL) << "frame type error!"; UNREACHABLE(); } } } } -} // namespace panda::ecmascript +} // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/interpreter/frame_handler.h b/ecmascript/interpreter/frame_handler.h index eaff88fb5644ccebe38422b850636dcd949b1db6..c1ca7ff820d287d4927b94a3b7597287201d738b 100644 --- a/ecmascript/interpreter/frame_handler.h +++ b/ecmascript/interpreter/frame_handler.h @@ -27,14 +27,13 @@ namespace panda { namespace ecmascript { class JSThread; class ConstantPool; +namespace kungfu { + class LLVMStackMapParser; +}; class FrameHandler { public: - explicit FrameHandler(const JSThread *thread) - : sp_(const_cast(thread->GetCurrentFrame())), thread_(thread) - { - AdvanceToInterpretedFrame(); - } + explicit FrameHandler(const JSThread *thread); ~FrameHandler() = default; DEFAULT_COPY_SEMANTIC(FrameHandler); @@ -61,8 +60,9 @@ public: { ASSERT(HasFrame()); // The structure of InterpretedFrame, AsmInterpretedFrame, InterpretedEntryFrame is the same, order is pc, base. - InterpretedFrame *state = InterpretedFrame::GetFrameFromSp(sp_); - return state->pc == nullptr; + FrameIterator it(sp_); + InterpretedFrame *state = it.GetFrame(); + return state->GetPc() == nullptr; } bool IsInterpretedFrame() const @@ -71,9 +71,21 @@ public: return (type >= FrameType::INTERPRETER_BEGIN) && (type <= FrameType::INTERPRETER_END); } + bool IsInterpretedFrame(FrameType type) const + { + return (type >= FrameType::INTERPRETER_BEGIN) && (type <= FrameType::INTERPRETER_END); + } + bool IsAsmInterpretedFrame() const { - FrameType type = GetFrameType(); + FrameIterator it(sp_, thread_); + FrameType type = it.GetFrameType(); + return (type == FrameType::ASM_INTERPRETER_FRAME) || + (type == FrameType::INTERPRETER_CONSTRUCTOR_FRAME); + } + + bool IsAsmInterpretedFrame(FrameType type) const + { return (type == FrameType::ASM_INTERPRETER_FRAME) || (type == FrameType::INTERPRETER_CONSTRUCTOR_FRAME); } @@ -96,6 +108,14 @@ public: return (GetFrameType() == FrameType::INTERPRETER_ENTRY_FRAME); } + bool IsInterpretedEntryFrame(FrameType type) const + { + if (thread_->IsAsmInterpreter()) { + return (type == FrameType::ASM_INTERPRETER_ENTRY_FRAME || type == FrameType::ASM_INTERPRETER_BRIDGE_FRAME); + } + return (type == FrameType::INTERPRETER_ENTRY_FRAME); + } + bool IsLeaveFrame() const { FrameType type = GetFrameType(); @@ -115,9 +135,6 @@ public: void PrevInterpretedFrame(); JSTaggedType *GetPrevInterpretedFrame(); - // for llvm. - static uintptr_t GetPrevFrameCallSiteSp(const JSTaggedType *sp, uintptr_t curPc); - // for InterpretedFrame. JSTaggedValue GetVRegValue(size_t index) const; void SetVRegValue(size_t index, JSTaggedValue value); @@ -144,12 +161,9 @@ public: DumpPC(std::cout, pc); } - // for InterpretedEntryFrame. - static JSTaggedType* GetInterpretedEntryFrameStart(const JSTaggedType *sp); - // for Frame GC. void Iterate(const RootVisitor &v0, const RootRangeVisitor &v1); - void IterateFrameChain(JSTaggedType *start, const RootVisitor &v0, const RootRangeVisitor &v1); + void IterateFrameChain(JSTaggedType *start, const RootVisitor &v0, const RootRangeVisitor &v1) const; void IterateRsp(const RootVisitor &v0, const RootRangeVisitor &v1); void IterateSp(const RootVisitor &v0, const RootRangeVisitor &v1); @@ -165,44 +179,13 @@ private: return *typeAddr; } - void PrevFrame(); void AdvanceToInterpretedFrame(); uintptr_t GetInterpretedFrameEnd(JSTaggedType *prevSp) const; - - // for Frame GC. - void InterpretedFrameIterate(const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1) const; - void AsmInterpretedFrameIterate(const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1) const; - void InterpretedEntryFrameIterate(const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1) const; - void AsmInterpretedBridgeFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying) const; - void BuiltinFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying) const; - void BuiltinWithArgvFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying) const; - void OptimizedFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying) const; - void OptimizedJSFunctionFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying); - void OptimizedEntryFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying); - void OptimizedLeaveFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying); - void OptimizedWithArgvLeaveFrameIterate( - const JSTaggedType *sp, const RootVisitor &v0, const RootRangeVisitor &v1, - ChunkMap *derivedPointers, bool isVerifying); - private: JSTaggedType *sp_ {nullptr}; JSTaggedType *fp_ {nullptr}; const JSThread *thread_ {nullptr}; - uintptr_t optimizedReturnAddr_ {0}; + const kungfu::LLVMStackMapParser *stackmapParser_ {nullptr}; }; class StackAssertScope { diff --git a/ecmascript/interpreter/interpreter-inl.h b/ecmascript/interpreter/interpreter-inl.h index ab8b13dc529e23aa34393be670448c1cec33ac8c..d15e004c489ccfa077d266fe0a6f5e265b2e359f 100644 --- a/ecmascript/interpreter/interpreter-inl.h +++ b/ecmascript/interpreter/interpreter-inl.h @@ -52,8 +52,11 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; #pragma GCC diagnostic ignored "-Wpedantic" #endif -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define LOG_INST() LOG(DEBUG, INTERPRETER) << ": " +#if ECMASCRIPT_ENABLE_INTERPRETER_LOG +#define LOG_INST() LOG_INTERPRETER(DEBUG) +#else +#define LOG_INST() false && LOG_INTERPRETER(DEBUG) +#endif // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define HANDLE_OPCODE(handle_opcode) \ @@ -85,9 +88,8 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define GET_ENTRY_FRAME(sp) \ (reinterpret_cast(sp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define GET_ENTRY_FRAME_WITH_ARGS_SIZE(actualNumArgs) \ - (static_cast(INTERPRETER_ENTRY_FRAME_STATE_SIZE + 1U + (actualNumArgs) + RESERVED_CALL_ARGCOUNT)) +#define GET_BUILTIN_FRAME(sp) \ + (reinterpret_cast(sp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SAVE_PC() (GET_FRAME(sp)->pc = pc) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -184,7 +186,7 @@ using CommonStubCSigns = kungfu::CommonStubCSigns; } \ funcObject = ECMAObject::Cast(funcValue.GetTaggedObject()); \ method = funcObject->GetCallTarget(); \ - newSp = sp - INTERPRETER_FRAME_STATE_SIZE; \ + newSp = sp - InterpretedFrame::NumOfMembers(); \ } while (false) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -406,9 +408,8 @@ JSTaggedValue EcmaInterpreter::ExecuteNative(EcmaRuntimeCallInfo *info) // current is entry frame. JSTaggedType *sp = const_cast(thread->GetCurrentSPFrame()); - int32_t actualNumArgs = static_cast(info->GetArgsNumber()); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - JSTaggedType *newSp = sp - GET_ENTRY_FRAME_WITH_ARGS_SIZE(static_cast(actualNumArgs)); + JSTaggedType *newSp = sp - InterpretedEntryFrame::NumOfMembers(); InterpretedFrame *state = GET_FRAME(newSp); state->base.prev = sp; @@ -416,17 +417,17 @@ JSTaggedValue EcmaInterpreter::ExecuteNative(EcmaRuntimeCallInfo *info) state->pc = nullptr; state->function = info->GetFunctionValue(); thread->SetCurrentSPFrame(newSp); - #if ECMASCRIPT_ENABLE_ACTIVE_CPUPROFILER CpuProfiler::IsNeedAndGetStack(thread); #endif + thread->CheckSafepoint(); ECMAObject *callTarget = reinterpret_cast(info->GetFunctionValue().GetTaggedObject()); JSMethod *method = callTarget->GetCallTarget(); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime Call."; + LOG_INST() << "Entry: Runtime Call."; JSTaggedValue tagged = reinterpret_cast(const_cast(method->GetNativePointer()))(info); - LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call."; + LOG_INST() << "Exit: Runtime Call."; InterpretedEntryFrame *entryState = GET_ENTRY_FRAME(sp); JSTaggedType *prevSp = entryState->base.prev; @@ -439,7 +440,7 @@ JSTaggedValue EcmaInterpreter::ExecuteNative(EcmaRuntimeCallInfo *info) JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) { - if (info == nullptr || (info->GetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -458,10 +459,10 @@ JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) // current is entry frame. JSTaggedType *sp = const_cast(thread->GetCurrentSPFrame()); - int32_t actualNumArgs = static_cast(info->GetArgsNumber()); + int32_t actualNumArgs = info->GetArgsNumber(); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - JSTaggedType *newSp = sp - GET_ENTRY_FRAME_WITH_ARGS_SIZE(static_cast(actualNumArgs)); - if (UNLIKELY(thread->DoStackOverflowCheck(newSp - actualNumArgs - RESERVED_CALL_ARGCOUNT))) { + JSTaggedType *newSp = sp - InterpretedEntryFrame::NumOfMembers(); + if (UNLIKELY(thread->DoStackOverflowCheck(newSp - actualNumArgs - NUM_MANDATORY_JSFUNC_ARGS))) { return JSTaggedValue::Undefined(); } @@ -533,11 +534,12 @@ JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) state->base.type = FrameType::INTERPRETER_FRAME; state->env = thisFunc->GetLexicalEnv(); thread->SetCurrentSPFrame(newSp); + #if ECMASCRIPT_ENABLE_ACTIVE_CPUPROFILER CpuProfiler::IsNeedAndGetStack(thread); #endif thread->CheckSafepoint(); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime Call " << std::hex << reinterpret_cast(newSp) << " " + LOG_INST() << "Entry: Runtime Call " << std::hex << reinterpret_cast(newSp) << " " << std::hex << reinterpret_cast(pc); EcmaInterpreter::RunInternal(thread, ConstantPool::Cast(constpool.GetTaggedObject()), pc, newSp); @@ -557,17 +559,21 @@ JSTaggedValue EcmaInterpreter::Execute(EcmaRuntimeCallInfo *info) JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSHandle context) { [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle func = JSHandle::Cast(JSHandle(thread, context->GetMethod())); + JSMethod *method = func->GetCallTarget(); + if (method->IsAotWithCallField()) { + return GeneratorReEnterAot(thread, context); + } + if (thread->IsAsmInterpreter()) { return InterpreterAssembly::GeneratorReEnterInterpreter(thread, context); } - JSHandle func = JSHandle::Cast(JSHandle(thread, context->GetMethod())); - JSMethod *method = func->GetCallTarget(); JSTaggedType *currentSp = const_cast(thread->GetCurrentSPFrame()); // push break frame // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - JSTaggedType *breakSp = currentSp - INTERPRETER_FRAME_STATE_SIZE; + JSTaggedType *breakSp = currentSp - InterpretedFrame::NumOfMembers(); if (UNLIKELY(thread->DoStackOverflowCheck(breakSp))) { return JSTaggedValue::Exception(); } @@ -580,7 +586,7 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH // create new frame and resume sp and pc uint32_t nregs = context->GetNRegs(); - size_t newFrameSize = INTERPRETER_FRAME_STATE_SIZE + nregs; + size_t newFrameSize = InterpretedFrame::NumOfMembers() + nregs; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic JSTaggedType *newSp = breakSp - newFrameSize; if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) { @@ -602,7 +608,6 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH state->constpool = constpool; state->profileTypeInfo = func->GetProfileTypeInfo(); state->acc = context->GetAcc(); - // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) state->base.prev = breakSp; state->base.type = FrameType::INTERPRETER_FRAME; JSTaggedValue env = context->GetLexicalEnv(); @@ -618,6 +623,27 @@ JSTaggedValue EcmaInterpreter::GeneratorReEnterInterpreter(JSThread *thread, JSH return res; } +JSTaggedValue EcmaInterpreter::GeneratorReEnterAot(JSThread *thread, JSHandle context) +{ + JSHandle func = JSHandle::Cast(JSHandle(thread, context->GetMethod())); + JSMethod *method = func->GetCallTarget(); + JSTaggedValue genObject = context->GetGeneratorObject(); + std::vector args(method->GetNumArgs() + NUM_MANDATORY_JSFUNC_ARGS + 1, + JSTaggedValue::Undefined().GetRawData()); + args[0] = func.GetTaggedValue().GetRawData(); + args[1] = genObject.GetRawData(); + JSTaggedValue env = func->GetLexicalEnv(); + args[args.size() - 1] = env.GetRawData(); // last arg is env. + auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_JSFunctionEntry); + auto res = reinterpret_cast(entry)(thread->GetGlueAddr(), + reinterpret_cast(thread->GetLastLeaveFrame()), + static_cast(args.size()) - 1, + static_cast(args.size()) - 1, + args.data(), + func->GetCodeEntry()); + return JSTaggedValue(res); +} + void EcmaInterpreter::NotifyBytecodePcChanged(JSThread *thread) { FrameHandler frameHandler(thread); @@ -668,11 +694,11 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool ObjectFactory *factory = ecmaVm->GetFactory(); constexpr size_t numOps = 0x100; - static thread_local std::array instDispatchTable { + static std::array instDispatchTable { #include "templates/instruction_dispatch.inl" }; - static thread_local std::array debugDispatchTable { + static std::array debugDispatchTable { #include "templates/debugger_instruction_dispatch.inl" }; @@ -893,22 +919,25 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool *(--newSp) = JSTaggedValue::VALUE_UNDEFINED; // push new target *(--newSp) = static_cast(ToUintPtr(funcObject)); // push func ASSERT(method->GetNumVregsWithCallField() == 0); // no need to push vregs - EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, actualNumArgs, newSp); + *(--newSp) = actualNumArgs + NUM_MANDATORY_JSFUNC_ARGS; + *(--newSp) = ToUintPtr(thread); + EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast(newSp); - InterpretedFrame *state = GET_FRAME(newSp); + InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp); state->base.prev = sp; - state->base.type = FrameType::INTERPRETER_FRAME; + state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME; state->pc = nullptr; state->function = JSTaggedValue(funcTagged); thread->SetCurrentSPFrame(newSp); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime Call."; + LOG_INST() << "Entry: Runtime Call."; + SAVE_PC(); JSTaggedValue retValue = reinterpret_cast( - const_cast(method->GetNativePointer()))(&ecmaRuntimeCallInfo); + const_cast(method->GetNativePointer()))(ecmaRuntimeCallInfo); thread->SetCurrentSPFrame(sp); if (UNLIKELY(thread->HasPendingException())) { INTERPRETER_GOTO_EXCEPTION_HANDLER(); } - LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call."; + LOG_INST() << "Exit: Runtime Call."; SET_ACC(retValue); INTERPRETER_HANDLE_RETURN(); } @@ -959,7 +988,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool JSTaggedValue env = JSFunction::Cast(funcObject)->GetLexicalEnv(); state->env = env; thread->SetCurrentSPFrame(newSp); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime Call " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Entry: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(pc); DISPATCH_OFFSET(0); } @@ -967,7 +996,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool HANDLE_OPCODE(HANDLE_RETURN_DYN) { LOG_INST() << "return.dyn"; InterpretedFrame *state = GET_FRAME(sp); - LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); JSMethod *method = JSFunction::Cast(state->function.GetTaggedObject())->GetMethod(); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); @@ -1019,7 +1048,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool HANDLE_OPCODE(HANDLE_RETURNUNDEFINED_PREF) { LOG_INST() << "return.undefined"; InterpretedFrame *state = GET_FRAME(sp); - LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); JSMethod *method = JSFunction::Cast(state->function.GetTaggedObject())->GetMethod(); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); @@ -1933,17 +1962,21 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool if (ctor.IsJSFunction() && ctor.IsConstructor()) { JSFunction *ctorFunc = JSFunction::Cast(ctor.GetTaggedObject()); JSMethod *ctorMethod = ctorFunc->GetMethod(); - if (ctorFunc->IsBuiltinsConstructor()) { + if (ctorFunc->IsBuiltinConstructor()) { ASSERT(ctorMethod->GetNumVregsWithCallField() == 0); - size_t frameSize = INTERPRETER_FRAME_STATE_SIZE + numArgs + 1; // +1 for this + size_t frameSize = InterpretedFrame::NumOfMembers() + numArgs + 3; // 3: this & numArgs & thread // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedType *newSp = sp - frameSize; if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) { INTERPRETER_GOTO_EXCEPTION_HANDLER(); } - EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, numArgs + 1 - NUM_MANDATORY_JSFUNC_ARGS, newSp); // copy args uint32_t index = 0; + // numArgs + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast(newSp); + newSp[index++] = ToUintPtr(thread); + newSp[index++] = static_cast(numArgs + 1); // +1 for this // func // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = GET_VREG(firstArgRegIdx); @@ -1958,21 +1991,22 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool newSp[index++] = GET_VREG(firstArgRegIdx + i); } - InterpretedFrame *state = GET_FRAME(newSp); + InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp); state->base.prev = sp; - state->base.type = FrameType::INTERPRETER_FRAME; + state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME; state->pc = nullptr; state->function = ctor; thread->SetCurrentSPFrame(newSp); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime New."; + LOG_INST() << "Entry: Runtime New."; + SAVE_PC(); JSTaggedValue retValue = reinterpret_cast( - const_cast(ctorMethod->GetNativePointer()))(&ecmaRuntimeCallInfo); + const_cast(ctorMethod->GetNativePointer()))(ecmaRuntimeCallInfo); thread->SetCurrentSPFrame(sp); if (UNLIKELY(thread->HasPendingException())) { INTERPRETER_GOTO_EXCEPTION_HANDLER(); } - LOG(DEBUG, INTERPRETER) << "Exit: Runtime New."; + LOG_INST() << "Exit: Runtime New."; SET_ACC(retValue); DISPATCH(BytecodeInstruction::Format::PREF_IMM16_V8); } @@ -1984,7 +2018,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool ctorMethod->GetNumArgsWithCallField() + 1 : // +1 for this ctorMethod->GetNumArgsWithCallField() + 2; // +2 for newTarget and this // +1 for hidden this, explicit this may be overwritten after bc optimizer - size_t frameSize = INTERPRETER_FRAME_STATE_SIZE + numVregs + numDeclaredArgs + 1; + size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs + 1; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedType *newSp = sp - frameSize; InterpretedFrame *state = GET_FRAME(newSp); @@ -2044,7 +2078,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool constpool = ConstantPool::Cast(state->constpool.GetTaggedObject()); thread->SetCurrentSPFrame(newSp); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime New " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Entry: Runtime New " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(pc); DISPATCH_OFFSET(0); } @@ -2317,7 +2351,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool JSMethod *method = JSFunction::Cast(state->function.GetTaggedObject())->GetMethod(); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); - LOG(DEBUG, INTERPRETER) << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); sp = state->base.prev; ASSERT(sp != nullptr); @@ -3466,23 +3500,28 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool JSTaggedValue thisFunc = GET_ACC(); JSTaggedValue newTarget = GetNewTarget(sp); + SAVE_PC(); JSTaggedValue superCtor = SlowRuntimeStub::GetSuperConstructor(thread, thisFunc); INTERPRETER_RETURN_IF_ABRUPT(superCtor); if (superCtor.IsJSFunction() && superCtor.IsConstructor() && !newTarget.IsUndefined()) { JSFunction *superCtorFunc = JSFunction::Cast(superCtor.GetTaggedObject()); JSMethod *superCtorMethod = superCtorFunc->GetMethod(); - if (superCtorFunc->IsBuiltinsConstructor()) { + if (superCtorFunc->IsBuiltinConstructor()) { ASSERT(superCtorMethod->GetNumVregsWithCallField() == 0); - size_t frameSize = INTERPRETER_FRAME_STATE_SIZE + range + NUM_MANDATORY_JSFUNC_ARGS; + size_t frameSize = + InterpretedFrame::NumOfMembers() + range + NUM_MANDATORY_JSFUNC_ARGS + 2; // 2:thread & numArgs // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedType *newSp = sp - frameSize; if (UNLIKELY(thread->DoStackOverflowCheck(newSp))) { INTERPRETER_GOTO_EXCEPTION_HANDLER(); } - EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, range, newSp); // copy args uint32_t index = 0; + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast(newSp); + newSp[index++] = ToUintPtr(thread); + newSp[index++] = static_cast(range + NUM_MANDATORY_JSFUNC_ARGS); // func // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) newSp[index++] = superCtor.GetRawData(); @@ -3497,21 +3536,21 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool newSp[index++] = GET_VREG(v0 + i); } - InterpretedFrame *state = GET_FRAME(newSp); + InterpretedBuiltinFrame *state = GET_BUILTIN_FRAME(newSp); state->base.prev = sp; - state->base.type = FrameType::INTERPRETER_FRAME; + state->base.type = FrameType::INTERPRETER_BUILTIN_FRAME; state->pc = nullptr; state->function = superCtor; thread->SetCurrentSPFrame(newSp); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime SuperCall "; + LOG_INST() << "Entry: Runtime SuperCall "; JSTaggedValue retValue = reinterpret_cast( - const_cast(superCtorMethod->GetNativePointer()))(&ecmaRuntimeCallInfo); + const_cast(superCtorMethod->GetNativePointer()))(ecmaRuntimeCallInfo); thread->SetCurrentSPFrame(sp); if (UNLIKELY(thread->HasPendingException())) { INTERPRETER_GOTO_EXCEPTION_HANDLER(); } - LOG(DEBUG, INTERPRETER) << "Exit: Runtime SuperCall "; + LOG_INST() << "Exit: Runtime SuperCall "; SET_ACC(retValue); DISPATCH(BytecodeInstruction::Format::PREF_IMM16_V8); } @@ -3523,7 +3562,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool superCtorMethod->GetNumArgsWithCallField() + 1 : // +1 for this superCtorMethod->GetNumArgsWithCallField() + 2; // +2 for newTarget and this // +1 for hidden this, explicit this may be overwritten after bc optimizer - size_t frameSize = INTERPRETER_FRAME_STATE_SIZE + numVregs + numDeclaredArgs + 1; + size_t frameSize = InterpretedFrame::NumOfMembers() + numVregs + numDeclaredArgs + 1; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) JSTaggedType *newSp = sp - frameSize; InterpretedFrame *state = GET_FRAME(newSp); @@ -3581,7 +3620,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool constpool = ConstantPool::Cast(state->constpool.GetTaggedObject()); thread->SetCurrentSPFrame(newSp); - LOG(DEBUG, INTERPRETER) << "Entry: Runtime SuperCall " << std::hex << reinterpret_cast(sp) + LOG_INST() << "Entry: Runtime SuperCall " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(pc); DISPATCH_OFFSET(0); } @@ -3697,7 +3736,7 @@ NO_UB_SANITIZE void EcmaInterpreter::RunInternal(JSThread *thread, ConstantPool DISPATCH_OFFSET(0); } HANDLE_OPCODE(HANDLE_OVERFLOW) { - LOG(FATAL, INTERPRETER) << "opcode overflow"; + LOG_INTERPRETER(FATAL) << "opcode overflow"; } #include "templates/debugger_instruction_handler.inl" } @@ -3707,7 +3746,7 @@ void EcmaInterpreter::InitStackFrame(JSThread *thread) if (thread->IsAsmInterpreter()) { return InterpreterAssembly::InitStackFrame(thread); } - uint64_t *prevSp = const_cast(thread->GetCurrentSPFrame()); + JSTaggedType *prevSp = const_cast(thread->GetCurrentSPFrame()); InterpretedFrame *state = GET_FRAME(prevSp); state->pc = nullptr; state->function = JSTaggedValue::Hole(); @@ -3772,9 +3811,9 @@ uint32_t EcmaInterpreter::GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_ JSTaggedType *lastFrame = state->base.prev; // The prev frame of InterpretedFrame may entry frame or interpreter frame. if (FrameHandler::GetFrameType(state->base.prev) == FrameType::INTERPRETER_ENTRY_FRAME) { - lastFrame = FrameHandler::GetInterpretedEntryFrameStart(state->base.prev); + lastFrame = lastFrame - InterpretedEntryFrame::NumOfMembers(); } else { - lastFrame = lastFrame - INTERPRETER_FRAME_STATE_SIZE; + lastFrame = lastFrame - InterpretedFrame::NumOfMembers(); } if (static_cast(lastFrame - sp) > numVregs + copyArgs + numArgs) { @@ -3843,7 +3882,7 @@ bool EcmaInterpreter::UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp, J // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) auto thisFunc = state->function; auto res = SlowRuntimeStub::NotifyInlineCache( - thread, JSFunction::Cast(thisFunc.GetHeapObject()), method); + thread, JSFunction::Cast(thisFunc.GetTaggedObject()), method); state->profileTypeInfo = res; method->SetHotnessCounter(EcmaInterpreter::METHOD_HOTNESS_THRESHOLD); return true; @@ -4066,7 +4105,6 @@ std::string GetEcmaOpcodeStr(EcmaOpcode opcode) #undef DISPATCH_OFFSET #undef GET_FRAME #undef GET_ENTRY_FRAME -#undef GET_ENTRY_FRAME_WITH_ARGS_SIZE #undef SAVE_PC #undef SAVE_ACC #undef RESTORE_ACC diff --git a/ecmascript/interpreter/interpreter.cpp b/ecmascript/interpreter/interpreter.cpp index 8081c39af6fb7b35d68da20ca69ebb689ba8eb0f..2a6da1407d72e416dbba1aeeffe94a342e4d93ea 100644 --- a/ecmascript/interpreter/interpreter.cpp +++ b/ecmascript/interpreter/interpreter.cpp @@ -20,15 +20,9 @@ namespace panda::ecmascript { // make EcmaRuntimeCallInfo in stack pointer as fallows: // +----------------------+ — -// | base.type | ^ -// |----------------------| | -// | base.prev | InterpretedEntryFrame -// |----------------------| | -// | pc | v -// |----------------------| — -// | numArgs | ^ +// | args... | ^ // |----------------------| | -// | args... | | +// | numArgs | | // |----------------------| | // | this | | // |----------------------| EcmaRuntimeCallInfo @@ -36,37 +30,49 @@ namespace panda::ecmascript { // |----------------------| | // | func | v // +----------------------+ — -EcmaRuntimeCallInfo EcmaInterpreter::NewRuntimeCallInfo( +// | base.type | ^ +// |----------------------| | +// | base.prev | InterpretedEntryFrame +// |----------------------| | +// | pc | v +// +--------------------------+ +EcmaRuntimeCallInfo* EcmaInterpreter::NewRuntimeCallInfo( JSThread *thread, JSHandle func, JSHandle thisObj, JSHandle newTarget, - size_t numArgs) + int32_t numArgs) { JSTaggedType *sp = const_cast(thread->GetCurrentSPFrame()); - JSTaggedType *newSp; + JSTaggedType *newSp = nullptr; JSTaggedType *prevSp = sp; if (thread->IsAsmInterpreter()) { - newSp = FrameHandler::GetInterpretedEntryFrameStart(sp); + newSp = sp - InterpretedEntryFrame::NumOfMembers(); } else { - newSp = sp - InterpretedFrame::NumOfMembers(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + if (FrameHandler::GetFrameType(sp) == FrameType::INTERPRETER_FRAME || + FrameHandler::GetFrameType(sp) == FrameType::INTERPRETER_FAST_NEW_FRAME) { + newSp = sp - InterpretedFrame::NumOfMembers(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + } else { + newSp = + sp - InterpretedEntryFrame::NumOfMembers(); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) + } } - if (UNLIKELY(thread->DoStackOverflowCheck(newSp - numArgs - RESERVED_CALL_ARGCOUNT))) { - EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, INVALID_ARGS_NUMBER, nullptr); - return ecmaRuntimeCallInfo; + if (UNLIKELY(thread->DoStackOverflowCheck(newSp - numArgs - NUM_MANDATORY_JSFUNC_ARGS))) { + return nullptr; } - thread->SetCurrentSPFrame(newSp); + newSp -= numArgs; + *(--newSp) = thisObj.GetTaggedType(); + *(--newSp) = newTarget.GetTaggedType(); + *(--newSp) = func.GetTaggedType(); + *(--newSp) = numArgs + NUM_MANDATORY_JSFUNC_ARGS; + *(--newSp) = ToUintPtr(thread); + EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast(newSp); + // create entry frame. InterpretedEntryFrame *entryState = InterpretedEntryFrame::GetFrameFromSp(newSp); entryState->base.type = FrameType::INTERPRETER_ENTRY_FRAME; entryState->base.prev = prevSp; entryState->pc = nullptr; - newSp -= INTERPRETER_ENTRY_FRAME_STATE_SIZE; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *(--newSp) = JSTaggedValue(static_cast(numArgs)).GetRawData(); - newSp -= numArgs; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - *(--newSp) = thisObj.GetTaggedType(); - *(--newSp) = newTarget.GetTaggedType(); - *(--newSp) = func.GetTaggedType(); - EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, numArgs, newSp); + thread->SetCurrentSPFrame(newSp); return ecmaRuntimeCallInfo; } } // namespace panda::ecmascript diff --git a/ecmascript/interpreter/interpreter.h b/ecmascript/interpreter/interpreter.h index d37e9b5be2415b6799c374f5cbc01e12ddb272eb..879806494b56723de4b8c8d99f156144290375e5 100644 --- a/ecmascript/interpreter/interpreter.h +++ b/ecmascript/interpreter/interpreter.h @@ -29,16 +29,6 @@ class ConstantPool; class ECMAObject; class GeneratorContext; -// NOLINTNEXTLINE(bugprone-sizeof-expression) -static const uint32_t INTERPRETER_FRAME_STATE_SIZE = sizeof(InterpretedFrame) / sizeof(uint64_t); -static const uint32_t INTERPRETER_ENTRY_FRAME_STATE_SIZE = sizeof(InterpretedEntryFrame) / sizeof(uint64_t); - -static constexpr uint32_t RESERVED_CALL_ARGCOUNT = 3; -static constexpr uint32_t RESERVED_INDEX_CALL_TARGET = 0; -static constexpr uint32_t RESERVED_INDEX_NEW_TARGET = 1; -static constexpr uint32_t RESERVED_INDEX_THIS = 2; -static constexpr uint32_t INVALID_ARGS_NUMBER = -1; - class EcmaInterpreter { public: static const int16_t METHOD_HOTNESS_THRESHOLD = 512; @@ -46,10 +36,11 @@ public: static inline JSTaggedValue Execute(EcmaRuntimeCallInfo *info); static inline JSTaggedValue ExecuteNative(EcmaRuntimeCallInfo *info); - static EcmaRuntimeCallInfo NewRuntimeCallInfo( + static EcmaRuntimeCallInfo* NewRuntimeCallInfo( JSThread *thread, JSHandle func, JSHandle thisObj, - JSHandle newTarget, size_t numArgs); + JSHandle newTarget, int32_t numArgs); static inline JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle context); + static inline JSTaggedValue GeneratorReEnterAot(JSThread *thread, JSHandle context); static inline void RunInternal(JSThread *thread, ConstantPool *constpool, const uint8_t *pc, JSTaggedType *sp); static inline void InitStackFrame(JSThread *thread); static inline uint32_t FindCatchBlock(JSMethod *caller, uint32_t pc); diff --git a/ecmascript/interpreter/interpreter_assembly.cpp b/ecmascript/interpreter/interpreter_assembly.cpp index 0c1411607409f53371f7b9c0cc403992b9ebadc8..0ad426b50d923780288efe6427860e1b7c8d112f 100644 --- a/ecmascript/interpreter/interpreter_assembly.cpp +++ b/ecmascript/interpreter/interpreter_assembly.cpp @@ -47,8 +47,11 @@ using panda::ecmascript::kungfu::CommonStubCSigns; #pragma GCC diagnostic ignored "-Wunused-parameter" #endif -// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -#define LOG_INST() LOG(DEBUG, INTERPRETER) << ": " +#if ECMASCRIPT_ENABLE_INTERPRETER_LOG +#define LOG_INST() LOG_INTERPRETER(DEBUG) +#else +#define LOG_INST() false && LOG_INTERPRETER(DEBUG) +#endif // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define ADVANCE_PC(offset) \ @@ -75,8 +78,8 @@ using panda::ecmascript::kungfu::CommonStubCSigns; (reinterpret_cast(CurrentSp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) #define GET_ENTRY_FRAME(sp) \ (reinterpret_cast(sp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) -#define GET_ENTRY_FRAME_WITH_ARGS_SIZE(actualNumArgs) \ - (static_cast(INTERPRETER_ENTRY_FRAME_STATE_SIZE + 1 + (actualNumArgs) + RESERVED_CALL_ARGCOUNT)) +#define GET_BUILTIN_FRAME(sp) \ + (reinterpret_cast(sp) - 1) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define SAVE_PC() (GET_ASM_FRAME(sp)->pc = pc) // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) @@ -187,7 +190,8 @@ using panda::ecmascript::kungfu::CommonStubCSigns; #define GET_ACC() (acc) // NOLINT(cppcoreguidelines-macro-usage) #define SET_ACC(val) (acc = val); // NOLINT(cppcoreguidelines-macro-usage) -using InterpreterEntry = JSTaggedType (*)(uintptr_t glue, uint32_t argc, uintptr_t argv); +using InterpreterEntry = JSTaggedType (*)(uintptr_t glue, ECMAObject *callTarget, + JSMethod *method, uint64_t callField, size_t argc, uintptr_t argv); using GeneratorReEnterInterpEntry = JSTaggedType (*)(uintptr_t glue, JSTaggedType context); void InterpreterAssembly::InitStackFrame(JSThread *thread) @@ -197,12 +201,6 @@ void InterpreterAssembly::InitStackFrame(JSThread *thread) entryState->base.type = FrameType::INTERPRETER_ENTRY_FRAME; entryState->base.prev = nullptr; entryState->pc = nullptr; - - JSTaggedType *newSp = prevSp - INTERPRETER_ENTRY_FRAME_STATE_SIZE; - *(--newSp) = JSTaggedValue(static_cast(0)).GetRawData(); - *(--newSp) = JSTaggedValue::Undefined().GetRawData(); - *(--newSp) = JSTaggedValue::Undefined().GetRawData(); - *(--newSp) = JSTaggedValue::Undefined().GetRawData(); } JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info) @@ -214,10 +212,14 @@ JSTaggedValue InterpreterAssembly::Execute(EcmaRuntimeCallInfo *info) CpuProfiler::IsNeedAndGetStack(thread); #endif thread->CheckSafepoint(); - size_t argc = info->GetArgsNumber(); + int32_t argc = info->GetArgsNumber(); uintptr_t argv = reinterpret_cast(info->GetArgs()); auto entry = thread->GetRTInterface(kungfu::RuntimeStubCSigns::ID_AsmInterpreterEntry); - auto acc = reinterpret_cast(entry)(thread->GetGlueAddr(), argc, argv); + + ECMAObject *callTarget = reinterpret_cast(info->GetFunctionValue().GetTaggedObject()); + JSMethod *method = callTarget->GetCallTarget(); + auto acc = reinterpret_cast(entry)(thread->GetGlueAddr(), + callTarget, method, method->GetCallField(), argc, argv); auto sp = const_cast(thread->GetCurrentSPFrame()); ASSERT(FrameHandler::GetFrameType(sp) == FrameType::INTERPRETER_ENTRY_FRAME); auto prevEntry = InterpretedEntryFrame::GetFrameFromSp(sp)->GetPrevFrameFp(); @@ -428,9 +430,9 @@ void InterpreterAssembly::HandleCallArg0DynPrefV8( // slow path JSHandle funcHandle(thread, GET_VREG_VALUE(funcReg)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, undefined, undefined, actualNumArgs); - JSFunction::Call(&info); + JSFunction::Call(info); DISPATCH(BytecodeInstruction::Format::PREF_V8); } @@ -446,10 +448,11 @@ void InterpreterAssembly::HandleCallArg1DynPrefV8V8( // slow path JSHandle funcHandle(thread, GET_VREG_VALUE(funcReg)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, undefined, undefined, actualNumArgs); - info.SetCallArg(GET_VREG_VALUE(a0)); - JSFunction::Call(&info); + RETURN_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(GET_VREG_VALUE(a0)); + JSFunction::Call(info); DISPATCH(BytecodeInstruction::Format::PREF_V8_V8); } @@ -466,10 +469,11 @@ void InterpreterAssembly::HandleCallArgs2DynPrefV8V8V8( // slow path JSHandle funcHandle(thread, GET_VREG_VALUE(funcReg)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, undefined, undefined, actualNumArgs); - info.SetCallArg(GET_VREG_VALUE(a0), GET_VREG_VALUE(a1)); - JSFunction::Call(&info); + RETURN_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(GET_VREG_VALUE(a0), GET_VREG_VALUE(a1)); + JSFunction::Call(info); DISPATCH(BytecodeInstruction::Format::PREF_V8_V8_V8); } @@ -487,10 +491,11 @@ void InterpreterAssembly::HandleCallArgs3DynPrefV8V8V8V8( // slow path JSHandle funcHandle(thread, GET_VREG_VALUE(funcReg)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, undefined, undefined, actualNumArgs); - info.SetCallArg(GET_VREG_VALUE(a0), GET_VREG_VALUE(a1), GET_VREG_VALUE(a2)); - JSFunction::Call(&info); + RETURN_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(GET_VREG_VALUE(a0), GET_VREG_VALUE(a1), GET_VREG_VALUE(a2)); + JSFunction::Call(info); DISPATCH(BytecodeInstruction::Format::PREF_V8_V8_V8_V8); } @@ -505,12 +510,13 @@ void InterpreterAssembly::HandleCallIThisRangeDynPrefImm16V8( JSHandle funcHandle(thread, GET_VREG_VALUE(funcReg)); JSHandle thisHandle(thread, GET_VREG_VALUE(funcReg + 1)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, thisHandle, undefined, actualNumArgs); + RETURN_IF_ABRUPT_COMPLETION(thread); for (uint32_t i = 0; i < actualNumArgs; i++) { - info.SetCallArg(i, GET_VREG_VALUE(funcReg + i + 2)); // 2: start index of the first arg + info->SetCallArg(i, GET_VREG_VALUE(funcReg + i + 2)); // 2: start index of the first arg } - JSFunction::Call(&info); + JSFunction::Call(info); DISPATCH(BytecodeInstruction::Format::PREF_IMM16_V8); } @@ -544,12 +550,13 @@ void InterpreterAssembly::HandleCallIRangeDynPrefImm16V8( // slow path JSHandle funcHandle(thread, GET_VREG_VALUE(funcReg)); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, undefined, undefined, actualNumArgs); + RETURN_IF_ABRUPT_COMPLETION(thread); for (uint32_t i = 0; i < actualNumArgs; i++) { - info.SetCallArg(i, GET_VREG_VALUE(funcReg + i + 1)); // 1: start index of the first arg + info->SetCallArg(i, GET_VREG_VALUE(funcReg + i + 1)); // 1: start index of the first arg } - JSFunction::Call(&info); + JSFunction::Call(info); DISPATCH(BytecodeInstruction::Format::PREF_IMM16_V8); } @@ -559,7 +566,7 @@ void InterpreterAssembly::HandleReturnDyn( { LOG_INST() << "returnla "; AsmInterpretedFrame *state = GET_ASM_FRAME(sp); - LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); JSMethod *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); @@ -587,7 +594,7 @@ void InterpreterAssembly::HandleReturnUndefinedPref( { LOG_INST() << "return.undefined"; AsmInterpretedFrame *state = GET_ASM_FRAME(sp); - LOG(DEBUG, INTERPRETER) << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Exit: Runtime Call " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); JSMethod *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); @@ -1995,7 +2002,7 @@ void InterpreterAssembly::HandleSuspendGeneratorPrefV8V8( JSMethod *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); [[maybe_unused]] auto fistPC = method->GetBytecodeArray(); UPDATE_HOTNESS_COUNTER(-(pc - fistPC)); - LOG(DEBUG, INTERPRETER) << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " + LOG_INST() << "Exit: SuspendGenerator " << std::hex << reinterpret_cast(sp) << " " << std::hex << reinterpret_cast(state->pc); sp = state->base.prev; ASSERT(sp != nullptr); @@ -3495,7 +3502,7 @@ void InterpreterAssembly::HandleOverflow( JSThread *thread, const uint8_t *pc, JSTaggedType *sp, JSTaggedValue constpool, JSTaggedValue profileTypeInfo, JSTaggedValue acc, int32_t hotnessCounter) { - LOG(FATAL, INTERPRETER) << "opcode overflow"; + LOG_INTERPRETER(FATAL) << "opcode overflow"; } uint32_t InterpreterAssembly::FindCatchBlock(JSMethod *caller, uint32_t pc) @@ -3556,9 +3563,7 @@ JSTaggedValue InterpreterAssembly::GetNewTarget(JSTaggedType *sp) JSTaggedType *InterpreterAssembly::GetAsmInterpreterFramePointer(AsmInterpretedFrame *state) { - JSTaggedType *fp = nullptr; - fp = state->GetCurrentFramePointer(); - return fp; + return state->GetCurrentFramePointer(); } uint32_t InterpreterAssembly::GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx) @@ -3640,7 +3645,6 @@ inline JSTaggedValue InterpreterAssembly::UpdateHotnessCounter(JSThread* thread, #undef DISPATCH_OFFSET #undef GET_ASM_FRAME #undef GET_ENTRY_FRAME -#undef GET_ENTRY_FRAME_WITH_ARGS_SIZE #undef SAVE_PC #undef SAVE_ACC #undef RESTORE_ACC diff --git a/ecmascript/interpreter/slow_runtime_helper.cpp b/ecmascript/interpreter/slow_runtime_helper.cpp index 609c782338ac5d42d2e79be200a8ecd873b3841a..06bd56bda825f4deff290999cae2ff70e9bb907f 100644 --- a/ecmascript/interpreter/slow_runtime_helper.cpp +++ b/ecmascript/interpreter/slow_runtime_helper.cpp @@ -34,19 +34,20 @@ JSTaggedValue SlowRuntimeHelper::CallBoundFunction(EcmaRuntimeCallInfo *info) } JSHandle boundArgs(thread, boundFunc->GetBoundArguments()); - const size_t boundLength = boundArgs->GetLength(); - const size_t argsLength = info->GetArgsNumber() + boundLength; + const int32_t boundLength = static_cast(boundArgs->GetLength()); + const int32_t argsLength = info->GetArgsNumber() + boundLength; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(targetFunc), + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(targetFunc), info->GetThis(), undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boundLength == 0) { - runtimeInfo.SetCallArg(argsLength, 0, info, 0); + runtimeInfo->SetCallArg(argsLength, 0, info, 0); } else { // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo. - runtimeInfo.SetCallArg(boundLength, boundArgs); - runtimeInfo.SetCallArg(argsLength, boundLength, info, 0); + runtimeInfo->SetCallArg(boundLength, boundArgs); + runtimeInfo->SetCallArg(argsLength, boundLength, info, 0); } - return EcmaInterpreter::Execute(&runtimeInfo); + return EcmaInterpreter::Execute(runtimeInfo); } JSTaggedValue SlowRuntimeHelper::NewObject(EcmaRuntimeCallInfo *info) @@ -73,17 +74,6 @@ JSTaggedValue SlowRuntimeHelper::NewObject(EcmaRuntimeCallInfo *info) THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception()); } - JSHandle jsFunc = JSHandle::Cast(func); - ASSERT(jsFunc->GetCallTarget() != nullptr); - ASSERT(JSFunction::Cast(info->GetNewTarget()->GetTaggedObject())->GetCallTarget() != nullptr); - - if (jsFunc->GetCallTarget()->IsNativeWithCallField()) { - if (jsFunc->IsBuiltinsConstructor()) { - return EcmaInterpreter::Execute(info); - } - THROW_TYPE_ERROR_AND_RETURN(thread, "Constructed NonConstructable", JSTaggedValue::Exception()); - } - JSTaggedValue result = JSFunction::ConstructInternal(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result; @@ -116,7 +106,7 @@ JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHa } JSHandle obj(thread, JSTaggedValue::Undefined()); - if (!ctor->IsBuiltinsConstructor() && ctor->IsBase()) { + if (ctor->IsBase()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); obj = JSHandle(factory->NewJSObjectByConstructor(ctor, newTgt)); } @@ -149,13 +139,14 @@ JSTaggedValue ConstructGeneric(JSThread *thread, JSHandle ctor, JSHa values.emplace_back(value.GetRawData()); } } - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(ctor), obj, newTgt, size); - info.SetCallArg(size, values.data()); - JSTaggedValue resultValue = EcmaInterpreter::Execute(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(size, values.data()); + JSTaggedValue resultValue = EcmaInterpreter::Execute(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9.3.2 [[Construct]] (argumentsList, newTarget) - if (ctor->IsBuiltinsConstructor() || resultValue.IsECMAObject()) { + if (resultValue.IsECMAObject()) { return resultValue; } @@ -218,8 +209,8 @@ JSTaggedValue ConstructProxy(JSThread *thread, JSHandle ctor, JSHandle< uint32_t preArgsSize = preArgs->IsUndefined() ? 0 : JSHandle::Cast(preArgs)->GetLength(); const uint32_t size = preArgsSize + argsCount; JSHandle args = thread->GetEcmaVM()->GetFactory()->NewTaggedArray(size); - JSHandle tgaPreArgs = JSHandle::Cast(preArgs); if (preArgsSize > 0) { + JSHandle tgaPreArgs = JSHandle::Cast(preArgs); for (uint32_t i = 0; i < preArgsSize; ++i) { JSTaggedValue value = tgaPreArgs->Get(i); args->Set(thread, i, value); @@ -232,11 +223,12 @@ JSTaggedValue ConstructProxy(JSThread *thread, JSHandle ctor, JSHandle< } // step 8 ~ 9 Call(trap, handler, «target, argArray, newTarget »). - const size_t argsLength = 3; // 3: «target, argArray, newTarget » + const int32_t argsLength = 3; // 3: «target, argArray, newTarget » JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, handler, undefined, argsLength); - info.SetCallArg(target.GetTaggedValue(), args.GetTaggedValue(), newTgt.GetTaggedValue()); - JSTaggedValue newObjValue = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, handler, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(target.GetTaggedValue(), args.GetTaggedValue(), newTgt.GetTaggedValue()); + JSTaggedValue newObjValue = JSFunction::Call(info); // 10.ReturnIfAbrupt(newObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 11.If Type(newObj) is not Object, throw a TypeError exception. diff --git a/ecmascript/interpreter/slow_runtime_helper.h b/ecmascript/interpreter/slow_runtime_helper.h index 39dd8c04873fccffe18d6dee86889d8779ec5d04..2e9573752177a2f4c94c131bf8d0b5885aedd421 100644 --- a/ecmascript/interpreter/slow_runtime_helper.h +++ b/ecmascript/interpreter/slow_runtime_helper.h @@ -21,7 +21,6 @@ #include "ecmascript/object_factory.h" namespace panda::ecmascript { -class EcmaRuntimeCallInfo; class SlowRuntimeHelper { public: static JSTaggedValue NewObject(EcmaRuntimeCallInfo *info); diff --git a/ecmascript/interpreter/slow_runtime_stub.cpp b/ecmascript/interpreter/slow_runtime_stub.cpp index 5caca98ad659e19f9955bd1444f3298e8b681369..dec6014dded2103c1caefb44a116b505814b9135 100644 --- a/ecmascript/interpreter/slow_runtime_stub.cpp +++ b/ecmascript/interpreter/slow_runtime_stub.cpp @@ -57,12 +57,13 @@ JSTaggedValue SlowRuntimeStub::CallSpreadDyn(JSThread *thread, JSTaggedValue fun JSHandle taggedObj(thread, obj); JSHandle coretypesArray(thread, GetCallSpreadArgs(thread, jsArray.GetTaggedValue())); - const size_t argsLength = coretypesArray->GetLength(); + const uint32_t argsLength = coretypesArray->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(jsFunc), taggedObj, undefined, argsLength); - info.SetCallArg(argsLength, coretypesArray); - return EcmaInterpreter::Execute(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, coretypesArray); + return EcmaInterpreter::Execute(info); } JSTaggedValue SlowRuntimeStub::NegDyn(JSThread *thread, JSTaggedValue value) @@ -911,9 +912,10 @@ JSTaggedValue SlowRuntimeStub::AsyncFunctionResolveOrReject(JSThread *thread, JS activeFunc = JSHandle(thread, reactions->GetRejectFunction()); } JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, activeFunc, thisArg, undefined, 1); - info.SetCallArg(valueHandle.GetTaggedValue()); - [[maybe_unused]] JSTaggedValue res = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, activeFunc, thisArg, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(valueHandle.GetTaggedValue()); + [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return promise.GetTaggedValue(); @@ -934,14 +936,15 @@ JSTaggedValue SlowRuntimeStub::NewObjSpreadDyn(JSThread *thread, JSTaggedValue f uint32_t length = JSHandle::Cast(jsArray)->GetArrayLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, funcHandle, undefined, newTargetHandle, length); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); for (size_t i = 0; i < length; i++) { auto prop = JSTaggedValue::GetProperty(thread, jsArray, i).GetValue(); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - info.SetCallArg(i, prop.GetTaggedValue()); + info->SetCallArg(i, prop.GetTaggedValue()); } - return SlowRuntimeHelper::NewObject(&info); + return SlowRuntimeHelper::NewObject(info); } void SlowRuntimeStub::ThrowUndefinedIfHole(JSThread *thread, JSTaggedValue obj) @@ -1329,8 +1332,8 @@ JSTaggedValue SlowRuntimeStub::GetIteratorNext(JSThread *thread, JSTaggedValue o ASSERT(next->IsCallable()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 0); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 0); + JSTaggedValue ret = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!ret.IsECMAObject()) { return ThrowTypeError(thread, "the Iterator is not an ecmaobject."); @@ -1419,8 +1422,8 @@ JSTaggedValue SlowRuntimeStub::GetIterator(JSThread *thread, JSTaggedValue obj) return valuesFunc.GetTaggedValue(); } JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, valuesFunc, objHandle, undefined, 0); - return EcmaInterpreter::Execute(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, valuesFunc, objHandle, undefined, 0); + return EcmaInterpreter::Execute(info); } JSTaggedValue SlowRuntimeStub::DefineGetterSetterByValue(JSThread *thread, JSTaggedValue obj, JSTaggedValue prop, @@ -1871,12 +1874,13 @@ JSTaggedValue SlowRuntimeStub::SuperCall(JSThread *thread, JSTaggedValue func, J JSHandle superFunc(thread, JSTaggedValue::GetPrototype(thread, funcHandle)); ASSERT(superFunc->IsJSFunction()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, superFunc, undefined, newTargetHandle, length); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); for (size_t i = 0; i < length; i++) { - info.SetCallArg(i, frameHandler.GetVRegValue(firstVRegIdx + i)); + info->SetCallArg(i, frameHandler.GetVRegValue(firstVRegIdx + i)); } - JSTaggedValue result = JSFunction::Construct(&info); + JSTaggedValue result = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result; @@ -1896,12 +1900,13 @@ JSTaggedValue SlowRuntimeStub::SuperCallSpread(JSThread *thread, JSTaggedValue f ASSERT(superFunc->IsJSFunction()); JSHandle argv(thread, GetCallSpreadArgs(thread, jsArray.GetTaggedValue())); - const size_t argsLength = argv->GetLength(); + const uint32_t argsLength = argv->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, superFunc, undefined, newTargetHandle, argsLength); - info.SetCallArg(argsLength, argv); - JSTaggedValue result = JSFunction::Construct(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, argv); + JSTaggedValue result = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result; diff --git a/ecmascript/interpreter/slow_runtime_stub.h b/ecmascript/interpreter/slow_runtime_stub.h index 1b7380c8ae0fd3eb063eeed6b574eb0a1e456a8d..93efa8c815387dc38343d10fbb38306455b6760e 100644 --- a/ecmascript/interpreter/slow_runtime_stub.h +++ b/ecmascript/interpreter/slow_runtime_stub.h @@ -26,7 +26,6 @@ class JSArray; class SlowRuntimeStub { public: - /* -------------- Common API Begin, Don't change those interface!!! ----------------- */ static JSTaggedValue CallSpreadDyn(JSThread *thread, JSTaggedValue func, JSTaggedValue obj, JSTaggedValue array); static JSTaggedValue NegDyn(JSThread *thread, JSTaggedValue value); static JSTaggedValue AsyncFunctionEnter(JSThread *thread); @@ -161,7 +160,6 @@ public: static JSTaggedValue GetModuleNamespace(JSThread *thread, JSTaggedValue localName); static JSTaggedValue LdBigInt(JSThread *thread, JSTaggedValue numberBigInt); static JSTaggedValue ThrowTypeError(JSThread *thread, const char *message); - /* -------------- Common API End, Don't change those interface!!! ----------------- */ private: static JSTaggedValue ThrowSyntaxError(JSThread *thread, const char *message); diff --git a/ecmascript/jobs/hitrace_scope.cpp b/ecmascript/jobs/hitrace_scope.cpp new file mode 100644 index 0000000000000000000000000000000000000000..69d585899e72dcc283bbc923d94c879ab25405e3 --- /dev/null +++ b/ecmascript/jobs/hitrace_scope.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/jobs/hitrace_scope.h" + +#include "ecmascript/jobs/pending_job.h" +#include "hitrace/hitrace.h" + +namespace panda::ecmascript::job { +EnqueueJobScope::EnqueueJobScope(const JSHandle &pendingJob, QueueType queueType) +{ + HiTraceId id = HiTrace::GetId(); + if (id.IsValid() && id.IsFlagEnabled(HITRACE_FLAG_INCLUDE_ASYNC)) { + HiTraceId childId = HiTrace::CreateSpan(); + + pendingJob->SetChainId(childId.GetChainId()); + pendingJob->SetSpanId(childId.GetSpanId()); + pendingJob->SetParentSpanId(childId.GetParentSpanId()); + pendingJob->SetFlags(childId.GetFlags()); + + if (id.IsFlagEnabled(HITRACE_FLAG_TP_INFO)) { + if (queueType == QueueType::QUEUE_PROMISE) { + HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_CS, + childId, "Queue type:%s", "Promise queue"); + } else if (queueType == QueueType::QUEUE_SCRIPT) { + HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_CS, + childId, "Queue type:%s", "Script queue"); + } else { + HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_CS, + childId, "Queue type:%s", "Other queue"); + } + } + } +} + +EnqueueJobScope::~EnqueueJobScope() +{ +} + +ExecuteJobScope::ExecuteJobScope(const JSHandle &pendingJob) +{ + saveId_ = HiTrace::GetId(); + if (saveId_.IsValid()) { + HiTrace::ClearId(); + } + if (pendingJob->GetChainId() != 0) { + hitraceId_.SetChainId(pendingJob->GetChainId()); + hitraceId_.SetSpanId(pendingJob->GetSpanId()); + hitraceId_.SetParentSpanId(pendingJob->GetParentSpanId()); + hitraceId_.SetFlags(pendingJob->GetFlags()); + + if (hitraceId_.IsValid()) { + HiTrace::SetId(hitraceId_); + if (hitraceId_.IsFlagEnabled(HITRACE_FLAG_TP_INFO)) { + HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_SR, + hitraceId_, "Before %s pending job execute", "Promise"); + } + } + } +} + +ExecuteJobScope::~ExecuteJobScope() +{ + if (hitraceId_.IsValid()) { + if (hitraceId_.IsFlagEnabled(HITRACE_FLAG_TP_INFO)) { + HiTrace::Tracepoint(HITRACE_CM_THREAD, HITRACE_TP_SS, + hitraceId_, "After %s pending job execute", "Promise"); + } + HiTrace::ClearId(); + } + if (saveId_.IsValid()) { + HiTrace::SetId(saveId_); + } +} +} // namespace panda::ecmascript::job \ No newline at end of file diff --git a/ecmascript/jobs/hitrace_scope.h b/ecmascript/jobs/hitrace_scope.h new file mode 100644 index 0000000000000000000000000000000000000000..9787ed87e2d555f9db007a836dea874c9a623da6 --- /dev/null +++ b/ecmascript/jobs/hitrace_scope.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_JOBS_HIREACE_SCOPE_H +#define ECMASCRIPT_JOBS_HIREACE_SCOPE_H + +#include "ecmascript/jobs/micro_job_queue.h" +#include "ecmascript/js_handle.h" +#if defined(ENABLE_HITRACE) +#include "hitrace/hitraceid.h" +#endif + +namespace panda::ecmascript::job { +#if defined(ENABLE_HITRACE) +using namespace OHOS::HiviewDFX; +#endif +class PendingJob; +class EnqueueJobScope { +public: + explicit EnqueueJobScope(const JSHandle &pendingJob, job::QueueType queueType); + + ~EnqueueJobScope(); +}; + +class ExecuteJobScope { +public: + explicit ExecuteJobScope(const JSHandle &pendingJob); + + ~ExecuteJobScope(); +private: +#if defined(ENABLE_HITRACE) + HiTraceId saveId_; + HiTraceId hitraceId_; +#endif +}; +} // namespace panda::ecmascript::job +#endif // ECMASCRIPT_JOBS_HIREACE_SCOPE_H diff --git a/ecmascript/jobs/micro_job_queue.cpp b/ecmascript/jobs/micro_job_queue.cpp index 14c046c3990a6474c40fdb4d3654d6e42f442351..93d9545ffd69b5a1b21c4cdf92471ae63f8bbbbf 100644 --- a/ecmascript/jobs/micro_job_queue.cpp +++ b/ecmascript/jobs/micro_job_queue.cpp @@ -16,6 +16,7 @@ #include "ecmascript/jobs/micro_job_queue.h" #include "ecmascript/global_env.h" +#include "ecmascript/jobs/hitrace_scope.h" #include "ecmascript/jobs/pending_job.h" #include "ecmascript/js_arguments.h" #include "ecmascript/js_handle.h" @@ -38,12 +39,12 @@ void MicroJobQueue::EnqueueJob(JSThread *thread, JSHandle jobQueu ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle pendingJob(factory->NewPendingJob(job, argv)); + ENQUEUE_JOB_HITRACE(pendingJob, queueType); if (queueType == QueueType::QUEUE_PROMISE) { JSHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); - LOG_ECMA(DEBUG) << "promiseQueue start length: " << promiseQueue->Size(); TaggedQueue *newPromiseQueue = TaggedQueue::Push(thread, promiseQueue, JSHandle(pendingJob)); jobQueue->SetPromiseJobQueue(thread, JSTaggedValue(newPromiseQueue)); - LOG_ECMA(DEBUG) << "promiseQueue end length: " << newPromiseQueue->Size(); + LOG_ECMA(VERBOSE) << "EnqueueJob length: " << newPromiseQueue->Size(); } else if (queueType == QueueType::QUEUE_SCRIPT) { JSHandle scriptQueue(thread, jobQueue->GetScriptJobQueue()); TaggedQueue *newScriptQueue = TaggedQueue::Push(thread, scriptQueue, JSHandle(pendingJob)); @@ -57,9 +58,8 @@ void MicroJobQueue::ExecutePendingJob(JSThread *thread, JSHandle JSMutableHandle promiseQueue(thread, jobQueue->GetPromiseJobQueue()); JSMutableHandle pendingJob(thread, JSTaggedValue::Undefined()); while (!promiseQueue->Empty()) { - LOG_ECMA(DEBUG) << "promiseQueue start length: " << promiseQueue->Size(); + LOG_ECMA(VERBOSE) << "ExecutePendingJob length: " << promiseQueue->Size(); pendingJob.Update(promiseQueue->Pop(thread)); - LOG_ECMA(DEBUG) << "promiseQueue end length: " << promiseQueue->Size(); PendingJob::ExecutePendingJob(pendingJob, thread); if (thread->HasPendingException()) { return; diff --git a/ecmascript/jobs/micro_job_queue.h b/ecmascript/jobs/micro_job_queue.h index d675f6c7d4f6db970e5d7d7d7de55525d2bc24bf..f21ac1bd2032e5e95fee6d3ded94f1a5eb519edf 100644 --- a/ecmascript/jobs/micro_job_queue.h +++ b/ecmascript/jobs/micro_job_queue.h @@ -17,7 +17,6 @@ #define ECMASCRIPT_JOBS_MICRO_JOB_QUEUE_H #include "ecmascript/ecma_string.h" -#include "ecmascript/jobs/pending_job.h" #include "ecmascript/js_handle.h" #include "ecmascript/js_thread.h" #include "ecmascript/mem/c_containers.h" @@ -33,7 +32,7 @@ enum class QueueType : uint8_t { class MicroJobQueue final : public Record { public: - static MicroJobQueue *Cast(ObjectHeader *object) + static MicroJobQueue *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsMicroJobQueue()); return static_cast(object); diff --git a/ecmascript/jobs/pending_job.h b/ecmascript/jobs/pending_job.h index 78dadfeb605ca243dba5b74428e2bc62ab8d6118..600d4d55c3e701584b205073afe541e722d437bd 100644 --- a/ecmascript/jobs/pending_job.h +++ b/ecmascript/jobs/pending_job.h @@ -18,10 +18,11 @@ #include "ecmascript/ecma_macros.h" #include "ecmascript/interpreter/interpreter.h" +#include "ecmascript/jobs/hitrace_scope.h" #include "ecmascript/js_function.h" -#include "ecmascript/record.h" #include "ecmascript/js_handle.h" #include "ecmascript/object_factory.h" +#include "ecmascript/record.h" #include "ecmascript/tagged_array.h" #include "ecmascript/tooling/interface/js_debugger_manager.h" #include "ecmascript/mem/c_containers.h" @@ -29,7 +30,7 @@ namespace panda::ecmascript::job { class PendingJob final : public Record { public: - static PendingJob *Cast(ObjectHeader *object) + static PendingJob *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsPendingJob()); return static_cast(object); @@ -37,26 +38,39 @@ public: static JSTaggedValue ExecutePendingJob(const JSHandle &pendingJob, JSThread *thread) { + EXECUTE_JOB_HITRACE(pendingJob); tooling::JsDebuggerManager *jsDebuggerManager = thread->GetEcmaVM()->GetJsDebuggerManager(); jsDebuggerManager->GetNotificationManager()->PendingJobEntryEvent(); JSHandle job(thread, pendingJob->GetJob()); ASSERT(job->IsCallable()); JSHandle argv(thread, pendingJob->GetArguments()); - const size_t argsLength = argv->GetLength(); + const int32_t argsLength = static_cast(argv->GetLength()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, job, undefined, undefined, argsLength); - info.SetCallArg(argsLength, argv); - return JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, job, undefined, undefined, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, argv); + return JSFunction::Call(info); } static constexpr size_t JOB_OFFSET = Record::SIZE; ACCESSORS(Job, JOB_OFFSET, ARGUMENT_OFFSET); - ACCESSORS(Arguments, ARGUMENT_OFFSET, SIZE); +#if defined(ENABLE_HITRACE) + ACCESSORS(Arguments, ARGUMENT_OFFSET, CHAINID_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(ChainId, uint64_t, CHAINID_OFFSET, SPANID_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(SpanId, uint64_t, SPANID_OFFSET, PARENTSPANID_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(ParentSpanId, uint64_t, PARENTSPANID_OFFSET, FLAGS_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(Flags, uint32_t, FLAGS_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_DUMP() + DECL_VISIT_OBJECT(JOB_OFFSET, CHAINID_OFFSET) +#else + ACCESSORS(Arguments, ARGUMENT_OFFSET, SIZE); DECL_VISIT_OBJECT(JOB_OFFSET, SIZE) +#endif + + DECL_DUMP() }; } // namespace panda::ecmascript::job #endif // ECMASCRIPT_JOBS_PENDING_JOB_H diff --git a/ecmascript/jobs/tests/micro_job_queue_test.cpp b/ecmascript/jobs/tests/micro_job_queue_test.cpp index c4ec66aeabf6f43c762ff9e633c35c7147c821e9..a7de13834d9b565d0c9a4eb3ad7d501f3dd32bca 100644 --- a/ecmascript/jobs/tests/micro_job_queue_test.cpp +++ b/ecmascript/jobs/tests/micro_job_queue_test.cpp @@ -14,6 +14,7 @@ */ #include "ecmascript/jobs/micro_job_queue.h" +#include "ecmascript/jobs/pending_job.h" #include "ecmascript/global_env.h" #include "ecmascript/js_promise.h" #include "ecmascript/tagged_queue.h" @@ -62,7 +63,7 @@ public: HWTEST_F_L0(MicroJobQueueTest, GetJobQueue) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - array_size_t capacity = 4; + uint32_t capacity = 4; JSHandle handleValue(thread, JSTaggedValue(123)); JSHandle handlePromiseQueue = factory->NewTaggedQueue(capacity); diff --git a/ecmascript/jobs/tests/pending_job_test.cpp b/ecmascript/jobs/tests/pending_job_test.cpp index 5bc5d71fa8b169c84381f60dade27a20c931df0b..4b64051b0e668df80e214e0dfd6c22123c8fab91 100644 --- a/ecmascript/jobs/tests/pending_job_test.cpp +++ b/ecmascript/jobs/tests/pending_job_test.cpp @@ -263,10 +263,10 @@ JSTaggedValue TestPromiseResolveThenableJob(EcmaRuntimeCallInfo *argv) JSHandle result = BuiltinsBase::GetCallArg(argv, 0); EXPECT_TRUE(result->IsJSFunction()); JSHandle undefined(argv->GetThread(), JSTaggedValue::Undefined()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(argv->GetThread(), result, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(44)); // 44 : 44 promise result - return JSFunction::Call(&info); + info->SetCallArg(JSTaggedValue(44)); // 44 : 44 promise result + return JSFunction::Call(info); } /** diff --git a/ecmascript/js_api_arraylist.cpp b/ecmascript/js_api_arraylist.cpp index 510c313798bac5336cec19e1bf8c548480ccffee..f59d3e70ae4f7dbd4cb6c4920156ba23abc8503e 100644 --- a/ecmascript/js_api_arraylist.cpp +++ b/ecmascript/js_api_arraylist.cpp @@ -237,15 +237,16 @@ JSTaggedValue JSAPIArrayList::ReplaceAllElements(JSThread *thread, const JSHandl uint32_t length = static_cast(arrayList->GetSize()); JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (uint32_t k = 0; k < length; k++) { kValue.Update(arrayList->Get(thread, k)); key.Update(JSTaggedValue(k)); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); arrayList->Set(thread, k, funcResult); @@ -310,15 +311,16 @@ JSTaggedValue JSAPIArrayList::ForEach(JSThread *thread, const JSHandle(arrayList->GetSize()); JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); - const size_t argsLength = 3; + const int32_t argsLength = 3; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (uint32_t k = 0; k < length; k++) { kValue.Update(arrayList->Get(thread, k)); key.Update(JSTaggedValue(k)); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(kValue.GetTaggedValue(), key.GetTaggedValue(), thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); if (static_cast(length) != arrayList->GetSize()) { length = static_cast(arrayList->GetSize()); diff --git a/ecmascript/js_api_arraylist.h b/ecmascript/js_api_arraylist.h index 25610621298b0a54a6d5191dc06ab02a5b974974..fe219dd52bb2deb534ae82b8eb8333c753f3639a 100644 --- a/ecmascript/js_api_arraylist.h +++ b/ecmascript/js_api_arraylist.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JS_APIARRAYLIST_H -#define ECMASCRIPT_JS_APIARRAYLIST_H +#ifndef ECMASCRIPT_JS_API_ARRAYLIST_H +#define ECMASCRIPT_JS_API_ARRAYLIST_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -27,7 +27,7 @@ namespace panda::ecmascript { class JSAPIArrayList : public JSObject { public: static constexpr uint32_t DEFAULT_CAPACITY_LENGTH = 10; - static JSAPIArrayList *Cast(ObjectHeader *object) + static JSAPIArrayList *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIArrayList()); return static_cast(object); @@ -95,4 +95,4 @@ private: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JS_APIARRAYLIST_H +#endif // ECMASCRIPT_JS_API_ARRAYLIST_H diff --git a/ecmascript/js_api_arraylist_iterator.h b/ecmascript/js_api_arraylist_iterator.h index 377ff00c27b16976d87bafcfe5dfd93053f7dc5d..90c5d62b6014639ab7e7037845cdaf981e78fdec 100644 --- a/ecmascript/js_api_arraylist_iterator.h +++ b/ecmascript/js_api_arraylist_iterator.h @@ -26,7 +26,7 @@ namespace panda::ecmascript { * */ class JSAPIArrayListIterator : public JSObject { public: - static JSAPIArrayListIterator *Cast(ObjectHeader *obj) + static JSAPIArrayListIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIArrayListIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_deque.h b/ecmascript/js_api_deque.h index ed56b1bea011a6e6e55847a23dab23dd444c4e6b..84e94b45eb7264018a64bb7daeb9de4f1a32010b 100644 --- a/ecmascript/js_api_deque.h +++ b/ecmascript/js_api_deque.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JSAPIDEQUE_H -#define ECMASCRIPT_JSAPIDEQUE_H +#ifndef ECMASCRIPT_JS_API_DEQUE_H +#define ECMASCRIPT_JS_API_DEQUE_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -23,7 +23,7 @@ namespace panda::ecmascript { class JSAPIDeque : public JSObject { public: static constexpr int DEFAULT_CAPACITY_LENGTH = 8; - static JSAPIDeque *Cast(ObjectHeader *object) + static JSAPIDeque *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIDeque()); return static_cast(object); @@ -77,4 +77,4 @@ private: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JSAPIDEQUE_H +#endif // ECMASCRIPT_JS_API_DEQUE_H diff --git a/ecmascript/js_api_deque_iterator.cpp b/ecmascript/js_api_deque_iterator.cpp index ab77f9179a70312be0324c4a4106ec981b3c581a..a4a6f0ffe28d66c69d62d4eef10571806bda7c76 100644 --- a/ecmascript/js_api_deque_iterator.cpp +++ b/ecmascript/js_api_deque_iterator.cpp @@ -44,7 +44,7 @@ JSTaggedValue JSAPIDequeIterator::Next(EcmaRuntimeCallInfo *argv) uint32_t index = iter->GetNextIndex(); JSHandle elements(thread, deque->GetElements()); - array_size_t capacity = elements->GetLength(); + uint32_t capacity = elements->GetLength(); uint32_t first = deque->GetFirst(); uint32_t last = deque->GetLast(); if (index == last) { diff --git a/ecmascript/js_api_deque_iterator.h b/ecmascript/js_api_deque_iterator.h index eee3639184c3e2f3ca9fd3bfd4221e6b7c07163f..43249062f912c61e818cc3bb2d054c2950876a65 100644 --- a/ecmascript/js_api_deque_iterator.h +++ b/ecmascript/js_api_deque_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPIDequeIterator : public JSObject { public: - static JSAPIDequeIterator *Cast(ObjectHeader *obj) + static JSAPIDequeIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIDequeIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_lightweightmap.cpp b/ecmascript/js_api_lightweightmap.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cf5799ec71f7103120a7df44fe4c13e38f82d0b2 --- /dev/null +++ b/ecmascript/js_api_lightweightmap.cpp @@ -0,0 +1,521 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_api_lightweightmap.h" +#include "ecmascript/js_array.h" +#include "ecmascript/js_function.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/js_object-inl.h" +#include "ecmascript/js_tagged_number.h" +#include "ecmascript/js_tagged_value.h" +#include "libpandabase/utils/bit_utils.h" +#include "object_factory.h" +#include "utils/bit_utils.h" + +namespace panda::ecmascript { +JSTaggedValue JSAPILightWeightMap::IncreaseCapacityTo(JSThread *thread, + const JSHandle &lightWeightMap, + int32_t index) +{ + int32_t num = lightWeightMap->GetSize(); + if (index < DEFAULT_CAPACITY_LENGTH || num >= index) { + return JSTaggedValue::False(); + } + JSHandle hashArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::HASH); + JSHandle keyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); + JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + JSHandle newHashArray = GrowCapacity(thread, hashArray, index); + JSHandle newKeyArray = GrowCapacity(thread, keyArray, index); + JSHandle newValueArray = GrowCapacity(thread, valueArray, index); + lightWeightMap->SetHashes(thread, newHashArray); + lightWeightMap->SetKeys(thread, newKeyArray); + lightWeightMap->SetValues(thread, newValueArray); + return JSTaggedValue::True(); +} + +void JSAPILightWeightMap::SetValue(const JSThread *thread, const JSHandle &lightWeightMap, + int32_t index, const JSHandle &value, AccossorsKind kind) +{ + JSHandle array = GetArrayByKind(thread, lightWeightMap, kind); + int32_t len = lightWeightMap->GetSize(); + JSHandle newArray = GrowCapacity(thread, array, len + 1); + while (len != index && len > 0) { + JSTaggedValue oldValue = newArray->Get(len - 1); + newArray->Set(thread, len, oldValue); + len--; + } + + newArray->Set(thread, index, value.GetTaggedValue()); + switch (kind) { + case AccossorsKind::HASH: + lightWeightMap->SetHashes(thread, newArray); + break; + case AccossorsKind::KEY: + lightWeightMap->SetKeys(thread, newArray); + break; + case AccossorsKind::VALUE: + lightWeightMap->SetValues(thread, newArray); + break; + default: + UNREACHABLE(); + } +} + +void JSAPILightWeightMap::RemoveValue(const JSThread *thread, const JSHandle &lightWeightMap, + uint32_t index, AccossorsKind kind) +{ + JSHandle array = GetArrayByKind(thread, lightWeightMap, kind); + uint32_t len = lightWeightMap->GetLength(); + uint32_t num = index; + ASSERT(num < len); + while (num < len - 1) { + array->Set(thread, num, array->Get(num + 1)); + num++; + } + switch (kind) { + case AccossorsKind::HASH: + lightWeightMap->SetHashes(thread, array); + break; + case AccossorsKind::KEY: + lightWeightMap->SetKeys(thread, array); + break; + case AccossorsKind::VALUE: + lightWeightMap->SetValues(thread, array); + break; + default: + break; + } +} + +void JSAPILightWeightMap::Set(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key, const JSHandle &value) +{ + int32_t hash = Hash(key.GetTaggedValue()); + JSHandle hashHandle(thread, JSTaggedValue(hash)); + int32_t length = lightWeightMap->GetSize(); + int32_t index = GetHashIndex(thread, lightWeightMap, hash, key.GetTaggedValue(), length); + if (GetIndexOfKey(thread, lightWeightMap, key) < 0) { + SetValue(thread, lightWeightMap, index, hashHandle, AccossorsKind::HASH); + SetValue(thread, lightWeightMap, index, key, AccossorsKind::KEY); + SetValue(thread, lightWeightMap, index, value, AccossorsKind::VALUE); + lightWeightMap->SetLength(length + 1); + return; + } + SetValue(thread, lightWeightMap, index, hashHandle, AccossorsKind::HASH); + SetValue(thread, lightWeightMap, index, key, AccossorsKind::KEY); + SetValue(thread, lightWeightMap, index, value, AccossorsKind::VALUE); +} + +JSTaggedValue JSAPILightWeightMap::Get(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key) +{ + int32_t index = GetIndexOfKey(thread, lightWeightMap, key); + if (index < 0) { + return JSTaggedValue::Undefined(); + } + JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + return valueArray->Get(index); +} + +JSTaggedValue JSAPILightWeightMap::HasAll(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &newLightWeightMap) +{ + int32_t length = newLightWeightMap->GetSize(); + int32_t len = lightWeightMap->GetSize(); + if (length > len) { + return JSTaggedValue::False(); + } + JSHandle oldHashArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::HASH); + JSHandle oldKeyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); + JSHandle oldValueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + JSHandle newKeyArray = GetArrayByKind(thread, newLightWeightMap, AccossorsKind::KEY); + JSHandle newValueArray = GetArrayByKind(thread, newLightWeightMap, AccossorsKind::VALUE); + JSTaggedValue dealKey = JSTaggedValue::Undefined(); + int32_t index = -1; + int32_t hash; + + for (int32_t num = 0; num < length; num++) { + dealKey = newKeyArray->Get(num); + hash = Hash(dealKey); + index = BinarySearchHashes(oldHashArray, hash, len); + if (index < 0 || index >= len) { + return JSTaggedValue::False(); + } + HashParams params { oldHashArray, oldKeyArray, &dealKey }; + index = AvoidHashCollision(params, index, len, hash); + if (!JSTaggedValue::SameValue(oldKeyArray->Get(index), dealKey) || + !JSTaggedValue::SameValue(oldValueArray->Get(index), newValueArray->Get(num))) { + // avoid Hash collision + return JSTaggedValue::False(); + } + } + return JSTaggedValue::True(); +} + +JSTaggedValue JSAPILightWeightMap::HasKey(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key) +{ + int32_t index = GetIndexOfKey(thread, lightWeightMap, key); + return index >= 0 ? JSTaggedValue::True() : JSTaggedValue::False(); +} + +JSTaggedValue JSAPILightWeightMap::HasValue(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &value) +{ + JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + int32_t length = lightWeightMap->GetSize(); + for (int32_t num = 0; num < length; num++) { + if (JSTaggedValue::SameValue(valueArray->Get(num), value.GetTaggedValue())) { + return JSTaggedValue::True(); + } + } + return JSTaggedValue::False(); +} + +int32_t JSAPILightWeightMap::GetIndexOfKey(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key) +{ + int32_t hash = Hash(key.GetTaggedValue()); + int32_t length = lightWeightMap->GetSize(); + JSHandle hashArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::HASH); + int32_t index = BinarySearchHashes(hashArray, hash, length); + if (index >= 0) { + // avoid Hash Collision + JSHandle keyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); + int32_t right = index; + while ((right < length) && (hashArray->Get(right).GetInt() == hash)) { + if (JSTaggedValue::SameValue(keyArray->Get(right), key.GetTaggedValue())) { + return right; + } + right++; + } + int32_t left = index - 1; + while ((left >= 0) && ((hashArray->Get(left).GetInt() == hash))) { + if (JSTaggedValue::SameValue(keyArray->Get(left), key.GetTaggedValue())) { + return left; + } + left--; + } + } + return -1; +} + +int32_t JSAPILightWeightMap::GetIndexOfValue(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &value) +{ + JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + int32_t length = lightWeightMap->GetSize(); + JSTaggedValue compValue = value.GetTaggedValue(); + for (int32_t i = 0; i < length; i++) { + if (valueArray->Get(i) == compValue) { + return i; + } + } + return -1; // not find, default return -1 +} + +JSTaggedValue JSAPILightWeightMap::GetKeyAt(JSThread *thread, const JSHandle &lightWeightMap, + int32_t index) +{ + int32_t length = lightWeightMap->GetSize(); + if (index < 0 || length <= index) { + THROW_RANGE_ERROR_AND_RETURN(thread, "index is not exits", JSTaggedValue::Exception()); + } + JSHandle keyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); + return keyArray->Get(index); +} + +JSTaggedValue JSAPILightWeightMap::GetValueAt(JSThread *thread, const JSHandle &lightWeightMap, + int32_t index) +{ + int32_t length = lightWeightMap->GetSize(); + if (index < 0 || length <= index) { + THROW_RANGE_ERROR_AND_RETURN(thread, "index is not exits", JSTaggedValue::Exception()); + } + JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + return valueArray->Get(index); +} + +void JSAPILightWeightMap::SetAll(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &needLightWeightMap) +{ + JSHandle needKeyArray = GetArrayByKind(thread, needLightWeightMap, AccossorsKind::KEY); + JSHandle needValueArray = GetArrayByKind(thread, needLightWeightMap, AccossorsKind::VALUE); + JSMutableHandle key(thread, JSTaggedValue::Undefined()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + int32_t length = needLightWeightMap->GetSize(); + for (int32_t num = 0; num < length; num++) { + key.Update(needKeyArray->Get(num)); + value.Update(needValueArray->Get(num)); + JSAPILightWeightMap::Set(thread, lightWeightMap, key, value); + } +} + +JSTaggedValue JSAPILightWeightMap::Remove(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key) +{ + int32_t hash = Hash(key.GetTaggedValue()); + int32_t length = lightWeightMap->GetSize(); + int32_t index = GetHashIndex(thread, lightWeightMap, hash, key.GetTaggedValue(), length); + if (index < 0 || index >= length) { + return JSTaggedValue::Undefined(); + } + JSTaggedValue value = JSTaggedValue::Undefined(); + JSHandle keyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); + JSHandle valueArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::VALUE); + for (int32_t i = 0; length > i; i++) { + if (keyArray->Get(i) == key.GetTaggedValue()) { + value = valueArray->Get(index); + RemoveValue(thread, lightWeightMap, index, AccossorsKind::HASH); + RemoveValue(thread, lightWeightMap, index, AccossorsKind::VALUE); + RemoveValue(thread, lightWeightMap, index, AccossorsKind::KEY); + lightWeightMap->SetLength(length - 1); + } + } + + return value; +} + +JSTaggedValue JSAPILightWeightMap::RemoveAt(JSThread *thread, + const JSHandle &lightWeightMap, int32_t index) +{ + int32_t length = lightWeightMap->GetSize(); + if (index < 0 || length <= index) { + return JSTaggedValue::False(); + } + RemoveValue(thread, lightWeightMap, index, AccossorsKind::HASH); + RemoveValue(thread, lightWeightMap, index, AccossorsKind::VALUE); + RemoveValue(thread, lightWeightMap, index, AccossorsKind::KEY); + lightWeightMap->SetLength(length - 1); + return JSTaggedValue::True(); +} + +JSTaggedValue JSAPILightWeightMap::IsEmpty() +{ + if (GetLength() == 0) { + return JSTaggedValue::True(); + } else { + return JSTaggedValue::False(); + } +} + +void JSAPILightWeightMap::Clear(JSThread *thread, const JSHandle &lightWeightMap) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle hashArray = JSHandle(factory->NewTaggedArray(DEFAULT_CAPACITY_LENGTH)); + JSHandle keyArray = JSHandle(factory->NewTaggedArray(DEFAULT_CAPACITY_LENGTH)); + JSHandle valueArray = JSHandle(factory->NewTaggedArray(DEFAULT_CAPACITY_LENGTH)); + lightWeightMap->SetHashes(thread, hashArray); + lightWeightMap->SetKeys(thread, keyArray); + lightWeightMap->SetValues(thread, valueArray); + lightWeightMap->SetLength(0); +} + +JSTaggedValue JSAPILightWeightMap::SetValueAt(JSThread *thread, const JSHandle &lightWeightMap, + int32_t index, const JSHandle &value) +{ + int32_t length = lightWeightMap->GetSize(); + if (index < 0 || length <= index) { + THROW_RANGE_ERROR_AND_RETURN(thread, "index is not exits", JSTaggedValue::False()); + } + SetValue(thread, lightWeightMap, index, value, AccossorsKind::VALUE); + return JSTaggedValue::True(); +} + +int32_t JSAPILightWeightMap::GetHashIndex(JSThread *thread, const JSHandle &lightWeightMap, + int32_t hash, const JSTaggedValue &key, int32_t size) +{ + JSHandle hashArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::HASH); + JSHandle keyArray = GetArrayByKind(thread, lightWeightMap, AccossorsKind::KEY); + int32_t index = BinarySearchHashes(hashArray, hash, size); + if (index < 0) { + index ^= HASH_REBELLION; + return index; + } + if ((index < size) && (JSTaggedValue::SameValue(keyArray->Get(index), key))) { + return index; + } + JSTaggedValue dealKey = key; + HashParams params { hashArray, keyArray, &dealKey }; + return AvoidHashCollision(params, index, size, hash); +} + +int32_t JSAPILightWeightMap::AvoidHashCollision(HashParams ¶ms, int32_t index, int32_t size, int32_t hash) +{ + int32_t right = index; + while ((right < size) && ((params.hashArray)->Get(right).GetInt() == hash)) { + if (JSTaggedValue::SameValue((params.keyArray)->Get(right), *(params.key))) { + return right; + } + right++; + } + int32_t left = index - 1; + while ((left >= 0) && ((params.hashArray)->Get(left).GetInt() == hash)) { + if (JSTaggedValue::SameValue((params.keyArray)->Get(left), *(params.key))) { + return left; + } + left--; + } + + int32_t res = (-right) ^ HASH_REBELLION; + return res; +} + +JSTaggedValue JSAPILightWeightMap::GetIteratorObj(JSThread *thread, const JSHandle &obj, + IterationKind type) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle iter(factory->NewJSAPILightWeightMapIterator(obj, type)); + + return iter.GetTaggedValue(); +} + +JSTaggedValue JSAPILightWeightMap::ToString(JSThread *thread, const JSHandle &lightWeightMap) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + std::u16string sepStr = std::wstring_convert, char16_t> {}.from_bytes(","); + std::u16string colonStr = std::wstring_convert, char16_t> {}.from_bytes(":"); + uint32_t length = lightWeightMap->GetLength(); + std::u16string concatStr; + std::u16string concatStrNew; + JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); + JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); + + for (uint32_t k = 0; k < length; k++) { + std::u16string valueStr; + valueHandle.Update(lightWeightMap->GetValueAt(thread, lightWeightMap, k)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + if (!valueHandle->IsUndefined() && !valueHandle->IsNull()) { + JSHandle valueStringHandle = JSTaggedValue::ToString(thread, valueHandle); + uint32_t valueLen = valueStringHandle->GetLength(); + if (valueStringHandle->IsUtf16()) { + valueStr = base::StringHelper::Utf16ToU16String(valueStringHandle->GetDataUtf16(), valueLen); + } else { + valueStr = base::StringHelper::Utf8ToU16String(valueStringHandle->GetDataUtf8(), valueLen); + } + } + + std::u16string keyStr; + keyHandle.Update(lightWeightMap->GetKeyAt(thread, lightWeightMap, k)); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + if (!keyHandle->IsUndefined() && !keyHandle->IsNull()) { + JSHandle keyStringHandle = JSTaggedValue::ToString(thread, keyHandle); + uint32_t keyLen = keyStringHandle->GetLength(); + if (keyStringHandle->IsUtf16()) { + keyStr = base::StringHelper::Utf16ToU16String(keyStringHandle->GetDataUtf16(), keyLen); + } else { + keyStr = base::StringHelper::Utf8ToU16String(keyStringHandle->GetDataUtf8(), keyLen); + } + } + + std::u16string nextStr = base::StringHelper::Append(keyStr, colonStr); + nextStr = base::StringHelper::Append(nextStr, valueStr); + + if (k > 0) { + concatStrNew = base::StringHelper::Append(concatStr, sepStr); + concatStr = base::StringHelper::Append(concatStrNew, nextStr); + continue; + } + concatStr = base::StringHelper::Append(concatStr, nextStr); + } + + char16_t *char16tData = concatStr.data(); + auto *uint16tData = reinterpret_cast(char16tData); + uint32_t u16strSize = concatStr.size(); + return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); +} + +JSHandle JSAPILightWeightMap::GrowCapacity(const JSThread *thread, const JSHandle &oldArray, + uint32_t needCapacity) +{ + uint32_t oldLength = oldArray->GetLength(); + if (needCapacity <= oldLength) { + return oldArray; + } + uint32_t newCapacity = ComputeCapacity(needCapacity); + JSHandle newArray = thread->GetEcmaVM()->GetFactory()->CopyArray(oldArray, oldLength, newCapacity); + return newArray; +} + +JSHandle JSAPILightWeightMap::GetArrayByKind(const JSThread *thread, + const JSHandle &lightWeightMap, + AccossorsKind kind) +{ + JSHandle array; + switch (kind) { + case AccossorsKind::HASH: + array = JSHandle(thread, lightWeightMap->GetHashes()); + break; + case AccossorsKind::KEY: + array = JSHandle(thread, lightWeightMap->GetKeys()); + break; + case AccossorsKind::VALUE: + array = JSHandle(thread, lightWeightMap->GetValues()); + break; + default: + UNREACHABLE(); + } + return array; +} + +int32_t JSAPILightWeightMap::Hash(JSTaggedValue key) +{ + if (key.IsDouble() && key.GetDouble() == 0.0) { + key = JSTaggedValue(0); + } + if (key.IsSymbol()) { + auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); + return symbolString->GetHashField(); + } + if (key.IsString()) { + auto keyString = EcmaString::Cast(key.GetTaggedObject()); + return keyString->GetHashcode(); + } + if (key.IsECMAObject()) { + uint32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(); + if (hash == 0) { + uint64_t keyValue = key.GetRawData(); + hash = GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); + ECMAObject::Cast(key.GetTaggedObject())->SetHash(hash); + } + return hash; + } + if (key.IsInt()) { + int32_t hash = key.GetInt(); + return hash; + } + uint64_t keyValue = key.GetRawData(); + return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); +} + +int32_t JSAPILightWeightMap::BinarySearchHashes(JSHandle &array, int32_t hash, int32_t size) +{ + int32_t low = 0; + int32_t high = size - 1; + while (low <= high) { + uint32_t mid = static_cast(low + high) >> 1U; + int32_t midHash = array->Get(mid).GetInt(); + if (midHash < hash) { + low = static_cast(mid) + 1; + } else { + if (midHash == hash) { + return mid; + } + high = static_cast(mid) - 1; + } + } + return -(low + 1); +} +} // namespace panda::ecmascript diff --git a/ecmascript/js_api_lightweightmap.h b/ecmascript/js_api_lightweightmap.h new file mode 100644 index 0000000000000000000000000000000000000000..1134c0dbbe6d49a0043171c7ebdb67a15b138557 --- /dev/null +++ b/ecmascript/js_api_lightweightmap.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_JS_API_LIGHTWEIGHTMAP_H +#define ECMASCRIPT_JS_API_LIGHTWEIGHTMAP_H + +#include "js_object.h" +#include "js_tagged_value-inl.h" + +namespace panda::ecmascript { +enum class AccossorsKind { HASH = 0, KEY, VALUE }; +struct HashParams { + JSHandle hashArray; + JSHandle keyArray; + JSTaggedValue *key; +}; +class JSAPILightWeightMap : public JSObject { +public: + static constexpr int DEFAULT_CAPACITY_LENGTH = 8; + static constexpr int32_t HASH_REBELLION = 0xFFFFFFFF; + static JSAPILightWeightMap *Cast(TaggedObject *object) + { + ASSERT(JSTaggedValue(object).IsJSAPILightWeightMap()); + return static_cast(object); + } + static void Set(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key, const JSHandle &value); + static JSTaggedValue Get(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key); + static JSTaggedValue HasAll(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &newLightWeightMap); + static JSTaggedValue HasKey(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key); + static JSTaggedValue HasValue(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &value); + static int32_t GetIndexOfKey(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key); + static int32_t GetIndexOfValue(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &value); + static JSTaggedValue GetKeyAt(JSThread *thread, const JSHandle &lightWeightMap, int32_t index); + static void SetAll(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &newLightWeightMap); + static JSTaggedValue Remove(JSThread *thread, const JSHandle &lightWeightMap, + const JSHandle &key); + static JSTaggedValue RemoveAt(JSThread *thread, const JSHandle &lightWeightMap, int32_t index); + static void Clear(JSThread *thread, const JSHandle &lightWeightMap); + static JSTaggedValue SetValueAt(JSThread *thread, const JSHandle &lightWeightMap, + int32_t index, const JSHandle &value); + static JSTaggedValue IncreaseCapacityTo(JSThread *thread, const JSHandle &lightWeightMap, + int32_t index); + static JSTaggedValue ToString(JSThread *thread, const JSHandle &lightWeightMap); + static JSTaggedValue GetValueAt(JSThread *thread, const JSHandle &lightWeightMap, + int32_t index); + static JSTaggedValue GetIteratorObj(JSThread *thread, const JSHandle &obj, IterationKind type); + static bool GetOwnProperty(JSThread *thread, const JSHandle &map, + const JSHandle &key, + PropertyDescriptor &desc); + JSTaggedValue IsEmpty(); + inline int32_t GetSize() const + { + return static_cast(GetLength()); + } + + static constexpr size_t LWP_HASHES_OFFSET = JSObject::SIZE; + ACCESSORS(Hashes, LWP_HASHES_OFFSET, LWP_KEYS_OFFSET); + ACCESSORS(Keys, LWP_KEYS_OFFSET, LWP_VALUES_OFFSET); + ACCESSORS(Values, LWP_VALUES_OFFSET, LWP_LENGTH_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LWP_LENGTH_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, LWP_HASHES_OFFSET, LWP_LENGTH_OFFSET) + DECL_DUMP() + +private: + static inline uint32_t ComputeCapacity(uint32_t oldCapacity) + { + uint32_t newCapacity = oldCapacity + (oldCapacity >> 1U); + return newCapacity > DEFAULT_CAPACITY_LENGTH ? newCapacity : DEFAULT_CAPACITY_LENGTH; + }; + static JSHandle GrowCapacity(const JSThread *thread, const JSHandle &oldArray, + uint32_t needCapacity); + static void RemoveValue(const JSThread *thread, const JSHandle &lightWeightMap, uint32_t index, + AccossorsKind kind); + static void SetValue(const JSThread *thread, const JSHandle &lightWeightMap, + int32_t index, const JSHandle &value, AccossorsKind kind); + static int32_t Hash(JSTaggedValue key); + static int32_t BinarySearchHashes(JSHandle &array, int32_t hash, int32_t size); + static JSHandle GetArrayByKind(const JSThread *thread, + const JSHandle &lightWeightMap, + AccossorsKind kind); + static int32_t GetHashIndex(JSThread *thread, const JSHandle &lightWeightMap, int32_t hash, + const JSTaggedValue &value, int32_t size); + static int32_t AvoidHashCollision(HashParams ¶ms, int32_t index, int32_t size, int32_t hash); +}; +} // namespace panda::ecmascript + +#endif // ECMASCRIPT_JS_API_LIGHTWEIGHTMAP_H diff --git a/ecmascript/js_api_lightweightmap_iterator.cpp b/ecmascript/js_api_lightweightmap_iterator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2b5fe41a5ceeb851bbf5cdde70c201f640d4023c --- /dev/null +++ b/ecmascript/js_api_lightweightmap_iterator.cpp @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_api_lightweightmap_iterator.h" +#include "builtins/builtins_errors.h" +#include "ecmascript/base/typed_array_helper-inl.h" +#include "ecmascript/base/typed_array_helper.h" +#include "global_env.h" +#include "js_api_lightweightmap.h" +#include "js_array.h" +#include "object_factory.h" + +namespace panda::ecmascript { +using BuiltinsBase = base::BuiltinsBase; +JSTaggedValue JSAPILightWeightMapIterator::Next(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv != nullptr); + JSThread *thread = argv->GetThread(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle input(BuiltinsBase::GetThis(argv)); + if (!input->IsJSAPILightWeightMapIterator()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an linkedList iterator", JSTaggedValue::Exception()); + } + JSHandle iter(input); + JSHandle oldlightWeightMap(thread, iter->GetIteratedLightWeightMap()); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); + JSHandle lightWeightMap(oldlightWeightMap); + IterationKind itemKind = IterationKind(iter->GetIterationKind()); + if (oldlightWeightMap->IsUndefined()) { + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); + } + int32_t index = iter->GetNextIndex(); + int32_t length = lightWeightMap->GetSize(); + if (index >= length) { + iter->SetIteratedLightWeightMap(thread, undefinedHandle); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); + } + iter->SetNextIndex(index + 1); + + JSHandle key(thread, lightWeightMap->GetKeyAt(thread, lightWeightMap, index)); + if (itemKind == IterationKind::KEY) { + return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); + } + JSHandle value(thread, lightWeightMap->Get(thread, lightWeightMap, key)); + if (itemKind == IterationKind::VALUE) { + return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); + } + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle array = factory->NewTaggedArray(2); // 2 means the length of array + array->Set(thread, 0, key); + array->Set(thread, 1, value); + JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); + + return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); +} + +JSHandle JSAPILightWeightMapIterator::CreateLightWeightMapIterator(JSThread *thread, + const JSHandle &obj, + IterationKind kind) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + if (!obj->IsJSAPILightWeightMap()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not JSAPILightWeightMap", + thread->GlobalConstants()->GetHandledUndefined()); + } + JSHandle iter(factory->NewJSAPILightWeightMapIterator(JSHandle(obj), kind)); + return iter; +} +} // namespace panda::ecmascript diff --git a/ecmascript/js_api_lightweightmap_iterator.h b/ecmascript/js_api_lightweightmap_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..e9d551249c7637a8b9587ddef3b7bb7ba343fba9 --- /dev/null +++ b/ecmascript/js_api_lightweightmap_iterator.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_JS_API_LIGHT_WEIGHT_MAP_ITERATOR_H +#define ECMASCRIPT_JS_API_LIGHT_WEIGHT_MAP_ITERATOR_H + +#include "js_iterator.h" +#include "js_object.h" + +namespace panda::ecmascript { +class JSAPILightWeightMapIterator : public JSObject { +public: + static JSAPILightWeightMapIterator *Cast(TaggedObject *obj) + { + ASSERT(JSTaggedValue(obj).IsJSAPILightWeightMapIterator()); + return static_cast(obj); + } + static JSHandle CreateLightWeightMapIterator(JSThread *thread, + const JSHandle &obj, + IterationKind kind); + static JSTaggedValue Next(EcmaRuntimeCallInfo *argv); + + static constexpr size_t ITERATED_LIGHT_WEIGHT_MAP_OFFSET = JSObject::SIZE; + ACCESSORS(IteratedLightWeightMap, ITERATED_LIGHT_WEIGHT_MAP_OFFSET, NEXT_INDEX_OFFSET) + ACCESSORS_PRIMITIVE_FIELD(NextIndex, int32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t ITERATION_KIND_BITS = 2; + FIRST_BIT_FIELD(BitField, IterationKind, IterationKind, ITERATION_KIND_BITS) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_LIGHT_WEIGHT_MAP_OFFSET, NEXT_INDEX_OFFSET) + + DECL_DUMP() +}; +} // namespace panda::ecmascript + +#endif // ECMASCRIPT_JS_LinkedList_ITERATOR_H \ No newline at end of file diff --git a/ecmascript/js_api_lightweightset.cpp b/ecmascript/js_api_lightweightset.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3eeeb839a87ede7fa40ff11799c995cac12ccc0b --- /dev/null +++ b/ecmascript/js_api_lightweightset.cpp @@ -0,0 +1,474 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_api_lightweightset.h" +#include "ecmascript/interpreter/interpreter.h" +#include "ecmascript/js_array.h" +#include "ecmascript/js_function.h" +#include "ecmascript/js_tagged_value.h" +#include "ecmascript/object_factory.h" +#include "js_api_lightweightset_iterator.h" + +namespace panda::ecmascript { +bool JSAPILightWeightSet::Add(JSThread *thread, const JSHandle &obj, + const JSHandle &value) +{ + uint32_t hashCode = obj->Hash(value.GetTaggedValue()); + JSHandle hashArray(thread, obj->GetHashes()); + JSHandle valueArray(thread, obj->GetValues()); + int32_t size = static_cast(obj->GetLength()); + int32_t index = obj->GetHashIndex(value, size); + if (index < 0) { + index ^= JSAPILightWeightSet::HASH_REBELLION; + } + if (index < size) { + obj->AdjustArray(thread, hashArray, index, size, true); + obj->AdjustArray(thread, valueArray, index, size, true); + } + uint32_t capacity = hashArray->GetLength(); + if (size + 1 >= static_cast(capacity)) { + // need expanding + uint32_t newCapacity = capacity << 1U; + hashArray = thread->GetEcmaVM()->GetFactory()->CopyArray(hashArray, capacity, newCapacity); + valueArray = thread->GetEcmaVM()->GetFactory()->CopyArray(valueArray, capacity, newCapacity); + obj->SetHashes(thread, hashArray); + obj->SetValues(thread, valueArray); + } + hashArray->Set(thread, index, JSTaggedValue(hashCode)); + valueArray->Set(thread, index, value.GetTaggedValue()); + size++; + obj->SetLength(size); + return true; +} + +JSHandle JSAPILightWeightSet::GrowCapacity(const JSThread *thread, + const JSHandle &obj, uint32_t capacity) +{ + JSHandle oldElements(thread, obj->GetElements()); + uint32_t oldLength = oldElements->GetLength(); + if (capacity < oldLength) { + return oldElements; + } + uint32_t newCapacity = ComputeCapacity(capacity); + JSHandle newElements = + thread->GetEcmaVM()->GetFactory()->CopyArray(oldElements, oldLength, newCapacity); + obj->SetElements(thread, newElements); + return newElements; +} + +JSTaggedValue JSAPILightWeightSet::Get(const uint32_t index) +{ + TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + return valueArray->Get(index); +} + +JSHandle JSAPILightWeightSet::CreateSlot(const JSThread *thread, const uint32_t capacity) +{ + ASSERT_PRINT(capacity > 0, "size must be a non-negative integer"); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle taggedArray = factory->NewTaggedArray(capacity); + for (uint32_t i = 0; i < capacity; i++) { + taggedArray->Set(thread, i, JSTaggedValue::Hole()); + } + return taggedArray; +} + +int32_t JSAPILightWeightSet::GetHashIndex(const JSHandle &value, int32_t size) +{ + uint32_t hashCode = Hash(value.GetTaggedValue()); + int32_t index = BinarySearchHashes(hashCode, size); + if (index < 0) { + return index; + } + TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + if (index < size && (JSTaggedValue::SameValue(valueArray->Get(index), value.GetTaggedValue()))) { + return index; + } + TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); + int32_t right = index; + while (right < size && (hashArray->Get(right).GetNumber() == hashCode)) { + if (JSTaggedValue::SameValue(valueArray->Get(right), value.GetTaggedValue())) { + return right; + } + right++; + } + int32_t left = index - 1; + while (left >= 0 && ((hashArray->Get(left).GetNumber() == hashCode))) { + if (JSTaggedValue::SameValue(valueArray->Get(left), value.GetTaggedValue())) { + return left; + } + left--; + } + return -right; +} + +int32_t JSAPILightWeightSet::BinarySearchHashes(uint32_t hash, int32_t size) +{ + int32_t low = 0; + int32_t high = size - 1; + TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); + while (low <= high) { + uint32_t mid = static_cast(low + high) >> 1U; + uint32_t midVal = (uint32_t)(hashArray->Get(mid).GetNumber()); + if (midVal < hash) { + low = mid + 1; + } else { + if (midVal <= hash) { + return mid; + } + high = mid - 1; + } + } + return -(low + 1); +} + +bool JSAPILightWeightSet::AddAll(JSThread *thread, const JSHandle &obj, + const JSHandle &value) +{ + bool changed = false; + JSHandle srcLightWeightSet = JSHandle::Cast(value); + uint32_t srcSize = srcLightWeightSet->GetSize(); + uint32_t size = obj->GetSize(); + obj->EnsureCapacity(thread, obj, size + srcSize); + JSMutableHandle element(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < srcSize; i++) { + element.Update(srcLightWeightSet->GetValueAt(i)); + changed = JSAPILightWeightSet::Add(thread, obj, element); + } + return changed; +} + +void JSAPILightWeightSet::EnsureCapacity(const JSThread *thread, const JSHandle &obj, + uint32_t minimumCapacity) +{ + TaggedArray *hashes = TaggedArray::Cast(obj->GetValues().GetTaggedObject()); + uint32_t capacity = hashes->GetLength(); + uint32_t newCapacity = capacity; + if (capacity > minimumCapacity) { + return; + } + // adjust + while (newCapacity <= minimumCapacity) { + newCapacity = newCapacity << 1U; + } + obj->SizeCopy(thread, obj, capacity, newCapacity); +} + +void JSAPILightWeightSet::SizeCopy(const JSThread *thread, const JSHandle &obj, + uint32_t capacity, uint32_t newCapacity) +{ + JSHandle hashArray(thread, obj->GetHashes()); + JSHandle valueArray(thread, obj->GetValues()); + hashArray = thread->GetEcmaVM()->GetFactory()->CopyArray(hashArray, capacity, newCapacity); + valueArray = thread->GetEcmaVM()->GetFactory()->CopyArray(valueArray, capacity, newCapacity); + + obj->SetValues(thread, hashArray); + obj->SetHashes(thread, valueArray); +} + +bool JSAPILightWeightSet::IsEmpty() +{ + return GetLength() == 0; +} + +JSTaggedValue JSAPILightWeightSet::GetValueAt(int32_t index) +{ + int32_t size = static_cast(GetLength()); + if (index < 0 || index >= size) { + return JSTaggedValue::Undefined(); + } + TaggedArray *values = TaggedArray::Cast(GetValues().GetTaggedObject()); + return values->Get(index); +} + +JSTaggedValue JSAPILightWeightSet::GetHashAt(int32_t index) +{ + int32_t size = static_cast(GetLength()); + if (index < 0 || index >= size) { + return JSTaggedValue::Undefined(); + } + TaggedArray *values = TaggedArray::Cast(GetHashes().GetTaggedObject()); + return values->Get(index); +} + +bool JSAPILightWeightSet::HasAll(const JSHandle &value) +{ + bool result = false; + uint32_t relocate = 0; + JSAPILightWeightSet *lightweightSet = JSAPILightWeightSet::Cast(value.GetTaggedValue().GetTaggedObject()); + uint32_t size = GetLength(); + uint32_t destSize = lightweightSet->GetLength(); + TaggedArray *hashes = TaggedArray::Cast(GetHashes().GetTaggedObject()); + TaggedArray *destHashes = TaggedArray::Cast(lightweightSet->GetHashes().GetTaggedObject()); + if (destSize > size) { + return result; + } + for (uint32_t i = 0; i < destSize; i++) { + uint32_t destHashCode = destHashes->Get(i).GetNumber(); + result = false; + for (uint32_t j = relocate; j < size; j++) { + uint32_t hashCode = hashes->Get(j).GetNumber(); + if (destHashCode == hashCode) { + result = true; + relocate = j + 1; + break; + } + } + if (!result) { + break; + } + } + return result; +} + +bool JSAPILightWeightSet::Has(const JSHandle &value) +{ + uint32_t size = GetLength(); + int32_t index = GetHashIndex(value, size); + if (index < 0) { + return false; + } + return true; +} + +bool JSAPILightWeightSet::HasHash(const JSHandle &hashCode) +{ + uint32_t size = GetLength(); + int32_t index = BinarySearchHashes(hashCode.GetTaggedValue().GetNumber(), size); + if (index < 0) { + return false; + } + return true; +} + +bool JSAPILightWeightSet::Equal(JSThread *thread, const JSHandle &obj, + const JSHandle &value) +{ + bool result = false; + JSHandle destHashes(thread, obj->GetHashes()); + uint32_t destSize = obj->GetLength(); + uint32_t srcSize; + JSMutableHandle srcHashes(thread, obj->GetHashes()); + if (value.GetTaggedValue().IsJSAPILightWeightSet()) { + JSAPILightWeightSet *srcLightWeightSet = JSAPILightWeightSet::Cast(value.GetTaggedValue().GetTaggedObject()); + srcSize = srcLightWeightSet->GetLength(); + if (srcSize == 0 || destSize == 0) { + return false; + } + srcHashes.Update(srcLightWeightSet->GetHashes()); + } + if (value.GetTaggedValue().IsJSArray()) { + srcHashes.Update(JSArray::ToTaggedArray(thread, value)); + srcSize = srcHashes->GetLength(); + if (srcSize == 0 || destSize == 0) { + return false; + } + } + if (srcSize != destSize) { + return false; + } + for (uint32_t i = 0; i < srcSize; i++) { + uint32_t destHashCode = destHashes->Get(i).GetNumber(); + uint32_t srcHashCode = srcHashes->Get(i).GetNumber(); + if (srcHashCode != destHashCode) { + result = false; + break; + } + result = true; + } + return result; +} + +void JSAPILightWeightSet::IncreaseCapacityTo(JSThread *thread, const JSHandle &obj, + int32_t minCapacity) +{ + uint32_t capacity = TaggedArray::Cast(obj->GetValues().GetTaggedObject())->GetLength(); + int32_t intCapacity = static_cast(capacity); + if (minCapacity <= 0 || intCapacity >= minCapacity) { + THROW_TYPE_ERROR(thread, "the index is not integer"); + } + obj->SizeCopy(thread, obj, intCapacity, minCapacity); +} + +JSHandle JSAPILightWeightSet::GetIteratorObj(JSThread *thread, const + JSHandle &obj, IterationKind kind) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle iter = + JSHandle::Cast(factory->NewJSAPILightWeightSetIterator(obj, kind)); + return iter; +} + +JSTaggedValue JSAPILightWeightSet::ForEach(JSThread *thread, const JSHandle &thisHandle, + const JSHandle &callbackFn, + const JSHandle &thisArg) +{ + JSHandle lightweightset = JSHandle::Cast(thisHandle); + uint32_t length = lightweightset->GetSize(); + JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); + for (uint32_t k = 0; k < length; k++) { + JSTaggedValue kValue = lightweightset->GetValueAt(k); + JSTaggedValue kHash = lightweightset->GetHashAt(k); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, 3); // 3:three args + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(kValue, kHash, thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); + } + return JSTaggedValue::Undefined(); +} + +int32_t JSAPILightWeightSet::GetIndexOf(JSHandle &value) +{ + uint32_t size = GetLength(); + int32_t index = GetHashIndex(value, size); + return index; +} + +JSTaggedValue JSAPILightWeightSet::Remove(JSThread *thread, JSHandle &value) +{ + uint32_t size = GetLength(); + TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + int32_t index = GetHashIndex(value, size); + if (index < 0) { + return JSTaggedValue::Undefined(); + } + JSTaggedValue result = valueArray->Get(index); + bool success = RemoveAt(thread, index); + if (!success) { + result = JSTaggedValue::Undefined(); + } + return result; +} + +bool JSAPILightWeightSet::RemoveAt(JSThread *thread, int32_t index) +{ + int32_t size = static_cast(GetLength()); + if (index < 0 || index >= size) { + return false; + } + JSHandle valueArray(thread, GetValues()); + JSHandle hashArray(thread, GetHashes()); + AdjustArray(thread, hashArray, index + 1, index, false); + AdjustArray(thread, valueArray, index + 1, index, false); + size--; + SetLength(size); + return true; +} + +void JSAPILightWeightSet::AdjustArray(JSThread *thread, JSHandle srcArray, uint32_t fromIndex, + uint32_t toIndex, bool direction) +{ + uint32_t size = GetLength(); + uint32_t idx = size - 1; + if (direction) { + while (fromIndex < toIndex) { + JSTaggedValue value = srcArray->Get(idx); + srcArray->Set(thread, idx + 1, value); + idx--; + fromIndex++; + } + } else { + uint32_t moveSize = size - fromIndex; + for (uint32_t i = 0; i < moveSize; i++) { + if ((fromIndex + i) < size) { + JSTaggedValue value = srcArray->Get(fromIndex + i); + srcArray->Set(thread, toIndex + i, value); + } else { + srcArray->Set(thread, toIndex + i, JSTaggedValue::Hole()); + } + } + } +} + +JSTaggedValue JSAPILightWeightSet::ToString(JSThread *thread, const JSHandle &obj) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + std::u16string sepStr = std::wstring_convert, char16_t> {}.from_bytes(","); + + uint32_t length = obj->GetSize(); + JSHandle valueArray(thread, obj->GetValues()); + std::u16string concatStr; + std::u16string concatStrNew; + JSMutableHandle values(thread, JSTaggedValue::Undefined()); + for (uint32_t k = 0; k < length; k++) { + std::u16string nextStr; + values.Update(valueArray->Get(k)); + if (!values->IsUndefined() && !values->IsNull()) { + JSHandle nextStringHandle = JSTaggedValue::ToString(thread, values); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + uint32_t nextLen = nextStringHandle->GetLength(); + if (nextStringHandle->IsUtf16()) { + nextStr = base::StringHelper::Utf16ToU16String(nextStringHandle->GetDataUtf16(), nextLen); + } else { + nextStr = base::StringHelper::Utf8ToU16String(nextStringHandle->GetDataUtf8(), nextLen); + } + } + if (k > 0) { + concatStrNew = base::StringHelper::Append(concatStr, sepStr); + concatStr = base::StringHelper::Append(concatStrNew, nextStr); + continue; + } + concatStr = base::StringHelper::Append(concatStr, nextStr); + } + char16_t *char16tData = concatStr.data(); + auto *uint16tData = reinterpret_cast(char16tData); + int32_t u16strSize = concatStr.size(); + return factory->NewFromUtf16Literal(uint16tData, u16strSize).GetTaggedValue(); +} + +void JSAPILightWeightSet::Clear(JSThread *thread) +{ + TaggedArray *hashArray = TaggedArray::Cast(GetHashes().GetTaggedObject()); + TaggedArray *valueArray = TaggedArray::Cast(GetValues().GetTaggedObject()); + uint32_t size = GetLength(); + for (uint32_t index = 0; index < size; index++) { + hashArray->Set(thread, index, JSTaggedValue::Hole()); + valueArray->Set(thread, index, JSTaggedValue::Hole()); + } + SetLength(0); +} + +uint32_t JSAPILightWeightSet::Hash(JSTaggedValue key) +{ + if (key.IsDouble() && key.GetDouble() == 0.0) { + key = JSTaggedValue(0); + } + if (key.IsSymbol()) { + auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); + return symbolString->GetHashField(); + } + if (key.IsString()) { + auto keyString = EcmaString::Cast(key.GetTaggedObject()); + return keyString->GetHashcode(); + } + if (key.IsECMAObject()) { + uint32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(); + if (hash == 0) { + uint64_t keyValue = key.GetRawData(); + hash = GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); + ECMAObject::Cast(key.GetTaggedObject())->SetHash(hash); + } + return hash; + } + if (key.IsInt()) { + uint32_t hash = key.GetInt(); + return hash; + } + uint64_t keyValue = key.GetRawData(); + return GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t)); +} +} // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/js_api_lightweightset.h b/ecmascript/js_api_lightweightset.h new file mode 100644 index 0000000000000000000000000000000000000000..6fa6ab52cc7f001c638281b9aa82d371b311d4d6 --- /dev/null +++ b/ecmascript/js_api_lightweightset.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_JS_API_LIGHTWEIGHTSET_H +#define ECMASCRIPT_JS_API_LIGHTWEIGHTSET_H + +#include "js_object.h" +#include "js_tagged_value-inl.h" + +namespace panda::ecmascript { +class JSAPILightWeightSet : public JSObject { +public: + static constexpr int DEFAULT_CAPACITY_LENGTH = 8; + static constexpr int32_t HASH_REBELLION = 0xFFFFFFFF; + static JSAPILightWeightSet *Cast(TaggedObject *object) + { + ASSERT(JSTaggedValue(object).IsJSAPILightWeightSet()); + return static_cast(object); + } + static bool Add(JSThread *thread, const JSHandle &obj, const JSHandle &value); + static JSHandle CreateSlot(const JSThread *thread, const uint32_t capacity); + static void EnsureCapacity(const JSThread *thread, const JSHandle &obj, + uint32_t minimumCapacity); + static void SizeCopy(const JSThread *thread, const JSHandle &obj, uint32_t capacity, + uint32_t newCapacity); + static bool AddAll(JSThread *thread, const JSHandle &obj, + const JSHandle &value); + static bool Equal(JSThread *thread, const JSHandle &obj, + const JSHandle &value); + static void IncreaseCapacityTo(JSThread *thread, const JSHandle &obj, int32_t minCapacity); + static JSTaggedValue ToString(JSThread *thread, const JSHandle &obj); + static JSTaggedValue ForEach(JSThread *thread, const JSHandle &thisHandle, + const JSHandle &callbackFn, const JSHandle &thisArg); + static JSHandle GetIteratorObj(JSThread *thread, const JSHandle &obj, + IterationKind kind); + void AdjustArray(JSThread *thread, JSHandle srcArray, uint32_t fromIndex, uint32_t toIndex, + bool direction); + void Clear(JSThread *thread); + JSTaggedValue Get(const uint32_t index); + JSTaggedValue GetHashAt(int32_t index); + JSTaggedValue GetValueAt(int32_t index); + JSTaggedValue Remove(JSThread *thread, JSHandle &value); + bool Has(const JSHandle &value); + bool HasHash(const JSHandle &hashCode); + bool HasAll(const JSHandle &value); + bool RemoveAt(JSThread *thread, int32_t index); + bool IsEmpty(); + int32_t GetIndexOf(JSHandle &value); + int32_t BinarySearchHashes(uint32_t hash, int32_t size); + int32_t GetHashIndex(const JSHandle &value, int32_t size); + uint32_t Hash(JSTaggedValue key); + inline uint32_t GetSize() const + { + return GetLength(); + } + static constexpr size_t HASHES_OFFSET = JSObject::SIZE; + ACCESSORS(Hashes, HASHES_OFFSET, VALUES_OFFSET); + ACCESSORS(Values, VALUES_OFFSET, LENGTH_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, HASHES_OFFSET, LENGTH_OFFSET) + DECL_DUMP() +private: + inline static uint32_t ComputeCapacity(uint32_t oldCapacity) + { + uint32_t newCapacity = oldCapacity + (oldCapacity >> 1U); + return newCapacity > DEFAULT_CAPACITY_LENGTH ? newCapacity : DEFAULT_CAPACITY_LENGTH; + } + static JSHandle GrowCapacity(const JSThread *thread, const JSHandle &obj, + uint32_t capacity); +}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_JS_API_LIGHTWEIGHTSET_H \ No newline at end of file diff --git a/ecmascript/js_api_lightweightset_iterator.cpp b/ecmascript/js_api_lightweightset_iterator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6324bf974bacc540bee8234ef715bb50ef93a10a --- /dev/null +++ b/ecmascript/js_api_lightweightset_iterator.cpp @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "js_api_lightweightset_iterator.h" +#include "builtins/builtins_errors.h" +#include "ecmascript/base/typed_array_helper-inl.h" +#include "ecmascript/base/typed_array_helper.h" +#include "global_env.h" +#include "js_api_lightweightset.h" +#include "js_array.h" +#include "object_factory.h" + +namespace panda::ecmascript { +using BuiltinsBase = base::BuiltinsBase; +JSTaggedValue JSAPILightWeightSetIterator::Next(EcmaRuntimeCallInfo *argv) +{ + ASSERT(argv); + JSThread *thread = argv->GetThread(); + [[maybe_unused]] EcmaHandleScope handleScope(thread); + JSHandle input(BuiltinsBase::GetThis(argv)); + if (!input->IsJSAPILightWeightSetIterator()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "this value is not an lightweightset iterator", + JSTaggedValue::Exception()); + } + JSHandle iter(input); + JSHandle undefinedHandle(thread, JSTaggedValue::Undefined()); + JSHandle lightWeightSet(thread, iter->GetIteratedLightWeightSet()); + uint32_t index = iter->GetNextIndex(); + IterationKind itemKind = IterationKind(iter->GetIterationKind()); + if (lightWeightSet->IsUndefined()) { + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); + } + uint32_t length = 0; + if (lightWeightSet->IsJSAPILightWeightSet()) { + length = JSHandle(lightWeightSet)->GetLength(); + } + if (index >= length) { + iter->SetIteratedLightWeightSet(thread, undefinedHandle); + return JSIterator::CreateIterResultObject(thread, undefinedHandle, true).GetTaggedValue(); + } + iter->SetNextIndex(index + 1); + JSHandle valueArray( + thread, TaggedArray::Cast(JSHandle(lightWeightSet)->GetValues().GetTaggedObject())); + JSHandle value(thread, valueArray->Get(index)); + if (itemKind == IterationKind::VALUE) { + return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); + } + TaggedArray *hashArray = + TaggedArray::Cast(JSHandle(lightWeightSet)->GetHashes().GetTaggedObject()); + JSHandle keyHandle(thread, hashArray->Get(index)); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle array(factory->NewTaggedArray(2)); // 2 means the length of array + array->Set(thread, 0, keyHandle); + array->Set(thread, 1, value); + JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); + return JSIterator::CreateIterResultObject(thread, keyAndValue, false).GetTaggedValue(); +} +} // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/js_api_lightweightset_iterator.h b/ecmascript/js_api_lightweightset_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..8e62959a6a61d5e1e862cbc424e07f3a8ae7e6ba --- /dev/null +++ b/ecmascript/js_api_lightweightset_iterator.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_JS_API_LIGHTWEIGHTSET_ITERATOR_H +#define ECMASCRIPT_JS_API_LIGHTWEIGHTSET_ITERATOR_H + +#include "js_iterator.h" +#include "js_object.h" + +namespace panda::ecmascript { +class JSAPILightWeightSetIterator : public JSObject { +public: + static JSAPILightWeightSetIterator *Cast(TaggedObject *obj) + { + ASSERT(JSTaggedValue(obj).IsJSAPILightWeightSetIterator()); + return static_cast(obj); + } + static JSTaggedValue Next(EcmaRuntimeCallInfo *argv); + static constexpr size_t ITERATED_LIGHT_WEIGHT_SET_OFFSET = JSObject::SIZE; + ACCESSORS(IteratedLightWeightSet, ITERATED_LIGHT_WEIGHT_SET_OFFSET, NEXT_INDEX_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(NextIndex, uint32_t, NEXT_INDEX_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + // define BitField + static constexpr size_t ITERATION_KIND_BITS = 2; + FIRST_BIT_FIELD(BitField, IterationKind, IterationKind, ITERATION_KIND_BITS) + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, ITERATED_LIGHT_WEIGHT_SET_OFFSET, NEXT_INDEX_OFFSET) + + DECL_DUMP() +}; +} // namespace panda::ecmascript +#endif // ECMASCRIPT_JS_API_LIGHT_WEIGHT_SET_ITERATOR_H \ No newline at end of file diff --git a/ecmascript/js_api_linked_list.h b/ecmascript/js_api_linked_list.h index c317f5f18e0a28d615d6be3b9ec904007baaeeab..13f52b209c1609c748f6f51b7a2b2db2d772bac2 100644 --- a/ecmascript/js_api_linked_list.h +++ b/ecmascript/js_api_linked_list.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JSAPILINKEDLIST_H -#define ECMASCRIPT_JSAPILINKEDLIST_H +#ifndef ECMASCRIPT_JS_API_LINKEDLIST_H +#define ECMASCRIPT_JS_API_LINKEDLIST_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -24,7 +24,7 @@ namespace panda::ecmascript { class JSAPILinkedList : public JSObject { public: static constexpr int DEFAULT_CAPACITY_LENGTH = 10; - static JSAPILinkedList *Cast(ObjectHeader *object) + static JSAPILinkedList *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPILinkedList()); return static_cast(object); @@ -69,4 +69,4 @@ public: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JSAPILinkedLIST_H +#endif // ECMASCRIPT_JS_API_LinkedLIST_H diff --git a/ecmascript/js_api_linked_list_iterator.h b/ecmascript/js_api_linked_list_iterator.h index ae3fddd12e8b5a22fd3e6421be48d85654d214ed..000ad4cd43bdc2c5d834dd4dd19422ec9515ab60 100644 --- a/ecmascript/js_api_linked_list_iterator.h +++ b/ecmascript/js_api_linked_list_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPILinkedListIterator : public JSObject { public: - static JSAPILinkedListIterator *Cast(ObjectHeader *obj) + static JSAPILinkedListIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPILinkedListIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_list.h b/ecmascript/js_api_list.h index 6655f17e49bccff21ebe413f5071ac59c2bacdff..4b04cc1373fadaa5fac28a336352de9f95310260 100644 --- a/ecmascript/js_api_list.h +++ b/ecmascript/js_api_list.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JSAPILIST_H -#define ECMASCRIPT_JSAPILIST_H +#ifndef ECMASCRIPT_JS_API_LIST_H +#define ECMASCRIPT_JS_API_LIST_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -24,7 +24,7 @@ namespace panda::ecmascript { class JSAPIList : public JSObject { public: static constexpr int DEFAULT_CAPACITY_LENGTH = 10; - static JSAPIList *Cast(ObjectHeader *object) + static JSAPIList *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIList()); return static_cast(object); @@ -72,4 +72,4 @@ public: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JSAPILIST_H +#endif // ECMASCRIPT_JS_API_LIST_H diff --git a/ecmascript/js_api_list_iterator.h b/ecmascript/js_api_list_iterator.h index 82bbe56377c5ddfa4d1bb6b04eca6d5b7a213c6d..1884285ae0ffa6a8c9c70c2822dfd3d350f30e0a 100644 --- a/ecmascript/js_api_list_iterator.h +++ b/ecmascript/js_api_list_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPIListIterator : public JSObject { public: - static JSAPIListIterator *Cast(ObjectHeader *obj) + static JSAPIListIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIListIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_plain_array.cpp b/ecmascript/js_api_plain_array.cpp index 0b22acb94c3ad222dda943499d62fb636d3ce129..94ebd3cbaa8b0188ad78f56611b3e32826be81e4 100644 --- a/ecmascript/js_api_plain_array.cpp +++ b/ecmascript/js_api_plain_array.cpp @@ -242,10 +242,11 @@ JSTaggedValue JSAPIPlainArray::ForEach(JSThread *thread, const JSHandleGet(k); JSTaggedValue key = keyArray->Get(k); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, 3); // 3: three args - info.SetCallArg(kValue, key, thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(kValue, key, thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); } return JSTaggedValue::Undefined(); diff --git a/ecmascript/js_api_plain_array.h b/ecmascript/js_api_plain_array.h index 89f1ee48b44192205ef042749c6034afdcecde85..080f3c5f8a96732a3ec9934dc8e5e0d7547b423b 100644 --- a/ecmascript/js_api_plain_array.h +++ b/ecmascript/js_api_plain_array.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JSPLAIN_ARRAY_H -#define ECMASCRIPT_JSPLAIN_ARRAY_H +#ifndef ECMASCRIPT_JS_API_PLAIN_ARRAY_H +#define ECMASCRIPT_JS_API_PLAIN_ARRAY_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -23,7 +23,7 @@ namespace panda::ecmascript { class JSAPIPlainArray : public JSObject { public: static constexpr int DEFAULT_CAPACITY_LENGTH = 8; - static JSAPIPlainArray *Cast(ObjectHeader *object) + static JSAPIPlainArray *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIPlainArray()); return static_cast(object); @@ -79,4 +79,4 @@ private: } }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JSPLAIN_ARRAY_H +#endif // ECMASCRIPT_JS_API_PLAIN_ARRAY_H diff --git a/ecmascript/js_api_plain_array_iterator.h b/ecmascript/js_api_plain_array_iterator.h index 413813bf50a5fcfc553e71cd6868e7cfeb99af8e..b2a6217d59cb4105392dbad839fe7930da0e74fd 100644 --- a/ecmascript/js_api_plain_array_iterator.h +++ b/ecmascript/js_api_plain_array_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPIPlainArrayIterator : public JSObject { public: - static JSAPIPlainArrayIterator *Cast(ObjectHeader *obj) + static JSAPIPlainArrayIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIPlainArrayIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_queue.h b/ecmascript/js_api_queue.h index 0df8f3c35d061fa23c99b272346c6e83916028ce..c2f09859f2faaaffe4206b9eca6045c0e1265c73 100644 --- a/ecmascript/js_api_queue.h +++ b/ecmascript/js_api_queue.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JSAPIQUEUE_H -#define ECMASCRIPT_JSAPIQUEUE_H +#ifndef ECMASCRIPT_JS_API_QUEUE_H +#define ECMASCRIPT_JS_API_QUEUE_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -23,7 +23,7 @@ namespace panda::ecmascript { class JSAPIQueue : public JSObject { public: static constexpr int DEFAULT_CAPACITY_LENGTH = 8; - static JSAPIQueue *Cast(ObjectHeader *object) + static JSAPIQueue *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIQueue()); return static_cast(object); @@ -82,4 +82,4 @@ private: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JSAPIQUEUE_H +#endif // ECMASCRIPT_JS_API_QUEUE_H diff --git a/ecmascript/js_api_queue_iterator.h b/ecmascript/js_api_queue_iterator.h index 470dd451060e6bbf4b5968c131c30054f9e9b23b..f105926a31989f393b805ca194c164a6b0c3412f 100644 --- a/ecmascript/js_api_queue_iterator.h +++ b/ecmascript/js_api_queue_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPIQueueIterator : public JSObject { public: - static JSAPIQueueIterator *Cast(ObjectHeader *obj) + static JSAPIQueueIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIQueueIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_stack.h b/ecmascript/js_api_stack.h index 74a92c70d8f8caad17240d6b058456ef948bfada..36fe57b64aefae9b0ad43f5f10b2824447569330 100644 --- a/ecmascript/js_api_stack.h +++ b/ecmascript/js_api_stack.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_JSAPISTACK_H -#define ECMASCRIPT_JSAPISTACK_H +#ifndef ECMASCRIPT_JS_API_STACK_H +#define ECMASCRIPT_JS_API_STACK_H #include "js_object.h" #include "js_tagged_value-inl.h" @@ -23,7 +23,7 @@ namespace panda::ecmascript { class JSAPIStack : public JSObject { public: static constexpr int DEFAULT_CAPACITY_LENGTH = 10; - static JSAPIStack *Cast(ObjectHeader *object) + static JSAPIStack *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIStack()); return static_cast(object); @@ -73,4 +73,4 @@ private: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_JSAPISTACK_H +#endif // ECMASCRIPT_JS_API_STACK_H diff --git a/ecmascript/js_api_stack_iterator.h b/ecmascript/js_api_stack_iterator.h index 2aa68e87565f0cb241302afb107e642cb166d6a4..8faa44cf13409989d62445e560b7aec31317ed85 100644 --- a/ecmascript/js_api_stack_iterator.h +++ b/ecmascript/js_api_stack_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPIStackIterator : public JSObject { public: - static JSAPIStackIterator *Cast(ObjectHeader *obj) + static JSAPIStackIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIStackIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_tree_map.h b/ecmascript/js_api_tree_map.h index 2e948deb0b30fad7524a476f30498010e685eb23..dcab7bb1bb39b7320952bca41cad600763870440 100644 --- a/ecmascript/js_api_tree_map.h +++ b/ecmascript/js_api_tree_map.h @@ -26,7 +26,7 @@ namespace panda::ecmascript { * */ class JSAPITreeMap : public JSObject { public: - static JSAPITreeMap *Cast(ObjectHeader *object) + static JSAPITreeMap *Cast(TaggedObject *object) { return static_cast(object); } diff --git a/ecmascript/js_api_tree_map_iterator.cpp b/ecmascript/js_api_tree_map_iterator.cpp index d91eb8da5167b1f0f7706647f512a8bb72c356b1..365a5a115d0c3f2d19119c8328fdfa66fd395cfa 100644 --- a/ecmascript/js_api_tree_map_iterator.cpp +++ b/ecmascript/js_api_tree_map_iterator.cpp @@ -71,7 +71,7 @@ JSTaggedValue JSAPITreeMapIterator::Next(EcmaRuntimeCallInfo *argv) return JSIterator::CreateIterResultObject(thread, value, false).GetTaggedValue(); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle array(factory->NewTaggedArray(2)); // 2 means the length of array + JSHandle array = factory->NewTaggedArray(2); // 2 means the length of array array->Set(thread, 0, key); array->Set(thread, 1, value); JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); diff --git a/ecmascript/js_api_tree_map_iterator.h b/ecmascript/js_api_tree_map_iterator.h index dc950c50c01d9937350367af5e2c1be32717f187..6addee7e77c8de9b2c58bf725b92be37d394a150 100644 --- a/ecmascript/js_api_tree_map_iterator.h +++ b/ecmascript/js_api_tree_map_iterator.h @@ -26,7 +26,7 @@ namespace panda::ecmascript { * */ class JSAPITreeMapIterator : public JSObject { public: - static JSAPITreeMapIterator *Cast(ObjectHeader *obj) + static JSAPITreeMapIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPITreeMapIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_tree_set.h b/ecmascript/js_api_tree_set.h index 83d5e3653fcca872eb37502d2af864dc7b3123a8..807c66ffff537c66a13c8fd8afb30b1220d1dff0 100644 --- a/ecmascript/js_api_tree_set.h +++ b/ecmascript/js_api_tree_set.h @@ -26,7 +26,7 @@ namespace panda::ecmascript { * */ class JSAPITreeSet : public JSObject { public: - static JSAPITreeSet *Cast(ObjectHeader *object) + static JSAPITreeSet *Cast(TaggedObject *object) { return static_cast(object); } diff --git a/ecmascript/js_api_tree_set_iterator.cpp b/ecmascript/js_api_tree_set_iterator.cpp index d66a5d03ef09f0b738473c6c495c50e44222bc6e..e73ab9accabb7e90342298701c61ae748eef428e 100644 --- a/ecmascript/js_api_tree_set_iterator.cpp +++ b/ecmascript/js_api_tree_set_iterator.cpp @@ -66,7 +66,7 @@ JSTaggedValue JSAPITreeSetIterator::Next(EcmaRuntimeCallInfo *argv) return JSIterator::CreateIterResultObject(thread, key, false).GetTaggedValue(); } ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle array(factory->NewTaggedArray(2)); // 2 means the length of array + JSHandle array = factory->NewTaggedArray(2); // 2 means the length of array array->Set(thread, 0, key); array->Set(thread, 1, key); JSHandle keyAndValue(JSArray::CreateArrayFromList(thread, array)); diff --git a/ecmascript/js_api_tree_set_iterator.h b/ecmascript/js_api_tree_set_iterator.h index ed25ee7cba7f7017d489b38f807a1ffb0696b5c4..d0487a82be257613f563540e4f09e4d4105fcc86 100644 --- a/ecmascript/js_api_tree_set_iterator.h +++ b/ecmascript/js_api_tree_set_iterator.h @@ -26,7 +26,7 @@ namespace panda::ecmascript { * */ class JSAPITreeSetIterator : public JSObject { public: - static JSAPITreeSetIterator *Cast(ObjectHeader *obj) + static JSAPITreeSetIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPITreeSetIterator()); return static_cast(obj); diff --git a/ecmascript/js_api_vector.cpp b/ecmascript/js_api_vector.cpp index 327716a6f5e3e9af831e977717382df3ab9a5b8b..80a144b675a782efcd9ffd5ae9aa9a3a8adc6842 100644 --- a/ecmascript/js_api_vector.cpp +++ b/ecmascript/js_api_vector.cpp @@ -32,7 +32,7 @@ bool JSAPIVector::Add(JSThread *thread, const JSHandle &vector, con int32_t length = vector->GetSize(); GrowCapacity(thread, vector, length + 1); - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); elements->Set(thread, length, value); vector->SetLength(++length); @@ -49,7 +49,7 @@ void JSAPIVector::Insert(JSThread *thread, const JSHandle &vector, } GrowCapacity(thread, vector, length + 1); - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); for (int32_t i = length - 1; i >= index; i--) { elements->Set(thread, i + 1, elements->Get(i)); @@ -70,7 +70,7 @@ void JSAPIVector::SetLength(JSThread *thread, const JSHandle &vecto uint32_t JSAPIVector::GetCapacity() { - TaggedArray* elementData = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elementData = TaggedArray::Cast(GetElements().GetTaggedObject()); ASSERT(!elementData->IsDictionaryMode()); return elementData->GetLength(); } @@ -101,7 +101,7 @@ int32_t JSAPIVector::GetIndexOf(JSThread *thread, const JSHandle &v int32_t JSAPIVector::GetIndexFrom(JSThread *thread, const JSHandle &vector, const JSHandle &obj, int32_t index) { - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); int32_t length = vector->GetSize(); if (index < 0) { @@ -130,7 +130,7 @@ JSTaggedValue JSAPIVector::GetLastElement() if (length == 0) { return JSTaggedValue::Undefined(); } - TaggedArray* elements = TaggedArray::Cast(GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); return elements->Get(length - 1); } @@ -138,20 +138,23 @@ JSTaggedValue JSAPIVector::GetLastElement() int32_t JSAPIVector::GetLastIndexOf(JSThread *thread, const JSHandle &vector, const JSHandle &obj) { - int32_t length = vector->GetSize(); - return JSAPIVector::GetLastIndexFrom(thread, vector, obj, length - 1); + int32_t index = vector->GetSize() - 1; + if (index < 0) { + return -1; // vector isEmpty, defalut return -1 + } + return JSAPIVector::GetLastIndexFrom(thread, vector, obj, index); } int32_t JSAPIVector::GetLastIndexFrom(JSThread *thread, const JSHandle &vector, const JSHandle &obj, int32_t index) { int32_t length = vector->GetSize(); - if (index < 0) { - index = 0; - } else if (index >= length) { + if (index >= length) { THROW_RANGE_ERROR_AND_RETURN(thread, "index-out-of-bounds", -1); + } else if (index < 0) { + index = 0; } - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); JSMutableHandle value(thread, JSTaggedValue::Undefined()); for (int32_t i = index; i >= 0; i--) { @@ -173,7 +176,7 @@ bool JSAPIVector::Remove(JSThread *thread, const JSHandle &vector, THROW_RANGE_ERROR_AND_RETURN(thread, "index-out-of-bounds", false); } - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); for (int32_t i = index; i < length - 1; i++) { elements->Set(thread, i, elements->Get(i + 1)); @@ -191,7 +194,7 @@ JSTaggedValue JSAPIVector::RemoveByIndex(JSThread *thread, const JSHandle= length) { THROW_RANGE_ERROR_AND_RETURN(thread, "the index is out-of-bounds", JSTaggedValue::Exception()); } - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); JSTaggedValue oldValue = elements->Get(index); @@ -218,7 +221,7 @@ JSTaggedValue JSAPIVector::RemoveByRange(JSThread *thread, const JSHandle= length ? length : toIndex; - TaggedArray* elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); + TaggedArray *elements = TaggedArray::Cast(vector->GetElements().GetTaggedObject()); ASSERT(!elements->IsDictionaryMode()); int32_t numMoved = length - endIndex; for (int32_t i = 0; i < numMoved; i++) { @@ -299,16 +302,17 @@ JSTaggedValue JSAPIVector::ForEach(JSThread *thread, const JSHandleGetSize(); JSTaggedValue key = JSTaggedValue::Undefined(); JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); - const size_t argsLength = RESERVED_CALL_ARGCOUNT; + const int32_t argsLength = NUM_MANDATORY_JSFUNC_ARGS; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (int32_t k = 0; k < length; k++) { kValue.Update(Get(thread, vector, k)); key = JSTaggedValue(k); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key, thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(kValue.GetTaggedValue(), key, thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); if (length != vector->GetSize()) { // prevent length change length = vector->GetSize(); @@ -326,16 +330,17 @@ JSTaggedValue JSAPIVector::ReplaceAllElements(JSThread *thread, const JSHandleGetSize(); JSTaggedValue key = JSTaggedValue::Undefined(); JSMutableHandle kValue(thread, JSTaggedValue::Undefined()); - const size_t argsLength = RESERVED_CALL_ARGCOUNT; + const int32_t argsLength = NUM_MANDATORY_JSFUNC_ARGS; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); for (int32_t k = 0; k < length; k++) { kValue.Update(Get(thread, vector, k)); key = JSTaggedValue(k); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, argsLength); - info.SetCallArg(kValue.GetTaggedValue(), key, thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(kValue.GetTaggedValue(), key, thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); if (length != vector->GetSize()) { // prevent length change length = vector->GetSize(); diff --git a/ecmascript/js_api_vector.h b/ecmascript/js_api_vector.h index ce19d96fc5eb5fe635bb9a2715c55ed761e14d16..41bc290659d467efa42699378225b702d59d4564 100644 --- a/ecmascript/js_api_vector.h +++ b/ecmascript/js_api_vector.h @@ -23,7 +23,7 @@ namespace panda::ecmascript { class JSAPIVector : public JSObject { public: static constexpr int32_t DEFAULT_CAPACITY_LENGTH = 10; - static JSAPIVector *Cast(ObjectHeader *object) + static JSAPIVector *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAPIVector()); return static_cast(object); diff --git a/ecmascript/js_api_vector_iterator.h b/ecmascript/js_api_vector_iterator.h index 253b8ef9e3f73486bdc1a193b1428f25699d4a3a..c63ff066a394395b49241bcb1ea5ae7a9c64468f 100644 --- a/ecmascript/js_api_vector_iterator.h +++ b/ecmascript/js_api_vector_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSAPIVectorIterator : public JSObject { public: - static JSAPIVectorIterator *Cast(ObjectHeader *obj) + static JSAPIVectorIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSAPIVectorIterator()); return static_cast(obj); diff --git a/ecmascript/js_arguments.cpp b/ecmascript/js_arguments.cpp index 96c8c8d1b96fbf6f4fcfb144d68af31cdc478d50..a5a3d0d0d4a858c7e6a4bcd5eef2a6d10a3bc43f 100644 --- a/ecmascript/js_arguments.cpp +++ b/ecmascript/js_arguments.cpp @@ -30,22 +30,6 @@ bool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle & return true; } - // 4.Let map be the value of the [[ParameterMap]] internal slot of the arguments object. - JSHandle map(thread, args->GetParameterMap()); - - // 5.Let isMapped be HasOwnProperty(map, P). - bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); - - // 6.Assert: isMapped is never an abrupt completion. - ASSERT(!thread->HasPendingException()); - - // 7.If the value of isMapped is true, then - // a.Set desc.[[Value]] to Get(map, P). - if (isMapped) { - auto prop = JSObject::GetProperty(thread, map, key).GetValue(); - desc.SetValue(prop); - } - // 8.If IsDataDescriptor(desc) is true and P is "caller" and desc.[[Value]] is a strict mode Function object, // throw a TypeError exception. JSHandle caller = thread->GetEcmaVM()->GetFactory()->NewFromASCII("caller"); @@ -60,46 +44,12 @@ bool JSArguments::GetOwnProperty(JSThread *thread, const JSHandle & bool JSArguments::DefineOwnProperty(JSThread *thread, const JSHandle &args, const JSHandle &key, const PropertyDescriptor &desc) { - // 1 ~ 2 Let args be the arguments object and get map. - JSHandle map(thread, args->GetParameterMap()); - - // 3.Let isMapped be HasOwnProperty(map, P). - bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); - // 4.Let allowed be OrdinaryDefineOwnProperty(args, P, Desc). bool allowed = JSObject::OrdinaryDefineOwnProperty(thread, JSHandle(args), key, desc); // 5.ReturnIfAbrupt(allowed). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, allowed); - // 6.If allowed is false, return false. - if (!allowed) { - return false; - } - - // 7.If the value of isMapped is true, then - // a.If IsAccessorDescriptor(Desc) is true, then - // i.Call map.[[Delete]](P). - // b.Else - // i.If Desc.[[Value]] is present, then - // 1.Let setStatus be Set(map, P, Desc.[[Value]], false). - // 2.Assert: setStatus is true because formal parameters mapped by argument objects are always writable. - // ii.If Desc.[[Writable]] is present and its value is false, then - // 1.Call map.[[Delete]](P). - if (isMapped) { - if (desc.IsAccessorDescriptor()) { - JSTaggedValue::DeleteProperty(thread, map, key); - } else { - if (desc.HasValue()) { - [[maybe_unused]] bool setStatus = JSTaggedValue::SetProperty(thread, map, key, desc.GetValue(), false); - ASSERT(setStatus == true); - } - if (desc.HasWritable() && !desc.IsWritable()) { - JSTaggedValue::DeleteProperty(thread, map, key); - } - } - } - // 8.Return true. return true; } @@ -107,53 +57,15 @@ bool JSArguments::DefineOwnProperty(JSThread *thread, const JSHandle &args, const JSHandle &key, const JSHandle &receiver) { - // 1 ~ 2 Let args be the arguments object and get map. - JSHandle map(thread, args->GetParameterMap()); - - // 3.Let isMapped be HasOwnProperty(map, P). - bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); - - // 4.Assert: isMapped is not an abrupt completion. - ASSERT(!thread->HasPendingException()); - // 5.If the value of isMapped is false, then // a.Return the result of calling the default ordinary object [[Get]] internal method (9.1.8) // on args passing P and Receiver as the arguments. - if (!isMapped) { - return JSTaggedValue::GetProperty(thread, JSHandle::Cast(args), key, receiver); - } - - // 6.Else map contains a formal parameter mapping for P, - // a.Return Get(map, P). - return JSTaggedValue::GetProperty(thread, map, key); + return JSTaggedValue::GetProperty(thread, JSHandle::Cast(args), key, receiver); } bool JSArguments::SetProperty(JSThread *thread, const JSHandle &args, const JSHandle &key, const JSHandle &value, const JSHandle &receiver) { - // 1.Let args be the arguments object. - JSHandle map(thread, args->GetParameterMap()); - - // 2.If SameValue(args, Receiver) is false, then - // a.Let isMapped be false. - bool isMapped = false; - if (JSTaggedValue::SameValue(args.GetTaggedValue(), receiver.GetTaggedValue())) { - // 3.Else, - // a.Let map be the value of the [[ParameterMap]] internal slot of the arguments object. - // b.Let isMapped be HasOwnProperty(map, P). - // c.Assert: isMapped is not an abrupt completion. - isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); - ASSERT(!thread->HasPendingException()); - } - - // 4.If isMapped is true, then - // a.Let setStatus be Set(map, P, V, false). - // b.Assert: setStatus is true because formal parameters mapped by argument objects are always writable. - if (isMapped) { - [[maybe_unused]] bool setStatus = JSTaggedValue::SetProperty(thread, map, key, value); - ASSERT(setStatus == true); - } - // 5.Return the result of calling the default ordinary object [[Set]] internal method (9.1.9) // on args passing P, V and Receiver as the arguments. return JSTaggedValue::SetProperty(thread, JSHandle::Cast(args), key, value, receiver); @@ -162,15 +74,6 @@ bool JSArguments::SetProperty(JSThread *thread, const JSHandle &arg bool JSArguments::DeleteProperty(JSThread *thread, const JSHandle &args, const JSHandle &key) { - // 1.Let map be the value of the [[ParameterMap]] internal slot of the arguments object. - JSHandle map(thread, args->GetParameterMap()); - - // 2.Let isMapped be HasOwnProperty(map, P). - bool isMapped = JSTaggedValue::HasOwnProperty(thread, map, key); - - // 3.Assert: isMapped is not an abrupt completion. - ASSERT(!thread->HasPendingException()); - // 4.Let result be the result of calling the default [[Delete]] internal method for ordinary objects (9.1.10) // on the arguments object passing P as the argument. bool result = JSTaggedValue::DeleteProperty(thread, JSHandle(args), key); @@ -178,12 +81,6 @@ bool JSArguments::DeleteProperty(JSThread *thread, const JSHandle & // 5.ReturnIfAbrupt(result). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); - // 6.If result is true and the value of isMapped is true, then - // a.Call map.[[Delete]](P). - if (result && isMapped) { - JSTaggedValue::DeleteProperty(thread, map, key); - } - // 7.Return result. return result; } diff --git a/ecmascript/js_arguments.h b/ecmascript/js_arguments.h index c04ed12b4006b010e6ff32a3a1840e6cb3cf0307..32819d58bbbbc9dd7cf19f5ac003c48340ddee0b 100644 --- a/ecmascript/js_arguments.h +++ b/ecmascript/js_arguments.h @@ -58,11 +58,6 @@ public: static bool DeleteProperty(JSThread *thread, const JSHandle &args, const JSHandle &key); // 9.4.4.6 CreateUnmappedArgumentsObject(argumentsList) // 9.4.4.7 CreateMappedArgumentsObject ( func, formals, argumentsList, env ) - - static constexpr size_t PARAMETER_MAP_OFFSET = JSObject::SIZE; - ACCESSORS(ParameterMap, PARAMETER_MAP_OFFSET, SIZE) - - DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, PARAMETER_MAP_OFFSET, SIZE) }; } // namespace panda::ecmascript diff --git a/ecmascript/js_array.cpp b/ecmascript/js_array.cpp index c8ffdd3dd10799fb4795bd5d521315dcf234733f..ee7f3b31235a0c9c8c8051c044644a4b15110d49 100644 --- a/ecmascript/js_array.cpp +++ b/ecmascript/js_array.cpp @@ -156,10 +156,11 @@ JSTaggedValue JSArray::ArraySpeciesCreate(JSThread *thread, const JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, constructor, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(arrayLength)); - JSTaggedValue result = JSFunction::Construct(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(JSTaggedValue(arrayLength)); + JSTaggedValue result = JSFunction::Construct(info); // NOTEIf originalArray was created using the standard built-in Array constructor for // a Realm that is not the Realm of the running execution context, then a new Array is diff --git a/ecmascript/js_arraybuffer.cpp b/ecmascript/js_arraybuffer.cpp index 3f7999f05e327494fae1b51abc6c42d956d63d4c..b6c0eb730d788e70d8a10ddd12b935529e0f9ad4 100644 --- a/ecmascript/js_arraybuffer.cpp +++ b/ecmascript/js_arraybuffer.cpp @@ -30,7 +30,7 @@ void JSArrayBuffer::CopyDataBlockBytes(JSTaggedValue toBlock, JSTaggedValue from auto *from = static_cast(fromBuf); auto *to = static_cast(toBuf); if (memcpy_s(to, count, from + fromIndex, count) != EOK) { // NOLINT - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } diff --git a/ecmascript/js_async_function.cpp b/ecmascript/js_async_function.cpp index 165a53d227782885d36b43a4f674fc19b5e537af..548f8196768d3a2dc7219b30b990647113ca5ae1 100644 --- a/ecmascript/js_async_function.cpp +++ b/ecmascript/js_async_function.cpp @@ -49,10 +49,11 @@ void JSAsyncFunction::AsyncFunctionAwait(JSThread *thread, const JSHandle thisArg = globalConst->GetHandledUndefined(); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, thisArg, undefined, 1); - info.SetCallArg(value.GetTaggedValue()); - [[maybe_unused]] JSTaggedValue res = JSFunction::Call(&info); + RETURN_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(value.GetTaggedValue()); + [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info); // 4.Let onFulfilled be a new built-in function object as defined in AsyncFunction Awaited Fulfilled. JSHandle fulFunc = factory->NewJSAsyncAwaitStatusFunction( diff --git a/ecmascript/js_async_function.h b/ecmascript/js_async_function.h index 7e94d15bb9e174ee9e2855cb105f619d9707e314..74d9a8976a8c84a0a23ec9b992ac90874a934d6a 100644 --- a/ecmascript/js_async_function.h +++ b/ecmascript/js_async_function.h @@ -43,7 +43,7 @@ public: class JSAsyncFunction : public JSFunction { public: - static JSAsyncFunction *Cast(ObjectHeader *object) + static JSAsyncFunction *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSAsyncFunction()); return static_cast(object); diff --git a/ecmascript/js_bigint.cpp b/ecmascript/js_bigint.cpp index cf35d0421defec255465701cb391606563d99457..770217f5dc8b57e25c921812f67d04ddd462389a 100644 --- a/ecmascript/js_bigint.cpp +++ b/ecmascript/js_bigint.cpp @@ -14,10 +14,9 @@ */ #include "ecmascript/js_bigint.h" -#include "ecmascript/base/number_helper.h" -#include "ecmascript/tagged_array-inl.h" -#include "object_factory.h" -#include "securec.h" +#include "ecmascript/js_tagged_value-inl.h" +#include "ecmascript/js_tagged_number.h" + namespace panda::ecmascript { class ObjectFactory; constexpr char dp[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -95,7 +94,7 @@ JSHandle BigIntHelper::SetBigInt(JSThread *thread, const CString &numStr val <<= 1; val |= static_cast(binaryStr[i] - '0'); } - BigInt::SetDigit(thread, bigint, index, val); + bigint->SetDigit(index, val); index--; } if (flag == 1) { @@ -108,7 +107,7 @@ JSHandle BigIntHelper::SetBigInt(JSThread *thread, const CString &numStr val <<= 1; val |= static_cast(binaryStr[i] - '0'); } - BigInt::SetDigit(thread, bigint, index, val); + bigint->SetDigit(index, val); index--; } return BigIntHelper::RightTruncate(thread, bigint); @@ -132,16 +131,13 @@ JSHandle BigIntHelper::RightTruncate(JSThread *thread, JSHandle } index--; } - JSHandle array(thread, x->GetData()); + if (index == -1) { - array->Trim(thread, 1); + return BigInt::Int32ToBigInt(thread, 0); } else { - array->Trim(thread, index + 1); - } - if (x->IsZero()) { - x->SetSign(false); + ASSERT(index >= 0); + return BigInt::Copy(thread, x, index + 1); } - return x; } CString BigIntHelper::GetBinary(const BigInt *bigint) @@ -165,32 +161,11 @@ CString BigIntHelper::GetBinary(const BigInt *bigint) return res; } -uint32_t BigInt::GetDigit(uint32_t index) const +JSHandle BigInt::CreateBigint(JSThread *thread, uint32_t length) { - TaggedArray *TaggedArray = TaggedArray::Cast(GetData().GetTaggedObject()); - JSTaggedValue digit = TaggedArray->Get(index); - return static_cast(digit.GetInt()); -} - -void BigInt::SetDigit(JSThread* thread, JSHandle bigint, uint32_t index, uint32_t digit) -{ - TaggedArray *TaggedArray = TaggedArray::Cast(bigint->GetData().GetTaggedObject()); - TaggedArray->Set(thread, index, JSTaggedValue(static_cast(digit))); -} - -uint32_t BigInt::GetLength() const -{ - TaggedArray *TaggedArray = TaggedArray::Cast(GetData().GetTaggedObject()); - return TaggedArray->GetLength(); -} - -JSHandle BigInt::CreateBigint(JSThread *thread, uint32_t size) -{ - ASSERT(size < MAXSIZE); + ASSERT(length < MAXSIZE); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle bigint = factory->NewBigInt(); - JSHandle taggedArray = factory->NewTaggedArray(size); - bigint->SetData(thread, taggedArray.GetTaggedValue()); + JSHandle bigint = factory->NewBigInt(length); return bigint; } @@ -229,14 +204,6 @@ bool BigInt::SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y) return Equal(x, y); } -void BigInt::InitializationZero(JSThread *thread, JSHandle bigint) -{ - uint32_t len = bigint->GetLength(); - for (uint32_t i = 0; i < len; ++i) { - SetDigit(thread, bigint, i, 0); - } -} - JSHandle BigInt::BitwiseOp(JSThread *thread, Operate op, JSHandle x, JSHandle y) { uint32_t maxLen = 0; @@ -251,25 +218,24 @@ JSHandle BigInt::BitwiseOp(JSThread *thread, Operate op, JSHandle bigint = BigInt::CreateBigint(thread, maxLen); - InitializationZero(thread, bigint); for (size_t i = 0; i < minLen; ++i) { if (op == Operate::OR) { - SetDigit(thread, bigint, i, x->GetDigit(i) | y->GetDigit(i)); + bigint->SetDigit(i, x->GetDigit(i) | y->GetDigit(i)); } else if (op == Operate::AND) { - SetDigit(thread, bigint, i, x->GetDigit(i) & y->GetDigit(i)); + bigint->SetDigit(i, x->GetDigit(i) & y->GetDigit(i)); } else { ASSERT(op == Operate::XOR); - SetDigit(thread, bigint, i, x->GetDigit(i) ^ y->GetDigit(i)); + bigint->SetDigit(i, x->GetDigit(i) ^ y->GetDigit(i)); } } if (op == Operate::OR || op == Operate::XOR) { if (xlen > ylen) { for (size_t i = ylen; i < xlen; ++i) { - SetDigit(thread, bigint, i, x->GetDigit(i)); + bigint->SetDigit(i, x->GetDigit(i)); } } else if (ylen > xlen) { for (size_t i = xlen; i < ylen; ++i) { - SetDigit(thread, bigint, i, y->GetDigit(i)); + bigint->SetDigit(i, y->GetDigit(i)); } } } @@ -289,11 +255,11 @@ JSHandle OneIsNegativeAND(JSThread *thread, JSHandle x, JSHandle uint32_t i = 0; while (i < minLen) { uint32_t res = x->GetDigit(i) & ~(yVal->GetDigit(i)); - BigInt::SetDigit(thread, newBigint, i, res); + newBigint->SetDigit(i, res); ++i; } while (i < xLength) { - BigInt::SetDigit(thread, newBigint, i, x->GetDigit(i)); + newBigint->SetDigit(i, x->GetDigit(i)); ++i; } return BigIntHelper::RightTruncate(thread, newBigint); @@ -360,12 +326,12 @@ JSHandle BigInt::BitwiseSubOne(JSThread *thread, JSHandle bigint uint32_t carry = 1; for (uint32_t i = 0; i < bigintLen; i++) { uint32_t bigintCarry = 0; - BigInt::SetDigit(thread, newBigint, i, BigIntHelper::SubHelper(bigint->GetDigit(i), carry, bigintCarry)); + newBigint->SetDigit(i, BigIntHelper::SubHelper(bigint->GetDigit(i), carry, bigintCarry)); carry = bigintCarry; } ASSERT(!carry); for (uint32_t i = bigintLen; i < maxLen; i++) { - BigInt::SetDigit(thread, newBigint, i, carry); + newBigint->SetDigit(i, carry); } return BigIntHelper::RightTruncate(thread, newBigint); } @@ -390,11 +356,11 @@ JSHandle BigInt::BitwiseAddOne(JSThread *thread, JSHandle bigint uint32_t carry = 1; for (uint32_t i = 0; i < bigintLength; i++) { uint32_t bigintCarry = 0; - BigInt::SetDigit(thread, newBigint, i, BigIntHelper::AddHelper(bigint->GetDigit(i), carry, bigintCarry)); + newBigint->SetDigit(i, BigIntHelper::AddHelper(bigint->GetDigit(i), carry, bigintCarry)); carry = bigintCarry; } if (needExpend) { - BigInt::SetDigit(thread, newBigint, bigintLength, carry); + newBigint->SetDigit(bigintLength, carry); } else { ASSERT(!carry); } @@ -419,11 +385,11 @@ JSHandle OneIsNegativeOR(JSThread *thread, JSHandle x, JSHandle< uint32_t i = 0; while (i < minLen) { uint32_t res = ~(x->GetDigit(i)) & yVal->GetDigit(i); - BigInt::SetDigit(thread, newBigint, i, res); + newBigint->SetDigit(i, res); ++i; } while (i < yLength) { - BigInt::SetDigit(thread, newBigint, i, yVal->GetDigit(i)); + newBigint->SetDigit(i, yVal->GetDigit(i)); ++i; } JSHandle temp = BigIntHelper::RightTruncate(thread, newBigint); @@ -490,33 +456,33 @@ JSTaggedValue BigInt::NumberToBigInt(JSThread *thread, JSHandle n // Bit operations must be of integer type uint64_t bits = 0; if (memcpy_s(&bits, sizeof(bits), &num, sizeof(num)) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } // Take out bits 62-52 (11 bits in total) and subtract 1023 uint64_t integerDigits = ((bits >> base::DOUBLE_SIGNIFICAND_SIZE) & 0x7FF) - base::DOUBLE_EXPONENT_BIAS; - uint32_t MayNeedLen = integerDigits / BigInt::DATEBITS + 1; + uint32_t mayNeedLen = integerDigits / DATEBITS + 1; - JSHandle bigint = CreateBigint(thread, MayNeedLen); + JSHandle bigint = CreateBigint(thread, mayNeedLen); bigint->SetSign(num < 0); uint64_t mantissa = (bits & base::DOUBLE_SIGNIFICAND_MASK) | base::DOUBLE_HIDDEN_BIT; int mantissaSize = base::DOUBLE_SIGNIFICAND_SIZE; int leftover = 0; - bool IsFirstInto = true; - for (int index = static_cast(MayNeedLen - 1); index >= 0; --index) { + bool isFirstInto = true; + for (int index = static_cast(mayNeedLen - 1); index >= 0; --index) { uint32_t doubleNum = 0; - if (IsFirstInto) { - IsFirstInto = false; - leftover = mantissaSize - static_cast(integerDigits % BigInt::DATEBITS); + if (isFirstInto) { + isFirstInto = false; + leftover = mantissaSize - static_cast(integerDigits % DATEBITS); doubleNum = static_cast(mantissa >> leftover); mantissa = mantissa << (64 - leftover); // 64 : double bits size - BigInt::SetDigit(thread, bigint, index, doubleNum); + bigint->SetDigit(index, doubleNum); } else { - leftover -= BigInt::DATEBITS; - doubleNum = static_cast(mantissa >> BigInt::DATEBITS); - mantissa = mantissa << BigInt::DATEBITS; - BigInt::SetDigit(thread, bigint, index, doubleNum); + leftover -= DATEBITS; + doubleNum = static_cast(mantissa >> DATEBITS); + mantissa = mantissa << DATEBITS; + bigint->SetDigit(index, doubleNum); } } return BigIntHelper::RightTruncate(thread, bigint).GetTaggedValue(); @@ -532,14 +498,13 @@ JSHandle BigInt::Int32ToBigInt(JSThread *thread, const int &number) } else { value = number; } - BigInt::SetDigit(thread, bigint, 0, value); + bigint->SetDigit(0, value); bigint->SetSign(sign); return bigint; } JSHandle BigInt::Int64ToBigInt(JSThread *thread, const int64_t &number) { - JSHandle bigint = CreateBigint(thread, 2); // 2 : one int64_t bits need two uint32_t bits uint64_t value = 0; bool sign = number < 0; if (sign) { @@ -547,9 +512,7 @@ JSHandle BigInt::Int64ToBigInt(JSThread *thread, const int64_t &number) } else { value = number; } - uint32_t *addr = reinterpret_cast(&value); - BigInt::SetDigit(thread, bigint, 0, *(addr)); - BigInt::SetDigit(thread, bigint, 1, *(addr + 1)); + JSHandle bigint = Uint64ToBigInt(thread, value); bigint->SetSign(sign); return BigIntHelper::RightTruncate(thread, bigint); } @@ -557,25 +520,33 @@ JSHandle BigInt::Int64ToBigInt(JSThread *thread, const int64_t &number) JSHandle BigInt::Uint64ToBigInt(JSThread *thread, const uint64_t &number) { JSHandle bigint = CreateBigint(thread, 2); // 2 : one int64_t bits need two uint32_t bits - const uint32_t *addr = reinterpret_cast(&number); - BigInt::SetDigit(thread, bigint, 0, *(addr)); - BigInt::SetDigit(thread, bigint, 1, *(addr + 1)); + uint32_t lowBits = static_cast(number & 0xffffffff); + uint32_t highBits = static_cast((number >> DATEBITS) & 0xffffffff); + bigint->SetDigit(0, lowBits); + bigint->SetDigit(1, highBits); return BigIntHelper::RightTruncate(thread, bigint); } -int64_t BigInt::ToInt64() +uint64_t BigInt::ToUint64() { uint32_t len = GetLength(); - ASSERT(len < 2); // The maximum length of the BigInt data is less 2 - uint64_t value = 0; - uint32_t *addr = reinterpret_cast(&value); - for (int32_t index = static_cast(len - 1); index >= 0; --index) { - *(addr + index) = GetDigit(index); - } + ASSERT(len <= 2); // The maximum length of the BigInt data is less or equal 2 + uint32_t lowBits = GetDigit(0); + uint32_t highBits = 0; + if (len > 1) { + highBits = GetDigit(1); + } + uint64_t value = static_cast(lowBits); + value |= static_cast(highBits) << DATEBITS; if (GetSign()) { value = ~(value - 1); } - return static_cast(value); + return value; +} + +int64_t BigInt::ToInt64() +{ + return static_cast(ToUint64()); } void BigInt::BigIntToInt64(JSThread *thread, JSHandle bigint, int64_t *cValue, bool *lossless) @@ -599,21 +570,20 @@ void BigInt::BigIntToUint64(JSThread *thread, JSHandle bigint, ui if (Equal(bigUint64.GetTaggedValue(), bigint.GetTaggedValue())) { *lossless = true; } - uint32_t *addr = reinterpret_cast(cValue); - int len = static_cast(bigUint64->GetLength()); - for (int index = len - 1; index >= 0; --index) { - *(addr + index) = bigUint64->GetDigit(index); - } + *cValue = bigUint64->ToUint64(); } JSHandle BigInt::CreateBigWords(JSThread *thread, bool sign, uint32_t size, const uint64_t *words) { ASSERT(words != nullptr); - uint32_t needLen = size * 2; // 2 : uint64_t size to uint32_t size + const uint32_t MULTIPLE = 2; + uint32_t needLen = size * MULTIPLE; JSHandle bigint = CreateBigint(thread, needLen); - const uint32_t *digits = reinterpret_cast(words); - for (uint32_t index = 0; index < needLen; ++index) { - SetDigit(thread, bigint, index, *(digits + index)); + for (uint32_t index = 0; index < size; ++index) { + uint32_t lowBits = static_cast(words[index] & 0xffffffff); + uint32_t highBits = static_cast((words[index] >> DATEBITS) & 0xffffffff); + bigint->SetDigit(MULTIPLE * index, lowBits); + bigint->SetDigit(MULTIPLE * index + 1, highBits); } bigint->SetSign(sign); return BigIntHelper::RightTruncate(thread, bigint); @@ -692,18 +662,18 @@ JSHandle BigInt::BigintAdd(JSThread *thread, JSHandle x, JSHandl uint32_t newBigintCarry = 0; uint32_t addPlus = BigIntHelper::AddHelper(x->GetDigit(i), y->GetDigit(i), newBigintCarry); addPlus = BigIntHelper::AddHelper(addPlus, bigintCarry, newBigintCarry); - SetDigit(thread, bigint, i, addPlus); + bigint->SetDigit(i, addPlus); bigintCarry = newBigintCarry; i++; } while (i < x->GetLength()) { uint32_t newBigintCarry = 0; uint32_t addPlus = BigIntHelper::AddHelper(x->GetDigit(i), bigintCarry, newBigintCarry); - SetDigit(thread, bigint, i, addPlus); + bigint->SetDigit(i, addPlus); bigintCarry = newBigintCarry; i++; } - SetDigit(thread, bigint, i, bigintCarry); + bigint->SetDigit(i, bigintCarry); bigint->SetSign(resultSign); return BigIntHelper::RightTruncate(thread, bigint); } @@ -726,14 +696,14 @@ JSHandle BigInt::BigintSub(JSThread *thread, JSHandle x, JSHandl uint32_t newBigintCarry = 0; uint32_t minuSub = BigIntHelper::SubHelper(x->GetDigit(i), y->GetDigit(i), newBigintCarry); minuSub = BigIntHelper::SubHelper(minuSub, bigintCarry, newBigintCarry); - SetDigit(thread, bigint, i, minuSub); + bigint->SetDigit(i, minuSub); bigintCarry = newBigintCarry; i++; } while (i < x->GetLength()) { uint32_t newBigintCarry = 0; uint32_t minuSub = BigIntHelper::SubHelper(x->GetDigit(i), bigintCarry, newBigintCarry); - SetDigit(thread, bigint, i, minuSub); + bigint->SetDigit(i, minuSub); bigintCarry = newBigintCarry; i++; } @@ -837,7 +807,7 @@ JSHandle BigInt::RightShiftHelper(JSThread *thread, JSHandle x, } JSHandle bigint = BigIntHelper::SetBigInt(thread, finalBinay, BINARY); if (x->GetSign()) { - SetDigit(thread, bigint, 0, bigint->GetDigit(0) + 1); + bigint->SetDigit(0, bigint->GetDigit(0) + 1); } bigint->SetSign(x->GetSign()); return BigIntHelper::RightTruncate(thread, bigint); @@ -869,15 +839,13 @@ JSTaggedValue BigInt::UnsignedRightShift(JSThread *thread) JSTaggedValue::Exception()); } -JSHandle BigInt::Copy(JSThread *thread, JSHandle x) +JSHandle BigInt::Copy(JSThread *thread, JSHandle x, uint32_t len) { - uint32_t len = x->GetLength(); - JSHandle temp = CreateBigint(thread, len); - for (uint32_t i = 0; i < len; i++) { - SetDigit(thread, temp, i, x->GetDigit(i)); - } - temp->SetSign(x->GetSign()); - return temp; + ASSERT(x->GetLength() >= len); + JSHandle newBig = CreateBigint(thread, len); + std::copy(x->GetData(), x->GetData() + len, newBig->GetData()); + newBig->SetSign(x->GetSign()); + return newBig; } JSHandle BigInt::UnaryMinus(JSThread *thread, JSHandle x) @@ -885,7 +853,7 @@ JSHandle BigInt::UnaryMinus(JSThread *thread, JSHandle x) if (x->IsZero()) { return x; } - JSHandle y = Copy(thread, x); + JSHandle y = Copy(thread, x, x->GetLength()); y->SetSign(!y->GetSign()); return y; } @@ -1154,7 +1122,7 @@ static JSTaggedNumber CalculateNumber(const uint64_t &sign, const uint64_t &mant uint64_t doubleBit = sign | exponent | mantissa; double res = 0; if (memcpy_s(&res, sizeof(res), &doubleBit, sizeof(doubleBit)) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } return JSTaggedNumber(res); @@ -1287,7 +1255,7 @@ ComparisonResult BigInt::CompareWithNumber(JSHandle bigint, JSHandle> base::DOUBLE_SIGNIFICAND_SIZE) & 0x7FF; diff --git a/ecmascript/js_bigint.h b/ecmascript/js_bigint.h index 02ee04699368625e6a83cac0563ef06c33dc746f..def5fe8112041741b2e8ff5427cda74f4634735f 100644 --- a/ecmascript/js_bigint.h +++ b/ecmascript/js_bigint.h @@ -20,6 +20,7 @@ #include "ecmascript/js_handle.h" #include "ecmascript/js_thread.h" #include "js_object.h" +#include "securec.h" namespace panda::ecmascript { enum class Operate : uint32_t { AND = 0, OR, XOR }; @@ -44,7 +45,6 @@ public: static bool SameValue(const JSTaggedValue &x, const JSTaggedValue &y); static bool SameValueZero(const JSTaggedValue &x, const JSTaggedValue &y); - static void InitializationZero(JSThread *thread, JSHandle bigint); static JSHandle BitwiseOp(JSThread *thread, Operate op, JSHandle x, JSHandle y); static JSHandle BitwiseAND(JSThread *thread, JSHandle x, JSHandle y); static JSHandle BitwiseXOR(JSThread *thread, JSHandle x, JSHandle y); @@ -63,7 +63,7 @@ public: static JSHandle Remainder(JSThread *thread, JSHandle n, JSHandle d); static JSHandle BigintAddOne(JSThread *thread, JSHandle x); static JSHandle BigintSubOne(JSThread *thread, JSHandle x); - static JSHandle Copy(JSThread *thread, JSHandle x); + static JSHandle Copy(JSThread *thread, JSHandle x, uint32_t len); static JSHandle Add(JSThread *thread, JSHandle x, JSHandle y); static JSHandle Subtract(JSThread *thread, JSHandle x, JSHandle y); @@ -82,6 +82,7 @@ public: static JSHandle Int64ToBigInt(JSThread *thread, const int64_t &number); static JSHandle Uint64ToBigInt(JSThread *thread, const uint64_t &number); int64_t ToInt64(); + uint64_t ToUint64(); static void BigIntToInt64(JSThread *thread, JSHandle bigint, int64_t *cValue, bool *lossless); static void BigIntToUint64(JSThread *thread, JSHandle bigint, uint64_t *cValue, bool *lossless); static JSHandle CreateBigWords(JSThread *thread, bool sign, uint32_t size, const uint64_t* words); @@ -90,27 +91,52 @@ public: static JSTaggedValue AsintN(JSThread *thread, JSTaggedNumber &bits, JSHandle bigint); static JSTaggedNumber BigIntToNumber(JSHandle bigint); static ComparisonResult CompareWithNumber(JSHandle bigint, JSHandle number); + static inline size_t ComputeSize(uint32_t length) + { + return DATA_OFFSET + sizeof(uint32_t) * length; + } + + inline uint32_t *GetData() const + { + return reinterpret_cast(ToUintPtr(this) + DATA_OFFSET); + } + + inline void InitializationZero() + { + uint32_t size = GetLength() * sizeof(uint32_t); + if (memset_s(GetData(), size, 0, size) != EOK) { + LOG_FULL(FATAL) << "memset failed"; + UNREACHABLE(); + } + } inline bool IsZero() { return GetLength() == 1 && !GetDigit(0); } - uint32_t GetDigit(uint32_t index) const; - static void SetDigit(JSThread* thread, JSHandle bigint, uint32_t index, uint32_t digit); + inline uint32_t GetDigit(uint32_t index) const + { + ASSERT(index < GetLength()); + return Barriers::GetDynValue(GetData(), sizeof(uint32_t) * index); + } - uint32_t GetLength() const; + inline void SetDigit(uint32_t index, uint32_t digit) + { + ASSERT(index < GetLength()); + Barriers::SetDynPrimitive(GetData(), sizeof(uint32_t) * index, digit); + } - static constexpr size_t DATA_OFFSET = TaggedObjectSize(); - ACCESSORS(Data, DATA_OFFSET, BIT_FIELD_OFFSET); + static constexpr size_t LENGTH_OFFSET = TaggedObjectSize(); + ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, BIT_FIELD_OFFSET) ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) DEFINE_ALIGN_SIZE(LAST_OFFSET); + static constexpr size_t DATA_OFFSET = SIZE; // define BitField static constexpr size_t SIGN_BITS = 1; FIRST_BIT_FIELD(BitField, Sign, bool, SIGN_BITS) - DECL_VISIT_OBJECT(DATA_OFFSET, BIT_FIELD_OFFSET) DECL_DUMP() private: @@ -135,5 +161,6 @@ public: static uint32_t AddHelper(uint32_t x, uint32_t y, uint32_t &bigintCarry); static uint32_t SubHelper(uint32_t x, uint32_t y, uint32_t &bigintCarry); }; +static_assert((BigInt::DATA_OFFSET % static_cast(MemAlignment::MEM_ALIGN_OBJECT)) == 0); } // namespace panda::ecmascript #endif // ECMASCRIPT_TAGGED_BIGINT_H \ No newline at end of file diff --git a/ecmascript/js_date.cpp b/ecmascript/js_date.cpp index cdba579a3449388f611ef2ef9c8a25fe3f458437..9981f9215dc748f83e3cc87961bffbdd9a99e980 100644 --- a/ecmascript/js_date.cpp +++ b/ecmascript/js_date.cpp @@ -544,7 +544,7 @@ JSTaggedValue JSDate::UTC(EcmaRuntimeCallInfo *argv) year = base::NAN_VALUE; } uint32_t index = 1; - uint32_t numArgs = argv->GetArgsNumber(); + uint32_t numArgs = static_cast(argv->GetArgsNumber()); JSTaggedValue res; if (numArgs > index) { JSHandle value = base::BuiltinsBase::GetCallArg(argv, index); @@ -966,7 +966,7 @@ JSTaggedValue JSDate::SetDateValue(EcmaRuntimeCallInfo *argv, uint32_t code, boo double timeMs = this->GetTimeValue().GetDouble(); // get values from argv. - uint32_t argc = argv->GetArgsNumber(); + uint32_t argc = static_cast(argv->GetArgsNumber()); if (argc == 0) { return JSTaggedValue(base::NAN_VALUE); } diff --git a/ecmascript/js_finalization_registry.cpp b/ecmascript/js_finalization_registry.cpp index 8951fd820d83797364fcbf8bab1f63147d88386a..1f32b2afdaa629d5db4d9e0c27220dd66ebc21a2 100644 --- a/ecmascript/js_finalization_registry.cpp +++ b/ecmascript/js_finalization_registry.cpp @@ -140,7 +140,10 @@ void JSFinalizationRegistry::CleanFinRegLists(JSThread *thread, JSHandleGetCheckAndCallEnterState()) { + return; + } + CheckAndCallScope scope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle prev = env->GetFinRegLists(); @@ -228,14 +231,6 @@ bool JSFinalizationRegistry::CleanupFinalizationRegistry(JSThread *thread, JSHan continue; } maybeUnregister->RemoveEntry(thread, index - 1); - // Maybe add or delete - JSTaggedValue nextTable = maybeUnregister->GetNextTable(); - while (!nextTable.IsHole()) { - index -= maybeUnregister->GetDeletedElementsAt(index); - maybeUnregister.Update(nextTable); - nextTable = maybeUnregister->GetNextTable(); - } - totalElements = maybeUnregister->NumberOfElements() + maybeUnregister->NumberOfDeletedElements(); } } JSHandle newMap = LinkedHashMap::Shrink(thread, maybeUnregister); diff --git a/ecmascript/js_finalization_registry.h b/ecmascript/js_finalization_registry.h index fff20249e9a17f4938baa0180604daaed7d4a41e..68edf9709770bf84088ca69472d0490115f48035 100644 --- a/ecmascript/js_finalization_registry.h +++ b/ecmascript/js_finalization_registry.h @@ -21,13 +21,13 @@ #include "ecmascript/weak_vector.h" namespace panda::ecmascript { -class CheckAndCallScrop { +class CheckAndCallScope { public: - CheckAndCallScrop(JSThread *thread) : thread_(thread) + CheckAndCallScope(JSThread *thread) : thread_(thread) { thread_->SetCheckAndCallEnterState(true); } - ~CheckAndCallScrop() + ~CheckAndCallScope() { thread_->SetCheckAndCallEnterState(false); } @@ -63,7 +63,7 @@ public: class CellRecordVector : public WeakVector { public: - static CellRecordVector *Cast(ObjectHeader *object) + static CellRecordVector *Cast(TaggedObject *object) { return static_cast(object); } diff --git a/ecmascript/js_function.cpp b/ecmascript/js_function.cpp index 8f3db64acfdb91d25d51b9f3fb6414175679a74e..d1ac0f91f1af5c96d9840f22e4d1fa0dd3c791b0 100644 --- a/ecmascript/js_function.cpp +++ b/ecmascript/js_function.cpp @@ -249,7 +249,7 @@ bool JSFunction::MakeConstructor(JSThread *thread, const JSHandle &f JSTaggedValue JSFunction::Call(EcmaRuntimeCallInfo *info) { - if (info == nullptr || (info->GetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -264,7 +264,7 @@ JSTaggedValue JSFunction::Call(EcmaRuntimeCallInfo *info) } auto *hclass = func->GetTaggedObject()->GetClass(); - if (!hclass->IsBuiltinsCtor() && hclass->IsClassConstructor()) { + if (hclass->IsClassConstructor()) { THROW_TYPE_ERROR_AND_RETURN(thread, "class constructor cannot call", JSTaggedValue::Exception()); } return EcmaInterpreter::Execute(info); @@ -272,7 +272,7 @@ JSTaggedValue JSFunction::Call(EcmaRuntimeCallInfo *info) JSTaggedValue JSFunction::Construct(EcmaRuntimeCallInfo *info) { - if (info == nullptr || (info->GetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -287,12 +287,19 @@ JSTaggedValue JSFunction::Construct(EcmaRuntimeCallInfo *info) THROW_TYPE_ERROR_AND_RETURN(thread, "Constructor is false", JSTaggedValue::Exception()); } - return JSFunction::ConstructInternal(info); + if (func->IsJSFunction()) { + return JSFunction::ConstructInternal(info); + } else if (func->IsJSProxy()) { + return JSProxy::ConstructInternal(info); + } else { + ASSERT(func->IsBoundFunction()); + return JSBoundFunction::ConstructInternal(info); + } } JSTaggedValue JSFunction::Invoke(EcmaRuntimeCallInfo *info, const JSHandle &key) { - if (info == nullptr || (info->GetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -300,6 +307,7 @@ JSTaggedValue JSFunction::Invoke(EcmaRuntimeCallInfo *info, const JSHandleGetThread(); JSHandle thisArg = info->GetThis(); JSHandle func(JSTaggedValue::GetProperty(thread, thisArg, key).GetValue()); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); info->SetFunction(func.GetTaggedValue()); return JSFunction::Call(info); } @@ -307,7 +315,7 @@ JSTaggedValue JSFunction::Invoke(EcmaRuntimeCallInfo *info, const JSHandleGetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -320,7 +328,7 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) } JSHandle obj(thread, JSTaggedValue::Undefined()); - if (!func->IsBuiltinsConstructor() && func->IsBase()) { + if (func->IsBase()) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); obj = JSHandle(factory->NewJSObjectByConstructor(func, newTarget)); } @@ -329,7 +337,7 @@ JSTaggedValue JSFunction::ConstructInternal(EcmaRuntimeCallInfo *info) JSTaggedValue resultValue = EcmaInterpreter::Execute(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); // 9.3.2 [[Construct]] (argumentsList, newTarget) - if (func->IsBuiltinsConstructor() || resultValue.IsECMAObject()) { + if (resultValue.IsECMAObject()) { return resultValue; } @@ -431,19 +439,20 @@ JSTaggedValue JSBoundFunction::ConstructInternal(EcmaRuntimeCallInfo *info) } JSHandle boundArgs(thread, func->GetBoundArguments()); - const size_t boundLength = boundArgs->GetLength(); - const size_t argsLength = info->GetArgsNumber() + boundLength; + const int32_t boundLength = static_cast(boundArgs->GetLength()); + const int32_t argsLength = info->GetArgsNumber() + boundLength; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo runtimeInfo = - EcmaInterpreter::NewRuntimeCallInfo(thread, target, undefined, newTargetMutable, argsLength); + EcmaRuntimeCallInfo *runtimeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, target, undefined, newTargetMutable, argsLength); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (boundLength == 0) { - runtimeInfo.SetCallArg(argsLength, 0, info, 0); + runtimeInfo->SetCallArg(argsLength, 0, info, 0); } else { // 0 ~ boundLength is boundArgs; boundLength ~ argsLength is args of EcmaRuntimeCallInfo. - runtimeInfo.SetCallArg(boundLength, boundArgs); - runtimeInfo.SetCallArg(argsLength, boundLength, info, 0); + runtimeInfo->SetCallArg(boundLength, boundArgs); + runtimeInfo->SetCallArg(argsLength, boundLength, info, 0); } - return JSFunction::Construct(&runtimeInfo); + return JSFunction::Construct(runtimeInfo); } void JSProxyRevocFunction::ProxyRevocFunctions(const JSThread *thread, const JSHandle &revoker) @@ -503,7 +512,7 @@ void JSFunction::SetFunctionNameNoPrefix(JSThread *thread, JSFunction *func, JST GetHandledRightSquareBracketString()); concatName = factory->ConcatFromString( leftBrackets, - JSHandle(thread, JSSymbol::Cast(nameBegin->GetHeapObject())->GetDescription())); + JSHandle(thread, JSSymbol::Cast(nameBegin->GetTaggedObject())->GetDescription())); concatName = factory->ConcatFromString(concatName, rightBrackets); nameHandle.Update(concatName.GetTaggedValue()); } diff --git a/ecmascript/js_function.h b/ecmascript/js_function.h index d9c25f827b5087a503a5013a0c9e0ebcffb96e1c..b6af3365d8038bb14eb01801cf7883b66ae95cd5 100644 --- a/ecmascript/js_function.h +++ b/ecmascript/js_function.h @@ -23,7 +23,7 @@ namespace panda::ecmascript { class JSThread; -class EcmaRuntimeCallInfo; +struct EcmaRuntimeCallInfo; class JSFunctionBase : public JSObject { public: @@ -58,7 +58,6 @@ public: static constexpr int PROTOTYPE_INLINE_PROPERTY_INDEX = 2; static constexpr int CLASS_PROTOTYPE_INLINE_PROPERTY_INDEX = 1; - /* -------------- Common API Begin, Don't change those interface!!! ----------------- */ CAST_CHECK(JSFunction, IsJSFunction); static void InitializeJSFunction(JSThread *thread, const JSHandle &env, const JSHandle &func, @@ -161,17 +160,19 @@ public: inline static bool IsConstructorKind(FunctionKind kind) { - return (kind >= FunctionKind::BUILTIN_PROXY_CONSTRUCTOR) && (kind <= FunctionKind::DERIVED_CONSTRUCTOR); + return (kind >= FunctionKind::BASE_CONSTRUCTOR) && (kind <= FunctionKind::DERIVED_CONSTRUCTOR); } - inline static bool IsBuiltinConstructor(FunctionKind kind) + inline bool IsBuiltinConstructor() { + FunctionKind kind = GetFunctionKind(); return kind >= FunctionKind::BUILTIN_PROXY_CONSTRUCTOR && kind <= FunctionKind::BUILTIN_CONSTRUCTOR; } inline static bool HasPrototype(FunctionKind kind) { - return kind >= FunctionKind::BUILTIN_CONSTRUCTOR && kind <= FunctionKind::GENERATOR_FUNCTION; + return (kind >= FunctionKind::BASE_CONSTRUCTOR) && (kind <= FunctionKind::GENERATOR_FUNCTION) + && (kind != FunctionKind::BUILTIN_PROXY_CONSTRUCTOR); } inline static bool HasAccessor(FunctionKind kind) @@ -189,7 +190,16 @@ public: GetClass()->SetClassConstructor(flag); } - /* -------------- Common API End, Don't change those interface!!! ----------------- */ + // add for AOT + inline void SetCodeEntryAndMarkAOT(const uintptr_t codeEntry) + { + auto method = GetMethod(); + ASSERT(method != nullptr); + method->SetAotCodeBit(true); + method->SetNativeBit(false); + SetCodeEntry(codeEntry); + } + static void InitializeJSFunction(JSThread *thread, const JSHandle &func, FunctionKind kind = FunctionKind::NORMAL_FUNCTION, bool strict = true); static JSHClass *GetOrCreateInitialJSHClass(JSThread *thread, const JSHandle &fun); @@ -310,6 +320,70 @@ public: DECL_DUMP() }; +// PromiseAnyRejectElementFunction +class JSPromiseAnyRejectElementFunction : public JSFunction { +public: + CAST_CHECK(JSPromiseAnyRejectElementFunction, IsJSPromiseAnyRejectElementFunction); + + static constexpr size_t ERRORS_OFFSET = JSFunction::SIZE; + + ACCESSORS(Errors, ERRORS_OFFSET, CAPABILITY_OFFSET); + ACCESSORS(Capability, CAPABILITY_OFFSET, REMAINING_ELEMENTS_OFFSET); + ACCESSORS(RemainingElements, REMAINING_ELEMENTS_OFFSET, ALREADY_CALLED_OFFSET); + ACCESSORS(AlreadyCalled, ALREADY_CALLED_OFFSET, INDEX_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(Index, uint32_t, INDEX_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, ERRORS_OFFSET, INDEX_OFFSET) + + DECL_DUMP() +}; + +// PromiseAllSettledElementFunction +class JSPromiseAllSettledElementFunction : public JSFunction { +public: + CAST_CHECK(JSPromiseAllSettledElementFunction, IsJSPromiseAllSettledElementFunction); + + static constexpr size_t ALREADY_CALLED_OFFSET = JSFunction::SIZE; + ACCESSORS(AlreadyCalled, ALREADY_CALLED_OFFSET, VALUES_OFFSET); + ACCESSORS(Values, VALUES_OFFSET, CAPABILITY_OFFSET); + ACCESSORS(Capability, CAPABILITY_OFFSET, REMAINING_ELEMENTS_OFFSET); + ACCESSORS(RemainingElements, REMAINING_ELEMENTS_OFFSET, INDEX_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(Index, uint32_t, INDEX_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, ALREADY_CALLED_OFFSET, INDEX_OFFSET) + + DECL_DUMP() +}; + +// PromiseFinallyFunction +class JSPromiseFinallyFunction : public JSFunction { +public: + CAST_CHECK(JSPromiseFinallyFunction, IsJSPromiseFinallyFunction); + + static constexpr size_t CONSTRUCTOR_OFFSET = JSFunction::SIZE; + ACCESSORS(Constructor, CONSTRUCTOR_OFFSET, ONFINALLY_OFFSET); + ACCESSORS(OnFinally, ONFINALLY_OFFSET, SIZE); + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, CONSTRUCTOR_OFFSET, SIZE) + + DECL_DUMP() +}; + +// ValueThunkOrThrowReason +class JSPromiseValueThunkOrThrowerFunction : public JSFunction { +public: + CAST_CHECK(JSPromiseValueThunkOrThrowerFunction, IsJSPromiseValueThunkOrThrowerFunction); + + static constexpr size_t RESULT_OFFSET = JSFunction::SIZE; + ACCESSORS(Result, RESULT_OFFSET, SIZE); + + DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSFunction, RESULT_OFFSET, SIZE) + + DECL_DUMP() +}; + class JSIntlBoundFunction : public JSFunction { public: CAST_CHECK(JSIntlBoundFunction, IsJSIntlBoundFunction); diff --git a/ecmascript/js_function_kind.h b/ecmascript/js_function_kind.h index bfb424bb190606831d210d240822f89108b0405d..4dd64b8f74ed41965496f88f3cdad5e615b65be3 100644 --- a/ecmascript/js_function_kind.h +++ b/ecmascript/js_function_kind.h @@ -28,9 +28,6 @@ enum class FunctionKind : uint8_t { // END arrow functions ASYNC_FUNCTION, // END async functions - // BEGIN constructable functions - BUILTIN_PROXY_CONSTRUCTOR, - BUILTIN_CONSTRUCTOR, // BEGIN base constructors BASE_CONSTRUCTOR, // BEGIN default constructors @@ -38,6 +35,9 @@ enum class FunctionKind : uint8_t { // BEGIN class constructors CLASS_CONSTRUCTOR, // END base constructors + // BEGIN constructable functions + BUILTIN_PROXY_CONSTRUCTOR, + BUILTIN_CONSTRUCTOR, // END default constructors DERIVED_CONSTRUCTOR, // END class constructors diff --git a/ecmascript/js_global_object.h b/ecmascript/js_global_object.h index 7fdbb07a1dafca5424149ddf8d08828a35ead044..bd9a3a288f40e7e0c4c43fc6e1bde2eabd4bf512 100644 --- a/ecmascript/js_global_object.h +++ b/ecmascript/js_global_object.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSGlobalObject : public JSObject { public: - static JSGlobalObject *Cast(ObjectHeader *object) + static JSGlobalObject *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsECMAObject()); return static_cast(object); diff --git a/ecmascript/js_handle.h b/ecmascript/js_handle.h index 86506c349492690801504f1f8212cdf8037b1e2a..a463e4dcb82a4fe64130d51f55e566d07ee42cc8 100644 --- a/ecmascript/js_handle.h +++ b/ecmascript/js_handle.h @@ -85,11 +85,6 @@ public: address_ = EcmaHandleScope::NewHandle(const_cast(thread), value.GetRawData()); } - explicit JSHandle(const JSThread *thread, const ObjectHeader *value) - { - address_ = EcmaHandleScope::NewHandle(const_cast(thread), JSTaggedValue(value).GetRawData()); - } - explicit JSHandle(const JSThread *thread, const TaggedObject *value) { address_ = EcmaHandleScope::NewHandle(const_cast(thread), JSTaggedValue(value).GetRawData()); diff --git a/ecmascript/js_hclass-inl.h b/ecmascript/js_hclass-inl.h index 65b9b471f6461ab5b2b9afdbd9a12e31c857c7d0..000ea15ae24dcb4ae5eaf0b6eb66d411d3a4e336 100644 --- a/ecmascript/js_hclass-inl.h +++ b/ecmascript/js_hclass-inl.h @@ -187,6 +187,10 @@ inline size_t JSHClass::SizeFromJSHClass(TaggedObject *header) size = reinterpret_cast(header)->GetMachineCodeObjectSize(); size = AlignUp(size, static_cast(MemAlignment::MEM_ALIGN_OBJECT)); break; + case JSType::BIGINT: + size = BigInt::ComputeSize(reinterpret_cast(header)->GetLength()); + size = AlignUp(size, static_cast(MemAlignment::MEM_ALIGN_OBJECT)); + break; default: ASSERT(GetObjectSize() != 0); size = GetObjectSize(); diff --git a/ecmascript/js_hclass.cpp b/ecmascript/js_hclass.cpp index 756e2241dfa863c0f693de87db897c8d42f54722..50b38e52155ec6d3e4095d0cc60d3124bd5a301d 100644 --- a/ecmascript/js_hclass.cpp +++ b/ecmascript/js_hclass.cpp @@ -233,12 +233,11 @@ void JSHClass::AddProperty(const JSThread *thread, const JSHandle &obj if (layoutInfoHandle->NumberOfElements() != static_cast(offset)) { layoutInfoHandle.Update(factory->CopyAndReSort(layoutInfoHandle, offset, offset + 1)); - newJshclass->SetLayout(thread, layoutInfoHandle); } else if (layoutInfoHandle->GetPropertiesCapacity() <= static_cast(offset)) { // need to Grow layoutInfoHandle.Update( factory->ExtendLayoutInfo(layoutInfoHandle, LayoutInfo::ComputeGrowCapacity(offset))); - newJshclass->SetLayout(thread, layoutInfoHandle); } + newJshclass->SetLayout(thread, layoutInfoHandle); layoutInfoHandle->AddKey(thread, offset, key.GetTaggedValue(), attr); } @@ -336,7 +335,9 @@ JSHandle JSHClass::TransProtoWithoutLayout(const JSThread *thread, con void JSHClass::SetPrototype(const JSThread *thread, JSTaggedValue proto) { if (proto.IsECMAObject()) { - JSObject::Cast(proto.GetTaggedObject())->GetJSHClass()->SetIsPrototype(true); + auto hclass = proto.GetTaggedObject()->GetClass(); + ASSERT(!Region::ObjectAddressToRange(reinterpret_cast(hclass))->InReadOnlySpace()); + hclass->SetIsPrototype(true); } SetProto(thread, proto); } diff --git a/ecmascript/js_hclass.h b/ecmascript/js_hclass.h index 9bf24151d1b87df7973762beaed57cf692ce6a1d..8ebeece02443e4f881c13a057658788f8e0ab86c 100644 --- a/ecmascript/js_hclass.h +++ b/ecmascript/js_hclass.h @@ -71,6 +71,10 @@ class ProtoChangeDetails; JS_PROMISE_REACTIONS_FUNCTION, /* /////////////////////////////////////////////////////////////////-PADDING */ \ JS_PROMISE_EXECUTOR_FUNCTION, /* /////////////////////////////////////////////////////////////////-PADDING */ \ JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION, /* //////////////////////////////////////////////////////-PADDING */ \ + JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION, /* ///////////////////////////////////////////////////////-PADDING */ \ + JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION, /* //////////////////////////////////////////////////////-PADDING */ \ + JS_PROMISE_FINALLY_FUNCTION, /* //////////////////////////////////////////////////////////////////-PADDING */ \ + JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION, /* ///////////////////////////////////////////////////-PADDING */ \ JS_GENERATOR_FUNCTION, /* /////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_ASYNC_FUNCTION, /* /////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_INTL_BOUND_FUNCTION, /* ////////////////////////////////////////////////////////////////////////-PADDING */ \ @@ -82,6 +86,7 @@ class ProtoChangeDetails; JS_RANGE_ERROR, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_REFERENCE_ERROR, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_TYPE_ERROR, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ + JS_AGGREGATE_ERROR, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_URI_ERROR, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_SYNTAX_ERROR, /* JS_ERROR_END /////////////////////////////////////////////////////////////////////// */ \ \ @@ -100,6 +105,8 @@ class ProtoChangeDetails; JS_REG_EXP_ITERATOR, /* ////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_ARRAYLIST_ITERATOR, /* /////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_DEQUE_ITERATOR, /* ///////////////////////////////////////////////////////////////////////-PADDING */ \ + JS_API_LIGHT_WEIGHT_MAP_ITERATOR, /* //////////////////////////////////////////////////////////////-PADDING */ \ + JS_API_LIGHT_WEIGHT_SET_ITERATOR, /* /////////////////////////////////////////////////////////////-PADDING */ \ JS_API_PLAIN_ARRAY_ITERATOR, /* //////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_QUEUE_ITERATOR, /* ///////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_STACK_ITERATOR, /* ///////////////////////////////////////////////////////////////////////-PADDING */ \ @@ -131,6 +138,8 @@ class ProtoChangeDetails; /* SPECIAL indexed objects begin, DON'T CHANGE HERE ///////////////////////////////////////////////-PADDING */ \ JS_ARRAY, /* ////////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_ARRAY_LIST, /* /////////////////////////////////////////////////////////////////////////////-PADDING */ \ + JS_API_LIGHT_WEIGHT_MAP, /* //////////////////////////////////////////////////////////////////-PADDING */ \ + JS_API_LIGHT_WEIGHT_SET, /* ///////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_VECTOR, /* /////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_LINKED_LIST, /* ////////////////////////////////////////////////////////////////////////////-PADDING */ \ JS_API_LIST, /* /////////////////////////////////////////////////////////////////////////////-PADDING */ \ @@ -240,11 +249,10 @@ enum class JSType : uint8_t { class JSHClass : public TaggedObject { public: static constexpr int TYPE_BITFIELD_NUM = 8; - using ObjectTypeBits = BitField; // 7 + using ObjectTypeBits = BitField; // 8 using CallableBit = ObjectTypeBits::NextFlag; - using ConstructorBit = CallableBit::NextFlag; // 9 - using BuiltinsCtorBit = ConstructorBit::NextFlag; // 10 - using ExtensibleBit = BuiltinsCtorBit::NextFlag; + using ConstructorBit = CallableBit::NextFlag; // 10 + using ExtensibleBit = ConstructorBit::NextFlag; using IsPrototypeBit = ExtensibleBit::NextFlag; using ElementRepresentationBits = IsPrototypeBit::NextField; // 3 means next 3 bit using DictionaryElementBits = ElementRepresentationBits::NextFlag; // 16 @@ -254,6 +262,8 @@ public: using IsLiteralBit = HasConstructorBits::NextFlag; // 20 using ClassConstructorBit = IsLiteralBit::NextFlag; // 21 using ClassPrototypeBit = ClassConstructorBit::NextFlag; // 22 + using GlobalConstOrBuiltinsObjectBit = ClassPrototypeBit::NextFlag; // 23 + using IsTSTypeBit = GlobalConstOrBuiltinsObjectBit::NextFlag; // 24 static constexpr int DEFAULT_CAPACITY_OF_IN_OBJECTS = 4; static constexpr int MAX_CAPACITY_OF_OUT_OBJECTS = @@ -346,11 +356,6 @@ public: ConstructorBit::Set(flag, GetBitFieldAddr()); } - inline void SetBuiltinsCtor(bool flag) const - { - BuiltinsCtorBit::Set(flag, GetBitFieldAddr()); - } - inline void SetExtensible(bool flag) const { ExtensibleBit::Set(flag, GetBitFieldAddr()); @@ -376,11 +381,21 @@ public: ClassPrototypeBit::Set(flag, GetBitFieldAddr()); } + inline void SetGlobalConstOrBuiltinsObject(bool flag) const + { + GlobalConstOrBuiltinsObjectBit::Set(flag, GetBitFieldAddr()); + } + inline void SetIsDictionaryMode(bool flag) const { IsDictionaryBit::Set(flag, GetBitFieldAddr()); } + inline void SetTSType(bool flag) const + { + IsTSTypeBit::Set(flag, GetBitFieldAddr()); + } + inline bool IsJSObject() const { JSType jsType = GetObjectType(); @@ -567,6 +582,26 @@ public: return GetObjectType() == JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION; } + inline bool IsJSPromiseAnyRejectElementFunction() const + { + return GetObjectType() == JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION; + } + + inline bool IsJSPromiseAllSettledElementFunction() const + { + return GetObjectType() == JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION; + } + + inline bool IsJSPromiseFinallyFunction() const + { + return GetObjectType() == JSType::JS_PROMISE_FINALLY_FUNCTION; + } + + inline bool IsJSPromiseValueThunkOrThrowerFunction() const + { + return GetObjectType() == JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION; + } + inline bool IsMicroJobQueue() const { return GetObjectType() == JSType::MICRO_JOB_QUEUE; @@ -702,17 +737,30 @@ public: { return GetObjectType() == JSType::JS_API_ARRAYLIST_ITERATOR; } - + inline bool IsJSAPILightWeightMap() const + { + return GetObjectType() == JSType::JS_API_LIGHT_WEIGHT_MAP; + } + inline bool IsJSAPILightWeightMapIterator() const + { + return GetObjectType() == JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR; + } + inline bool IsJSAPILightWeightSet() const + { + return GetObjectType() == JSType::JS_API_LIGHT_WEIGHT_SET; + } + inline bool IsJSAPILightWeightSetIterator() const + { + return GetObjectType() == JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR; + } inline bool IsJSAPIStack() const { return GetObjectType() == JSType::JS_API_STACK; } - inline bool IsJSAPIDeque() const { return GetObjectType() == JSType::JS_API_DEQUE; } - inline bool IsJSAPIQueue() const { return GetObjectType() == JSType::JS_API_QUEUE; @@ -895,12 +943,6 @@ public: return ConstructorBit::Decode(bits); } - inline bool IsBuiltinsCtor() const - { - uint32_t bits = GetBitField(); - return BuiltinsCtorBit::Decode(bits); - } - inline bool IsExtensible() const { uint32_t bits = GetBitField(); @@ -936,12 +978,24 @@ public: return ClassPrototypeBit::Decode(bits); } + inline bool IsGlobalConstOrBuiltinsObject() const + { + uint32_t bits = GetBitField(); + return GlobalConstOrBuiltinsObjectBit::Decode(bits); + } + inline bool IsDictionaryMode() const { uint32_t bits = GetBitField(); return IsDictionaryBit::Decode(bits); } + inline bool IsTSType() const + { + uint32_t bits = GetBitField(); + return IsTSTypeBit::Decode(bits); + } + inline bool IsGeneratorFunction() const { return GetObjectType() == JSType::JS_GENERATOR_FUNCTION; @@ -1108,17 +1162,17 @@ public: return GetObjectType() == JSType::SOURCE_TEXT_MODULE_RECORD; } - inline bool IsJSCjsExports() const + inline bool IsCjsExports() const { return GetObjectType() == JSType::JS_CJS_EXPORTS; } - inline bool IsJSCjsModule() const + inline bool IsCjsModule() const { return GetObjectType() == JSType::JS_CJS_MODULE; } - inline bool IsJSCjsRequire() const + inline bool IsCjsRequire() const { return GetObjectType() == JSType::JS_CJS_REQUIRE; } @@ -1292,8 +1346,6 @@ public: } } - JSTaggedValue GetAccessor(const JSTaggedValue &key); - static constexpr size_t PROTOTYPE_OFFSET = TaggedObjectSize(); ACCESSORS(Proto, PROTOTYPE_OFFSET, LAYOUT_OFFSET); ACCESSORS(Layout, LAYOUT_OFFSET, TRANSTIONS_OFFSET); diff --git a/ecmascript/js_intl.h b/ecmascript/js_intl.h index 2b1de0b626ea6eb68b226dcdf6a3800ba5f96eae..7ae82587d0a8083184e901455a236e444cef2ccc 100644 --- a/ecmascript/js_intl.h +++ b/ecmascript/js_intl.h @@ -21,7 +21,7 @@ namespace panda::ecmascript { class JSIntl : public JSObject { public: - static JSIntl *Cast(ObjectHeader *object) + static JSIntl *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSIntl()); return static_cast(object); diff --git a/ecmascript/js_iterator.cpp b/ecmascript/js_iterator.cpp index 4480667e87eb20f4875ea77ad5f9676e2834644c..fe6b377eb870c10192ede28179af32a1ddce78e6 100644 --- a/ecmascript/js_iterator.cpp +++ b/ecmascript/js_iterator.cpp @@ -57,8 +57,8 @@ JSHandle JSIterator::GetIterator(JSThread *thread, const JSHandle RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, obj); // 3.Let iterator be Call(method,obj). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, obj, undefined, 0); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, obj, undefined, 0); + JSTaggedValue ret = JSFunction::Call(info); JSHandle iter(thread, ret); // 4.ReturnIfAbrupt(iterator). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, iter); @@ -77,8 +77,8 @@ JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandle key(globalConst->GetHandledNextString()); JSHandle next(JSObject::GetMethod(thread, iter, key)); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 0); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 0); + JSTaggedValue ret = JSFunction::Call(info); JSHandle result(thread, ret); // 3.ReturnIfAbrupt(result) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); @@ -97,9 +97,10 @@ JSHandle JSIterator::IteratorNext(JSThread *thread, const JSHandle key(globalConst->GetHandledNextString()); JSHandle next(JSObject::GetMethod(thread, iter, key)); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 1); - info.SetCallArg(value.GetTaggedValue()); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, next, iter, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, thread->GetEcmaVM()->GetFactory()->NewEmptyJSObject()); + info->SetCallArg(value.GetTaggedValue()); + JSTaggedValue ret = JSFunction::Call(info); JSHandle result(thread, ret); // 3.ReturnIfAbrupt(result) RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, result); @@ -173,8 +174,8 @@ JSHandle JSIterator::IteratorClose(JSThread *thread, const JSHand } // 6.Let innerResult be Call(return, iterator, «‍ »). JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, returnFunc, iter, undefined, 0); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, returnFunc, iter, undefined, 0); + JSTaggedValue ret = JSFunction::Call(info); if (!exceptionOnThread.IsEmpty()) { thread->SetException(exceptionOnThread.GetTaggedValue()); } diff --git a/ecmascript/js_locale.h b/ecmascript/js_locale.h index 58da78739f1aab69efc0e80b1b725403ca191f99..2ce3266f0beb644c86b014133fe6aa6cdb423972 100644 --- a/ecmascript/js_locale.h +++ b/ecmascript/js_locale.h @@ -150,7 +150,7 @@ public: std::string extension; }; - static JSLocale *Cast(ObjectHeader *object) + static JSLocale *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSLocale()); return static_cast(object); diff --git a/ecmascript/js_map_iterator.h b/ecmascript/js_map_iterator.h index 8a11bb6e3a8b5ad32bce27c57108ce1f345cdefa..9e39ee68ad7b582a2581911f0991aac14fb9d64b 100644 --- a/ecmascript/js_map_iterator.h +++ b/ecmascript/js_map_iterator.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSMapIterator : public JSObject { public: - static JSMapIterator *Cast(ObjectHeader *obj) + static JSMapIterator *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsJSMapIterator()); return static_cast(obj); diff --git a/ecmascript/js_method.h b/ecmascript/js_method.h index adc1630c08d2d2cc05788d5312b663fcb8c29297..0d29059f04a4747ba1cb5f781853ca9dd2f03387 100644 --- a/ecmascript/js_method.h +++ b/ecmascript/js_method.h @@ -129,6 +129,11 @@ struct PUBLIC_API JSMethod : public base::AlignedStruct= MAX_SLOT_SIZE) { literalInfo_ = SlotSizeBits::Update(literalInfo_, MAX_SLOT_SIZE); - return MAX_SLOT_SIZE; + return MAX_SLOT_SIZE - 1; // prevent solt + 1 overflow } literalInfo_ = SlotSizeBits::Update(literalInfo_, static_cast(end)); return start; diff --git a/ecmascript/js_native_pointer.h b/ecmascript/js_native_pointer.h index 7f71413d9252b7ba9f1d1cc2438d2aca65155be7..a842bcb431cb7e74aa4453f5acd50452ade264ee 100644 --- a/ecmascript/js_native_pointer.h +++ b/ecmascript/js_native_pointer.h @@ -25,7 +25,7 @@ using DeleteEntryPoint = void (*)(void *, void *); // Used for the requirement of ACE that wants to associated a registered C++ resource with a JSObject. class JSNativePointer : public TaggedObject { public: - static JSNativePointer *Cast(ObjectHeader *object) + static JSNativePointer *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSNativePointer()); return reinterpret_cast(object); diff --git a/ecmascript/js_number_format.cpp b/ecmascript/js_number_format.cpp index 84c20c952aaa834bca5678bed16f1177c9a13756..a44578d17674c1366f1395954a22a5500ab26698 100644 --- a/ecmascript/js_number_format.cpp +++ b/ecmascript/js_number_format.cpp @@ -508,9 +508,6 @@ void JSNumberFormat::InitializeNumberFormat(JSThread *thread, const JSHandle numberingSystemPtr(icu::NumberingSystem::createInstance(icuLocale, status)); - int32_t mnfdDefault = 0; int32_t mxfdDefault = 0; FractionDigitsOption fractionOptions = diff --git a/ecmascript/js_object-inl.h b/ecmascript/js_object-inl.h index aceba78b3078a48555360d1e9e37f65d01c6815d..9782a2ad89525cc80912a83583cd70ac6d1c67ac 100644 --- a/ecmascript/js_object-inl.h +++ b/ecmascript/js_object-inl.h @@ -23,16 +23,6 @@ #include "ecmascript/tagged_array-inl.h" namespace panda::ecmascript { -inline void ECMAObject::SetBuiltinsCtorMode() -{ - GetClass()->SetBuiltinsCtor(true); -} - -inline bool ECMAObject::IsBuiltinsConstructor() const -{ - return GetClass()->IsBuiltinsCtor(); -} - inline void ECMAObject::SetCallable(bool flag) { GetClass()->SetCallable(flag); diff --git a/ecmascript/js_object.cpp b/ecmascript/js_object.cpp index 62ca5f81e464cd5ba4221b5c0b7b721444c3386e..c0c70b3473f892989698c46bcec3dc80d9af1ba6 100644 --- a/ecmascript/js_object.cpp +++ b/ecmascript/js_object.cpp @@ -77,6 +77,48 @@ JSHandle JSObject::GrowElementsCapacity(const JSThread *thread, con return newElements; } +JSHandle JSObject::IterableToList(JSThread *thread, const JSHandle &items, + JSTaggedValue method) +{ + // 1. If method is present, then + // a. Let iteratorRecord be ? GetIterator(items, sync, method). + // 2. Else, + // a. Let iteratorRecord be ? GetIterator(items, sync). + JSHandle iteratorRecord; + JSHandle methodHandle(thread, method); + if (!methodHandle->IsUndefined()) { + iteratorRecord = JSIterator::GetIterator(thread, items, methodHandle); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + } else { + iteratorRecord = JSIterator::GetIterator(thread, items); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + } + // 3. Let values be a new empty List. + // 4. Let next be true. + JSHandle array = JSHandle::Cast(JSArray::ArrayCreate(thread, JSTaggedNumber(0))); + JSHandle valuesList = JSHandle::Cast(array); + JSMutableHandle next(thread, JSTaggedValue::True()); + // 5. Repeat, while next is not false, + // a. Set next to ? IteratorStep(iteratorRecord). + // b. If next is not false, then + // i. Let nextValue be ? IteratorValue(next). + // ii. Append nextValue to the end of the List values. + uint32_t k = 0; + while (!next->IsFalse()) { + next.Update(JSIterator::IteratorStep(thread, iteratorRecord).GetTaggedValue()); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + if (!next->IsFalse()) { + JSHandle nextValue(JSIterator::IteratorValue(thread, next)); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + JSArray::FastSetPropertyByValue(thread, valuesList, k, nextValue); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + k++; + } + } + // 6. Return values. + return valuesList; +} + bool JSObject::IsRegExp(JSThread *thread, const JSHandle &argument) { if (!argument->IsECMAObject()) { @@ -236,6 +278,10 @@ void JSObject::DeletePropertyInternal(JSThread *thread, const JSHandle } if (!array->IsDictionaryMode()) { + if (obj->GetJSHClass()->IsTSType()) { + obj->SetPropertyInlinedProps(thread, index, JSTaggedValue::Hole()); + return; + } JSHandle dictHandle(TransitionToDictionary(thread, obj)); int entry = dictHandle->FindEntry(key.GetTaggedValue()); ASSERT(entry != -1); @@ -258,7 +304,7 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, int end = static_cast(obj->GetJSHClass()->NumberOfProps()); if (end > 0) { LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject()) - ->GetAllKeys(thread, end, offset, *keyArray); + ->GetAllKeys(thread, end, offset, *keyArray, obj); } return; } @@ -273,8 +319,7 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, } // For Serialization use. Does not support JSGlobalObject -void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, - std::vector &keyVector) +void JSObject::GetAllKeys(const JSHandle &obj, std::vector &keyVector) { DISALLOW_GARBAGE_COLLECTION; ASSERT_PRINT(!obj->IsJSGlobalObject(), "Do not support get key of JSGlobal Object"); @@ -282,8 +327,7 @@ void JSObject::GetAllKeys(const JSThread *thread, const JSHandle &obj, if (!array->IsDictionaryMode()) { int end = static_cast(obj->GetJSHClass()->NumberOfProps()); if (end > 0) { - LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject()) - ->GetAllKeys(thread, end, keyVector); + LayoutInfo::Cast(obj->GetJSHClass()->GetLayout().GetTaggedObject())->GetAllKeys(end, keyVector, obj); } } else { NameDictionary *dict = NameDictionary::Cast(obj->GetProperties().GetTaggedObject()); @@ -315,7 +359,7 @@ JSHandle JSObject::GetAllEnumKeys(const JSThread *thread, const JSH int end = static_cast(jsHclass->NumberOfProps()); if (end > 0) { LayoutInfo::Cast(jsHclass->GetLayout().GetTaggedObject()) - ->GetAllEnumKeys(thread, end, offset, *keyArray, keys); + ->GetAllEnumKeys(thread, end, offset, *keyArray, keys, obj); if (*keys == keyArray->GetLength()) { jsHclass->SetEnumCache(thread, keyArray.GetTaggedValue()); } @@ -632,9 +676,10 @@ bool JSObject::CallSetter(JSThread *thread, const AccessorData &accessor, const JSHandle func(thread, setter); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, receiver, undefined, 1); - info.SetCallArg(value.GetTaggedValue()); - JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, receiver, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(value.GetTaggedValue()); + JSFunction::Call(info); // 10. ReturnIfAbrupt(setterResult). RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); @@ -653,8 +698,8 @@ JSTaggedValue JSObject::CallGetter(JSThread *thread, const AccessorData *accesso JSHandle func(thread, getter); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, receiver, undefined, 0); - JSTaggedValue res = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, receiver, undefined, 0); + JSTaggedValue res = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return res; } @@ -1156,16 +1201,16 @@ bool JSObject::CreateMethodProperty(JSThread *thread, const JSHandle & JSHandle JSObject::GetMethod(JSThread *thread, const JSHandle &obj, const JSHandle &key) { - JSTaggedValue func = FastRuntimeStub::FastGetProperty(thread, obj.GetTaggedValue(), key.GetTaggedValue()); - if (func.IsUndefined() || func.IsNull()) { + JSHandle func = JSTaggedValue::GetProperty(thread, obj, key).GetValue(); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); + if (func->IsUndefined() || func->IsNull()) { return JSHandle(thread, JSTaggedValue::Undefined()); } - JSHandle result(thread, func); - if (!result->IsCallable()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not Callable", result); + if (!func->IsCallable()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "obj is not Callable", func); } - return result; + return func; } // 7.3.14 SetIntegrityLevel (O, level) @@ -1357,7 +1402,8 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con key.Update(ownKeys->Get(thread, i)); if (key->IsString()) { PropertyDescriptor desc(thread); - bool status = GetOwnProperty(thread, obj, JSHandle(key), desc); + bool status = JSTaggedValue::GetOwnProperty(thread, JSHandle(obj), + key, desc); RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); if (status && desc.IsEnumerable()) { if (kind == PropertyKind::KEY) { @@ -1381,6 +1427,9 @@ JSHandle JSObject::EnumerableOwnPropertyNames(JSThread *thread, con } } } + if (UNLIKELY(index < length)) { + properties->Trim(thread, index); + } // 5. Return properties. return properties; } @@ -1409,10 +1458,10 @@ JSHandle JSObject::GetFunctionRealm(JSThread *thread, const JSHandle< return GetFunctionRealm(thread, proxyTarget); } JSTaggedValue maybeGlobalEnv = JSHandle(object)->GetLexicalEnv(); - if (maybeGlobalEnv.IsUndefined()) { - return thread->GetEcmaVM()->GetGlobalEnv(); - } while (!maybeGlobalEnv.IsJSGlobalEnv()) { + if (maybeGlobalEnv.IsUndefined()) { + return thread->GetEcmaVM()->GetGlobalEnv(); + } maybeGlobalEnv = LexicalEnv::Cast(maybeGlobalEnv.GetTaggedObject())->GetParentEnv(); } return JSHandle(thread, maybeGlobalEnv); @@ -1437,10 +1486,11 @@ bool JSObject::InstanceOf(JSThread *thread, const JSHandle &objec if (!instOfHandler->IsUndefined()) { // a. Return ! ToBoolean(? Call(instOfHandler, target, «object»)). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, instOfHandler, target, undefined, 1); - info.SetCallArg(object.GetTaggedValue()); - JSTaggedValue tagged = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(object.GetTaggedValue()); + JSTaggedValue tagged = JSFunction::Call(info); return tagged.ToBoolean(); } @@ -1674,7 +1724,8 @@ JSHandle JSObject::SpeciesConstructor(JSThread *thread, const JSH // Let C be Get(O, "constructor"). JSHandle contructorKey = globalConst->GetHandledConstructorString(); - JSHandle objConstructor(GetProperty(thread, JSHandle(obj), contructorKey).GetValue()); + JSHandle objConstructor(JSTaggedValue::GetProperty(thread, JSHandle(obj), + contructorKey).GetValue()); // ReturnIfAbrupt(C). RETURN_HANDLE_IF_ABRUPT_COMPLETION(JSTaggedValue, thread); // If C is undefined, return defaultConstructor. @@ -1866,7 +1917,7 @@ void ECMAObject::SetHash(int32_t hash) if (value.IsHeapObject()) { JSThread *thread = this->GetJSThread(); ASSERT(value.IsTaggedArray()); - TaggedArray *array = TaggedArray::Cast(value.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(value.GetTaggedObject()); array->Set(thread, 0, JSTaggedValue(hash)); } else { Barriers::SetDynPrimitive(this, HASH_OFFSET, JSTaggedValue(hash).GetRawData()); @@ -1878,7 +1929,7 @@ int32_t ECMAObject::GetHash() const JSTaggedType hashField = Barriers::GetDynValue(this, HASH_OFFSET); JSTaggedValue value(hashField); if (value.IsHeapObject()) { - TaggedArray *array = TaggedArray::Cast(value.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(value.GetTaggedObject()); return array->Get(0).GetInt(); } JSThread *thread = this->GetJSThread(); @@ -1931,7 +1982,7 @@ int32_t ECMAObject::GetNativePointerFieldCount() const JSTaggedType hashField = Barriers::GetDynValue(this, HASH_OFFSET); JSTaggedValue value(hashField); if (value.IsHeapObject()) { - TaggedArray *array = TaggedArray::Cast(value.GetHeapObject()); + TaggedArray *array = TaggedArray::Cast(value.GetTaggedObject()); len = static_cast(array->GetLength() - 1); } return len; diff --git a/ecmascript/js_object.h b/ecmascript/js_object.h index ffe8c978b703c3e8416879c07f647c5842f39cb3..fcca1c29b4501d527d5630dd9b2e9511be475800 100644 --- a/ecmascript/js_object.h +++ b/ecmascript/js_object.h @@ -326,8 +326,6 @@ class ECMAObject : public TaggedObject { public: CAST_CHECK(ECMAObject, IsECMAObject); - void SetBuiltinsCtorMode(); - bool IsBuiltinsConstructor() const; void SetCallable(bool flag); bool IsCallable() const; JSMethod *GetCallTarget() const; @@ -560,8 +558,7 @@ public: const JSHandle &properties); static void GetAllKeys(const JSThread *thread, const JSHandle &obj, int offset, const JSHandle &keyArray); - static void GetAllKeys(const JSThread *thread, const JSHandle &obj, - std::vector &keyVector); + static void GetAllKeys(const JSHandle &obj, std::vector &keyVector); static void GetAllElementKeys(JSThread *thread, const JSHandle &obj, int offset, const JSHandle &keyArray); static void GetALLElementKeysIntoVector(const JSThread *thread, const JSHandle &obj, @@ -603,6 +600,9 @@ public: static JSHandle GrowElementsCapacity(const JSThread *thread, const JSHandle &obj, uint32_t capacity); + static JSHandle IterableToList(JSThread *thread, const JSHandle &items, + JSTaggedValue method = JSTaggedValue::Undefined()); + protected: static void ElementsToDictionary(const JSThread *thread, JSHandle obj); diff --git a/ecmascript/js_promise.cpp b/ecmascript/js_promise.cpp index f35b2d3a2fe65522fd0ff4a704490e1bc5be641d..218d1c67d0b845c5f591420c50b2f9a4dfadd08a 100644 --- a/ecmascript/js_promise.cpp +++ b/ecmascript/js_promise.cpp @@ -18,6 +18,7 @@ #include "ecmascript/builtins/builtins_promise_handler.h" #include "ecmascript/ecma_macros.h" #include "ecmascript/global_env.h" +#include "ecmascript/interpreter/interpreter.h" #include "ecmascript/jobs/micro_job_queue.h" #include "ecmascript/js_function.h" #include "ecmascript/js_handle.h" @@ -98,9 +99,10 @@ JSHandle JSPromise::NewPromiseCapability(JSThread *thread, co // 6. Let promise be Construct(C, «executor»). // 7. ReturnIfAbrupt(promise). JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, obj, undefined, undefined, 1); - info.SetCallArg(executor.GetTaggedValue()); - JSTaggedValue result = JSFunction::Construct(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, obj, undefined, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, factory->NewPromiseCapability()); + info->SetCallArg(executor.GetTaggedValue()); + JSTaggedValue result = JSFunction::Construct(info); JSHandle promise(thread, result); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, factory->NewPromiseCapability()); // 8. If IsCallable(promiseCapability.[[Resolve]]) is false, throw a TypeError exception. diff --git a/ecmascript/js_proxy.cpp b/ecmascript/js_proxy.cpp index 87328e9f75a6c75d21532cced2e404693d9010f6..b7f56874ae9d22d0465c8d86765728a1708c8013 100644 --- a/ecmascript/js_proxy.cpp +++ b/ecmascript/js_proxy.cpp @@ -71,9 +71,10 @@ JSTaggedValue JSProxy::GetPrototype(JSThread *thread, const JSHandle &p } // 8. Let handlerProto be Call(trap, handler, «target»). JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handler, undefined, 1); - info.SetCallArg(targetHandle.GetTaggedValue()); - JSTaggedValue handlerProto = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handler, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(targetHandle.GetTaggedValue()); + JSTaggedValue handlerProto = JSFunction::Call(info); // 9. ReturnIfAbrupt(handlerProto). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); @@ -130,11 +131,12 @@ bool JSProxy::SetPrototype(JSThread *thread, const JSHandle &proxy, con return JSTaggedValue::SetPrototype(thread, targetHandle, proto); } JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 2; // 2: target and proto + const int32_t argsLength = 2; // 2: target and proto JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg(targetHandle.GetTaggedValue(), proto.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue(), proto.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, V»)). // If booleanTrapResult is false, return false @@ -192,9 +194,10 @@ bool JSProxy::IsExtensible(JSThread *thread, const JSHandle &proxy) JSHandle newTgt(thread, JSTaggedValue::Undefined()); JSHandle handlerTag(thread, proxy->GetHandler()); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1); - info.SetCallArg(targetHandle.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); bool booleanTrapResult = trapResult.ToBoolean(); // 9. ReturnIfAbrupt(booleanTrapResult). @@ -241,9 +244,10 @@ bool JSProxy::PreventExtensions(JSThread *thread, const JSHandle &proxy } JSHandle handlerTag(thread, proxy->GetHandler()); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1); - info.SetCallArg(targetHandle.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, 1); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); bool booleanTrapResult = trapResult.ToBoolean(); // 9. ReturnIfAbrupt(booleanTrapResult). @@ -292,11 +296,12 @@ bool JSProxy::GetOwnProperty(JSThread *thread, const JSHandle &proxy, c return JSTaggedValue::GetOwnProperty(thread, targetHandle, key, desc); } JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 2; // 2: target and key + const int32_t argsLength = 2; // 2: target and key JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue()); - JSTaggedValue trapResultObj = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue()); + JSTaggedValue trapResultObj = JSFunction::Call(info); JSHandle resultHandle(thread, trapResultObj); @@ -389,11 +394,12 @@ bool JSProxy::DefineOwnProperty(JSThread *thread, const JSHandle &proxy // 9. Let descObj be FromPropertyDescriptor(Desc). JSHandle descObj = JSObject::FromPropertyDescriptor(thread, desc); JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 3; // 3: target, key and desc + const int32_t argsLength = 3; // 3: target, key and desc JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue(), descObj.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue(), descObj.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); bool booleanTrapResult = trapResult.ToBoolean(); // 11. ReturnIfAbrupt(booleanTrapResult). @@ -476,11 +482,12 @@ bool JSProxy::HasProperty(JSThread *thread, const JSHandle &proxy, cons // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 2; // 2: target and key + const int32_t argsLength = 2; // 2: target and key JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); bool booleanTrapResult = trapResult.ToBoolean(); // 10. ReturnIfAbrupt(booleanTrapResult). @@ -536,11 +543,13 @@ OperationResult JSProxy::GetProperty(JSThread *thread, const JSHandle & } // 9. Let trapResult be Call(trap, handler, «target, P, Receiver»). JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 3; // 3: «target, P, Receiver» + const int32_t argsLength = 3; // 3: «target, P, Receiver» JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue(), receiver.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION( + thread, OperationResult(thread, exceptionHandle.GetTaggedValue(), PropertyMetaData(false))); + info->SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue(), receiver.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); JSHandle resultHandle(thread, trapResult); // 10. ReturnIfAbrupt(trapResult). @@ -605,12 +614,13 @@ bool JSProxy::SetProperty(JSThread *thread, const JSHandle &proxy, cons // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P, V, Receiver»)) JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 4; // 4: «target, P, V, Receiver» + const int32_t argsLength = 4; // 4: «target, P, V, Receiver» JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg( + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg( targetHandle.GetTaggedValue(), key.GetTaggedValue(), value.GetTaggedValue(), receiver.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + JSTaggedValue trapResult = JSFunction::Call(info); bool booleanTrapResult = trapResult.ToBoolean(); // 11. ReturnIfAbrupt(booleanTrapResult). @@ -664,11 +674,12 @@ bool JSProxy::DeleteProperty(JSThread *thread, const JSHandle &proxy, c // 9. Let booleanTrapResult be ToBoolean(Call(trap, handler, «target, P»)). JSHandle newTgt(thread, JSTaggedValue::Undefined()); JSHandle handlerTag(thread, proxy->GetHandler()); - const size_t argsLength = 2; // 2: target and key + const int32_t argsLength = 2; // 2: target and key JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); - info.SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue()); - JSTaggedValue trapResult = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerTag, undefined, argsLength); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, false); + info->SetCallArg(targetHandle.GetTaggedValue(), key.GetTaggedValue()); + JSTaggedValue trapResult = JSFunction::Call(info); bool booleanTrapResult = trapResult.ToBoolean(); // 11. ReturnIfAbrupt(booleanTrapResult). @@ -728,9 +739,11 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // 8.Let trapResultArray be Call(trap, handler, «target»). JSHandle tagFunc(targetHandle); JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerHandle, undefined, 1); - info.SetCallArg(targetHandle.GetTaggedValue()); - JSTaggedValue res = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, trap, handlerHandle, undefined, 1); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); + info->SetCallArg(targetHandle.GetTaggedValue()); + JSTaggedValue res = JSFunction::Call(info); + RETURN_HANDLE_IF_ABRUPT_COMPLETION(TaggedArray, thread); JSHandle trap_res_arr(thread, res); // 9.Let trapResult be CreateListFromArrayLike(trapResultArray, «String, Symbol»). @@ -845,7 +858,7 @@ JSHandle JSProxy::OwnPropertyKeys(JSThread *thread, const JSHandle< // ES6 9.5.13 [[Call]] (thisArgument, argumentsList) JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info) { - if (info == nullptr || (info->GetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -866,35 +879,39 @@ JSTaggedValue JSProxy::CallInternal(EcmaRuntimeCallInfo *info) // 6.ReturnIfAbrupt(trap). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + int32_t argc = info->GetArgsNumber(); + JSHandle thisArg = info->GetThis(); + JSHandle undefined = globalConst->GetHandledUndefined(); // 7.If trap is undefined, then // a.Return Call(target, thisArgument, argumentsList). if (method->IsUndefined()) { - info->SetFunction(target.GetTaggedValue()); - return JSFunction::Call(info); + EcmaRuntimeCallInfo *runtimeInfo = + EcmaInterpreter::NewRuntimeCallInfo(thread, target, thisArg, undefined, argc); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(argc, 0, info, 0); + return JSFunction::Call(runtimeInfo); } // 8.Let argArray be CreateArrayFromList(argumentsList). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - size_t argc = info->GetArgsNumber(); JSHandle taggedArray = factory->NewTaggedArray(static_cast(argc)); - for (size_t index = 0; index < argc; ++index) { + for (int32_t index = 0; index < argc; ++index) { taggedArray->Set(thread, index, info->GetCallArg(index)); } JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); // 9.Return Call(trap, handler, «target, thisArgument, argArray»). - JSHandle thisArg = info->GetThis(); - const size_t argsLength = 3; // 3: «target, thisArgument, argArray» - JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo runtimeInfo = + const int32_t argsLength = 3; // 3: «target, thisArgument, argArray» + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, method, handler, undefined, argsLength); - runtimeInfo.SetCallArg(target.GetTaggedValue(), thisArg.GetTaggedValue(), arrHandle.GetTaggedValue()); - return JSFunction::Call(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(target.GetTaggedValue(), thisArg.GetTaggedValue(), arrHandle.GetTaggedValue()); + return JSFunction::Call(runtimeInfo); } // ES6 9.5.14 [[Construct]] ( argumentsList, newTarget) JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info) { - if (info == nullptr || (info->GetArgsNumber() == INVALID_ARGS_NUMBER)) { + if (info == nullptr) { return JSTaggedValue::Exception(); } @@ -926,21 +943,22 @@ JSTaggedValue JSProxy::ConstructInternal(EcmaRuntimeCallInfo *info) // 8.Let argArray be CreateArrayFromList(argumentsList). ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - size_t argc = info->GetArgsNumber(); + int32_t argc = info->GetArgsNumber(); JSHandle taggedArray = factory->NewTaggedArray(static_cast(argc)); - for (size_t index = 0; index < argc; ++index) { + for (int32_t index = 0; index < argc; ++index) { taggedArray->Set(thread, index, info->GetCallArg(index)); } JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); // step 8 ~ 9 Call(trap, handler, «target, argArray, newTarget »). JSHandle newTarget(info->GetNewTarget()); - const size_t argsLength = 3; // 3: «target, argArray, newTarget » + const int32_t argsLength = 3; // 3: «target, argArray, newTarget » JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, method, handler, undefined, argsLength); - runtimeInfo.SetCallArg(target.GetTaggedValue(), arrHandle.GetTaggedValue(), newTarget.GetTaggedValue()); - JSTaggedValue newObj = JSFunction::Call(&runtimeInfo); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + runtimeInfo->SetCallArg(target.GetTaggedValue(), arrHandle.GetTaggedValue(), newTarget.GetTaggedValue()); + JSTaggedValue newObj = JSFunction::Call(runtimeInfo); // 10.ReturnIfAbrupt(newObj). RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); diff --git a/ecmascript/js_realm.h b/ecmascript/js_realm.h index 6d201190f26a908f086f31bc6504c83f8be0a415..56273c2e9663747e45abb83f714c73a196dbddc4 100644 --- a/ecmascript/js_realm.h +++ b/ecmascript/js_realm.h @@ -21,7 +21,7 @@ namespace panda::ecmascript { class JSRealm : public JSObject { public: - static JSRealm *Cast(ObjectHeader *object) + static JSRealm *Cast(TaggedObject *object) { return static_cast(object); } diff --git a/ecmascript/js_regexp.h b/ecmascript/js_regexp.h index b2452ca59646cc9f5641a18e8f63aa163f101441..1cce45515f5635d62a0b2935e7e299db3d83ec85 100644 --- a/ecmascript/js_regexp.h +++ b/ecmascript/js_regexp.h @@ -29,7 +29,8 @@ public: static constexpr size_t REGEXP_BYTE_CODE_OFFSET = JSObject::SIZE; ACCESSORS(ByteCodeBuffer, REGEXP_BYTE_CODE_OFFSET, ORIGINAL_SOURCE_OFFSET) ACCESSORS(OriginalSource, ORIGINAL_SOURCE_OFFSET, ORIGINAL_FLAGS_OFFSET) - ACCESSORS(OriginalFlags, ORIGINAL_FLAGS_OFFSET, LENGTH_OFFSET) + ACCESSORS(OriginalFlags, ORIGINAL_FLAGS_OFFSET, GROUP_NAME_OFFSET) + ACCESSORS(GroupName, GROUP_NAME_OFFSET, LENGTH_OFFSET) ACCESSORS_PRIMITIVE_FIELD(Length, uint32_t, LENGTH_OFFSET, LAST_OFFSET) DEFINE_ALIGN_SIZE(LAST_OFFSET); diff --git a/ecmascript/js_regexp_iterator.cpp b/ecmascript/js_regexp_iterator.cpp index 69d6a6c3f00c8229c05a1fb0ccd62624e6c606f0..a988d56a7cd86de44bc51a03b8bf48a2fcf1f104 100644 --- a/ecmascript/js_regexp_iterator.cpp +++ b/ecmascript/js_regexp_iterator.cpp @@ -90,9 +90,9 @@ JSTaggedValue JSRegExpIterator::Next(EcmaRuntimeCallInfo *argv) RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); uint32_t nextIndex = BuiltinsRegExp::AdvanceStringIndex(inputStr, thisIndex.ToUint32(), fullUnicode); - FastRuntimeStub::FastSetProperty(thread, regexHandle.GetTaggedValue(), - lastIndexString.GetTaggedValue(), - JSTaggedValue(nextIndex), true); + FastRuntimeStub::FastSetPropertyByValue(thread, regexHandle.GetTaggedValue(), + lastIndexString.GetTaggedValue(), + JSTaggedValue(nextIndex)); } // iii. Return ! CreateIterResultObject(match, false). return JSIterator::CreateIterResultObject(thread, matchHandle, false).GetTaggedValue(); diff --git a/ecmascript/js_runtime_options.h b/ecmascript/js_runtime_options.h index 8553997e40f372733c5eaffe1bfac09eea7e19ef..f4afde5c2a76ee039d5a7e510297445d58979aef 100644 --- a/ecmascript/js_runtime_options.h +++ b/ecmascript/js_runtime_options.h @@ -17,7 +17,6 @@ #define ECMASCRIPT_JS_RUNTIME_OPTIONS_H_ #include "libpandabase/utils/pandargs.h" -#include "utils/logger.h" // namespace panda { namespace panda::ecmascript { @@ -354,6 +353,16 @@ public: return heap_size_limit_.WasSet(); } + void SetIsWorker(bool isWorker) + { + isWorker_.SetValue(isWorker); + } + + bool IsWorker() const + { + return isWorker_.GetValue(); + } + bool EnableIC() const { return enableIC_.GetValue(); @@ -458,9 +467,8 @@ private: PandArg enableCpuprofiler_ {"enable-cpuprofiler", false, R"(Enable cpuprofiler to sample call stack and output to json file. Default: false)"}; PandArg stubFile_ {"stub-file", - STUB_FILE_GEN_DIR R"(stub.m)", - R"(Path of file includes common stubs module compiled by stub compiler. Default: )" - STUB_FILE_GEN_DIR R"(stub.m)"}; + R"(stub.m)", + R"(Path of file includes common stubs module compiled by stub compiler. Default: "stub.m")"}; PandArg enableForceGc_ {"enable-force-gc", true, R"(enable force gc when allocating object)"}; PandArg forceFullGc_ {"force-full-gc", true, @@ -500,7 +508,8 @@ private: PandArg startup_time_ {"startup-time", false, R"(Print the start time of command execution. Default: false)"}; PandArg logCompiledMethods {"log-compiled-methods", R"(none)", - R"(print stub or aot logs in units of method, "none": no log, "all": every method)"}; + R"(print stub or aot logs in units of method, "none": no log, "all": every method," + "asm": log all disassemble code)"}; PandArg snapshotOutputFile_ {"snapshot-output-file", R"(snapshot)", R"(Path to snapshot output file. Default: "snapshot")"}; @@ -508,6 +517,8 @@ private: R"(enable statistics of runtime state. Default: false)"}; PandArg logTypeInfer_ {"log-Type-Infer", false, R"(print aot type infer log. Default: false)"}; + PandArg isWorker_ {"IsWorker", false, + R"(whether is worker vm)"}; }; } // namespace panda::ecmascript diff --git a/ecmascript/js_serializer.cpp b/ecmascript/js_serializer.cpp index c7f01e9b2ea78ab85677ba61d099ec732a6a849c..fa750e2893dddc755b23de00adfa9407a569ef91 100644 --- a/ecmascript/js_serializer.cpp +++ b/ecmascript/js_serializer.cpp @@ -135,7 +135,7 @@ bool JSSerializer::WriteRawData(const void *data, size_t length) errno_t rc; rc = memcpy_s(buffer_ + bufferSize_, bufferCapacity_ - bufferSize_, data, length); if (rc != EOK) { - LOG(ERROR, RUNTIME) << "Failed to memcpy_s Data"; + LOG_FULL(ERROR) << "Failed to memcpy_s Data"; return false; } bufferSize_ += length; @@ -195,7 +195,7 @@ bool JSSerializer::ExpandBuffer(size_t requestedSize) errno_t rc; rc = memcpy_s(newBuffer, newCapacity, buffer_, bufferSize_); if (rc != EOK) { - LOG(ERROR, RUNTIME) << "Failed to memcpy_s Data"; + LOG_FULL(ERROR) << "Failed to memcpy_s Data"; free(newBuffer); return false; } @@ -261,6 +261,7 @@ bool JSSerializer::WriteTaggedObject(const JSHandle &value) case JSType::JS_RANGE_ERROR: case JSType::JS_REFERENCE_ERROR: case JSType::JS_TYPE_ERROR: + case JSType::JS_AGGREGATE_ERROR: case JSType::JS_URI_ERROR: case JSType::JS_SYNTAX_ERROR: return WriteJSError(value); @@ -341,6 +342,8 @@ bool JSSerializer::WriteJSErrorHeader(JSType type) return WriteType(SerializationUID::REFERENCE_ERROR); case JSType::JS_TYPE_ERROR: return WriteType(SerializationUID::TYPE_ERROR); + case JSType::JS_AGGREGATE_ERROR: + return WriteType(SerializationUID::AGGREGATE_ERROR); case JSType::JS_URI_ERROR: return WriteType(SerializationUID::URI_ERROR); case JSType::JS_SYNTAX_ERROR: @@ -660,30 +663,48 @@ bool JSSerializer::WriteJSArrayBuffer(const JSHandle &value) return true; } -bool JSSerializer::WritePlainObject(const JSHandle &objValue) +bool JSSerializer::IsNativeBindingObject(std::vector keyVector) { - JSHandle obj = JSHandle::Cast(objValue); - size_t oldSize = bufferSize_; - std::vector keyVector; - uint32_t propertiesLength = obj->GetNumberOfKeys(); - JSObject::GetAllKeys(thread_, obj, keyVector); - if (keyVector.size() != propertiesLength) { + if (keyVector.size() < 2) { // 2:detachSymbol, attachSymbol return false; } - - if (keyVector.size() >= 2 && (keyVector[0].IsSymbol() && keyVector[1].IsSymbol())) { // 2:attachSymbol, detachSymbol - return WriteNativeBindingObject(objValue, keyVector); + [[maybe_unused]] JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); + uint32_t keyLength = keyVector.size(); + for (uint32_t i = 0; i < keyLength - 1; i++) { + if (keyVector[i].IsSymbol() && keyVector[i + 1].IsSymbol()) { + JSHandle detach = env->GetDetachSymbol(); + JSHandle attach = env->GetAttachSymbol(); + if (JSTaggedValue::Equal(thread_, detach, JSHandle(thread_, keyVector[i])) || + JSTaggedValue::Equal(thread_, attach, JSHandle(thread_, keyVector[i + 1]))) { + return true; + } + } } - if (!WriteType(SerializationUID::JS_PLAIN_OBJECT)) { - return false; + return false; +} + +bool JSSerializer::IsTargetSymbol(JSTaggedValue symbolVal) +{ + JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); + JSHandle detach = env->GetDetachSymbol(); + JSHandle attach = env->GetAttachSymbol(); + if (JSTaggedValue::Equal(thread_, detach, JSHandle(thread_, symbolVal)) || + JSTaggedValue::Equal(thread_, attach, JSHandle(thread_, symbolVal))) { + return true; } - // Get the number of elements stored in obj + return false; +} + +bool JSSerializer::WriteAllKeys(const JSHandle &objValue) +{ + JSHandle obj = JSHandle::Cast(objValue); + size_t oldSize = bufferSize_; + std::vector keyVector; uint32_t elementsLength = obj->GetNumberOfElements(); if (!WriteInt(static_cast(elementsLength))) { bufferSize_ = oldSize; return false; } - keyVector.clear(); JSObject::GetALLElementKeysIntoVector(thread_, obj, keyVector); // Write elements' description attributes and value if (keyVector.size() != elementsLength) { @@ -708,13 +729,14 @@ bool JSSerializer::WritePlainObject(const JSHandle &objValue) return false; } } - // Get the number of k-v form properties stored in obj + + uint32_t propertiesLength = obj->GetNumberOfKeys(); keyVector.clear(); + JSObject::GetAllKeys(obj, keyVector); if (!WriteInt(static_cast(propertiesLength))) { bufferSize_ = oldSize; return false; } - JSObject::GetAllKeys(thread_, obj, keyVector); if (keyVector.size() != propertiesLength) { bufferSize_ = oldSize; return false; @@ -745,21 +767,48 @@ bool JSSerializer::WritePlainObject(const JSHandle &objValue) return true; } -bool JSSerializer::WriteNativeBindingObject( - const JSHandle &objValue, std::vector keyVector) +bool JSSerializer::WritePlainObject(const JSHandle &objValue) +{ + JSHandle obj = JSHandle::Cast(objValue); + std::vector keyVector; + uint32_t propertiesLength = obj->GetNumberOfKeys(); + JSObject::GetAllKeys(obj, keyVector); + if (keyVector.size() != propertiesLength) { + return false; + } + + if (IsNativeBindingObject(keyVector)) { + return WriteNativeBindingObject(objValue); + } + if (!WriteType(SerializationUID::JS_PLAIN_OBJECT)) { + return false; + } + return WriteAllKeys(objValue); +} + +bool JSSerializer::WriteNativeBindingObject(const JSHandle &objValue) { JSHandle obj = JSHandle::Cast(objValue); size_t oldSize = bufferSize_; JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); JSHandle detach = env->GetDetachSymbol(); JSHandle attach = env->GetAttachSymbol(); - if (!(JSTaggedValue::Equal(thread_, detach, JSHandle(thread_, keyVector[0]))) || - !(JSTaggedValue::Equal(thread_, attach, JSHandle(thread_, keyVector[1])))) { - return false; - } if (!WriteType(SerializationUID::NATIVE_BINDING_OBJECT)) { return false; } + int32_t paramCount = obj->GetNativePointerFieldCount(); + void *enginePointer = nullptr; + void *objPointer = nullptr; + void *hint = nullptr; + void *detachData = nullptr; + void *attachData = nullptr; + if (paramCount == 5) { // 5 : enginePointer, objPointer, hint, detachData, attachData + enginePointer = obj->GetNativePointerField(0); + objPointer = obj->GetNativePointerField(1); + hint = obj->GetNativePointerField(2); // 2 : hint + detachData = obj->GetNativePointerField(3); // 3 : detachData + attachData = obj->GetNativePointerField(4); // 4 : attachData + } // Write custom object's values: AttachFunc*, buffer* JSHandle detachVal = JSObject::GetProperty(thread_, obj, detach).GetRawValue(); JSHandle attackVal = JSObject::GetProperty(thread_, obj, attach).GetRawValue(); @@ -768,7 +817,7 @@ bool JSSerializer::WriteNativeBindingObject( if (detachNative == nullptr) { return false; } - void *buffer = detachNative(); + void *buffer = detachNative(enginePointer, objPointer, hint, detachData); AttachFunc attachNative = reinterpret_cast(JSNativePointer::Cast( attackVal.GetTaggedValue().GetTaggedObject())->GetExternalPointer()); if (!WriteRawData(&attachNative, sizeof(uintptr_t))) { @@ -779,43 +828,14 @@ bool JSSerializer::WriteNativeBindingObject( bufferSize_ = oldSize; return false; } - bool hasThirdKey = false; - if (keyVector.size() == 2) { // 2:attachSymbol, detachSymbol - if (!WriteBoolean(hasThirdKey)) { - return false; - } - return true; - } - - hasThirdKey = true; - if (!WriteBoolean(hasThirdKey)) { + if (!WriteRawData(&hint, sizeof(uintptr_t))) { + bufferSize_ = oldSize; return false; } - uint32_t propertiesLength = keyVector.size() - 2; - if (!WriteInt(static_cast(propertiesLength))) { + if (!WriteRawData(&attachData, sizeof(uintptr_t))) { bufferSize_ = oldSize; return false; } - // Write keys' description attributes and related values - for (uint32_t i = 0; i < propertiesLength; i++) { - JSMutableHandle key(thread_, keyVector[i + 2]); // 2:attachSymbol, detachSymbol - if (!SerializeJSTaggedValue(key)) { - bufferSize_ = oldSize; - return false; - } - PropertyDescriptor desc(thread_); - JSObject::OrdinaryGetOwnProperty(thread_, obj, key, desc); - if (!WriteDesc(desc)) { - bufferSize_ = oldSize; - return false; - } - JSHandle value = desc.GetValue(); - if (!SerializeJSTaggedValue(value)) { - bufferSize_ = oldSize; - return false; - } - } - return true; } @@ -950,6 +970,7 @@ JSHandle JSDeserializer::DeserializeJSTaggedValue() case SerializationUID::RANGE_ERROR: case SerializationUID::REFERENCE_ERROR: case SerializationUID::TYPE_ERROR: + case SerializationUID::AGGREGATE_ERROR: case SerializationUID::URI_ERROR: case SerializationUID::SYNTAX_ERROR: return ReadJSError(uid); @@ -1022,6 +1043,9 @@ JSHandle JSDeserializer::ReadJSError(SerializationUID uid) case SerializationUID::TYPE_ERROR: errorType = base::ErrorType::TYPE_ERROR; break; + case SerializationUID::AGGREGATE_ERROR: + errorType = base::ErrorType::AGGREGATE_ERROR; + break; case SerializationUID::URI_ERROR: errorType = base::ErrorType::URI_ERROR; break; @@ -1132,18 +1156,11 @@ JSHandle JSDeserializer::ReadPlainObject() JSHandle JSDeserializer::ReadNativeBindingObject() { - JSHandle env = thread_->GetEcmaVM()->GetGlobalEnv(); - JSHandle objFunc = env->GetObjectFunction(); - JSHandle jsObject = - thread_->GetEcmaVM()->GetFactory()->NewJSObjectByConstructor(JSHandle(objFunc), objFunc); - JSHandle objTag(jsObject); - referenceMap_.insert(std::pair(objectId_++, objTag)); - - uintptr_t pointer; - if (!ReadNativePointer(&pointer)) { + uintptr_t funcPointer; + if (!ReadNativePointer(&funcPointer)) { return JSHandle(); } - AttachFunc attachFunc = reinterpret_cast(pointer); + AttachFunc attachFunc = reinterpret_cast(funcPointer); if (attachFunc == nullptr) { return JSHandle(); } @@ -1151,39 +1168,21 @@ JSHandle JSDeserializer::ReadNativeBindingObject() if (!ReadNativePointer(&bufferPointer)) { return JSHandle(); } - void *buffer = reinterpret_cast(bufferPointer); - attachFunc(buffer); - bool hasThirdKey = false; - if (!ReadBoolean(&hasThirdKey)) { + uintptr_t hint; + if (!ReadNativePointer(&hint)) { return JSHandle(); } - if (!hasThirdKey) { - return objTag; - } - - int32_t propertyLength; - if (!JudgeType(SerializationUID::INT32) || !ReadInt(&propertyLength)) { + uintptr_t attachData; + if (!ReadNativePointer(&attachData)) { return JSHandle(); } - for (int32_t i = 0; i < propertyLength; i++) { - JSHandle key = DeserializeJSTaggedValue(); - if (key.IsEmpty()) { - return JSHandle(); - } - PropertyDescriptor desc(thread_); - if (!ReadDesc(&desc)) { - return JSHandle(); - } - JSHandle value = DeserializeJSTaggedValue(); - if (value.IsEmpty()) { - return JSHandle(); - } - desc.SetValue(value); - if (!JSTaggedValue::DefineOwnProperty(thread_, objTag, key, desc)) { - return JSHandle(); - } + Local attachVal = attachFunc(engine_, reinterpret_cast(bufferPointer), + reinterpret_cast(hint), reinterpret_cast(attachData)); + if (attachVal.IsEmpty()) { + LOG_ECMA(ERROR) << "NativeBindingObject is empty"; + attachVal = JSValueRef::Undefined(thread_->GetEcmaVM()); } - return objTag; + return JSNApiHelper::ToJSHandle(attachVal); } JSHandle JSDeserializer::ReadJSMap() @@ -1639,7 +1638,7 @@ bool Serializer::FinalizeTransfer(JSThread *thread, const JSHandle element = JSArray::FastGetPropertyByValue(thread, transfer, idx); - JSArrayBuffer::Cast(element->GetHeapObject())->Detach(thread); + JSArrayBuffer::Cast(element->GetTaggedObject())->Detach(thread); } return true; } diff --git a/ecmascript/js_serializer.h b/ecmascript/js_serializer.h index f6390834e165a7aa7f156419069e58001003c715..91d7bcce660626c35ed97269b9b0a7beea85838d 100644 --- a/ecmascript/js_serializer.h +++ b/ecmascript/js_serializer.h @@ -26,10 +26,13 @@ #include "ecmascript/js_thread.h" #include "ecmascript/js_typed_array.h" #include "ecmascript/mem/dyn_chunk.h" +#include "ecmascript/napi/jsnapi_helper.h" +#include "ecmascript/napi/include/jsnapi.h" +using panda::JSValueRef; namespace panda::ecmascript { -typedef void* (*DetachFunc)(void); -typedef void (*AttachFunc)(void* buffer); +typedef void* (*DetachFunc)(void *enginePointer, void *objPointer, void *hint, void *detachData); +typedef Local (*AttachFunc)(void *enginePointer, void *buffer, void *hint, void *attachData); enum class SerializationUID : uint8_t { // JS special values @@ -79,6 +82,7 @@ enum class SerializationUID : uint8_t { RANGE_ERROR, REFERENCE_ERROR, TYPE_ERROR, + AGGREGATE_ERROR, URI_ERROR, SYNTAX_ERROR, ERROR_MESSAGE_BEGIN, @@ -116,11 +120,14 @@ private: bool WriteJSRegExp(const JSHandle &value); bool WriteEcmaString(const JSHandle &value); bool WriteJSTypedArray(const JSHandle &value, SerializationUID uId); + bool WriteAllKeys(const JSHandle &value); bool WritePlainObject(const JSHandle &value); - bool WriteNativeBindingObject(const JSHandle &value, std::vector keyVector); + bool WriteNativeBindingObject(const JSHandle &value); bool WriteNativeFunctionPointer(const JSHandle &value); bool WriteJSArrayBuffer(const JSHandle &value); bool WriteDesc(const PropertyDescriptor &desc); + bool IsNativeBindingObject(std::vector keyVector); + bool IsTargetSymbol(JSTaggedValue symbolVal); bool IsSerialized(uintptr_t addr) const; bool WriteIfSerialized(uintptr_t addr); @@ -141,8 +148,9 @@ private: class JSDeserializer { public: // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - JSDeserializer(JSThread *thread, uint8_t *data, size_t size) - : thread_(thread), factory_(thread->GetEcmaVM()->GetFactory()), begin_(data), position_(data), end_(data + size) + JSDeserializer(JSThread *thread, uint8_t *data, size_t size, void *hint = nullptr) + : thread_(thread), factory_(thread->GetEcmaVM()->GetFactory()), + begin_(data), position_(data), end_(data + size), engine_(hint) { } ~JSDeserializer(); @@ -184,6 +192,7 @@ private: const uint8_t * const end_ = nullptr; uint64_t objectId_ = 0; std::map> referenceMap_; + void *engine_ = nullptr; }; class SerializationData { @@ -239,8 +248,8 @@ private: class Deserializer { public: - explicit Deserializer(JSThread *thread, SerializationData* data) - : valueDeserializer_(thread, data->GetData(), data->GetSize()) {} + explicit Deserializer(JSThread *thread, SerializationData *data, void *hint) + : valueDeserializer_(thread, data->GetData(), data->GetSize(), hint) {} ~Deserializer() = default; JSHandle ReadValue(); diff --git a/ecmascript/js_stable_array.cpp b/ecmascript/js_stable_array.cpp index f21586b02b9bafabc81f26ec005a3fe9769c2a94..95bf8c2577f9c29657bd42ecbbb923bf6e6089a0 100644 --- a/ecmascript/js_stable_array.cpp +++ b/ecmascript/js_stable_array.cpp @@ -27,7 +27,7 @@ namespace panda::ecmascript { JSTaggedValue JSStableArray::Push(JSHandle receiver, EcmaRuntimeCallInfo *argv) { JSThread *thread = argv->GetThread(); - uint32_t argc = argv->GetArgsNumber(); + uint32_t argc = static_cast(argv->GetArgsNumber()); uint32_t oldLength = receiver->GetArrayLength(); uint32_t newLength = argc + oldLength; @@ -72,7 +72,7 @@ JSTaggedValue JSStableArray::Splice(JSHandle receiver, EcmaRuntimeCallI { JSThread *thread = argv->GetThread(); uint32_t len = receiver->GetArrayLength(); - uint32_t argc = argv->GetArgsNumber(); + uint32_t argc = static_cast(argv->GetArgsNumber()); JSHandle thisObjHandle(receiver); JSTaggedValue newArray = JSArray::ArraySpeciesCreate(thread, thisObjHandle, JSTaggedNumber(actualDeleteCount)); @@ -224,7 +224,9 @@ JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInf CVector> vec; JSMutableHandle elementHandle(thread, JSTaggedValue::Undefined()); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - for (uint32_t k = 0; k < length; k++) { + uint32_t elementslength = elements->GetLength(); + uint32_t len = elementslength > length ? length : elementslength; + for (uint32_t k = 0; k < len; k++) { JSTaggedValue element = elements->Get(k); if (!element.IsUndefinedOrNull() && !element.IsHole()) { if (!element.IsString()) { @@ -243,11 +245,13 @@ JSTaggedValue JSStableArray::Join(JSHandle receiver, EcmaRuntimeCallInf vec.push_back(JSHandle(globalConst->GetHandledEmptyString())); } } - allocateLength += sepLength * (length - 1); + if (len > 0) { + allocateLength += sepLength * (len - 1); + } auto newString = EcmaString::AllocStringObject(allocateLength, isOneByte, thread->GetEcmaVM()); int current = 0; DISALLOW_GARBAGE_COLLECTION; - for (uint32_t k = 0; k < length; k++) { + for (uint32_t k = 0; k < len; k++) { if (k > 0) { if (sep >= 0) { newString->WriteData(static_cast(sep), current); diff --git a/ecmascript/js_tagged_value-inl.h b/ecmascript/js_tagged_value-inl.h index d7e4dc058c416e3f08b8af1769ec3686a2e8f92d..a8b0a44d28e1338c826e45792e553e227c9aa09b 100644 --- a/ecmascript/js_tagged_value-inl.h +++ b/ecmascript/js_tagged_value-inl.h @@ -474,7 +474,7 @@ inline bool JSTaggedValue::IsJSProxy() const inline bool JSTaggedValue::IsBoolean() const { - return ((value_ & TAG_HEAPOBJECT_BOOLEAN) == TAG_BOOLEAN_MASK); + return ((value_ & TAG_HEAPOBJECT_MARK) == TAG_BOOLEAN_MARK); } inline bool JSTaggedValue::IsJSObject() const @@ -616,6 +616,17 @@ inline bool JSTaggedValue::IsJSAPIDeque() const { return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIDeque(); } + +inline bool JSTaggedValue::IsJSAPILightWeightMap() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightMap(); +} + +inline bool JSTaggedValue::IsJSAPILightWeightSet() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightSet(); +} + inline bool JSTaggedValue::IsJSAPIStack() const { return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIStack(); @@ -661,6 +672,26 @@ inline bool JSTaggedValue::IsPromiseCapability() const return IsHeapObject() && GetTaggedObject()->GetClass()->IsPromiseCapability(); } +inline bool JSTaggedValue::IsJSPromiseAnyRejectElementFunction() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseAnyRejectElementFunction(); +} + +inline bool JSTaggedValue::IsJSPromiseAllSettledElementFunction() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseAllSettledElementFunction(); +} + +inline bool JSTaggedValue::IsJSPromiseFinallyFunction() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseFinallyFunction(); +} + +inline bool JSTaggedValue::IsJSPromiseValueThunkOrThrowerFunction() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSPromiseValueThunkOrThrowerFunction(); +} + inline bool JSTaggedValue::IsJSError() const { return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSError(); @@ -974,6 +1005,16 @@ inline bool JSTaggedValue::IsJSAPIDequeIterator() const return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIDequeIterator(); } +inline bool JSTaggedValue::IsJSAPILightWeightMapIterator() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightMapIterator(); +} + +inline bool JSTaggedValue::IsJSAPILightWeightSetIterator() const +{ + return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPILightWeightSetIterator(); +} + inline bool JSTaggedValue::IsJSAPIStackIterator() const { return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSAPIStackIterator(); @@ -1084,19 +1125,19 @@ inline bool JSTaggedValue::IsTSClassInstanceType() const return IsHeapObject() && GetTaggedObject()->GetClass()->IsTSClassInstanceType(); } -inline bool JSTaggedValue::IsJSCjsExports() const +inline bool JSTaggedValue::IsCjsExports() const { - return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSCjsExports(); + return IsHeapObject() && GetTaggedObject()->GetClass()->IsCjsExports(); } -inline bool JSTaggedValue::IsJSCjsModule() const +inline bool JSTaggedValue::IsCjsModule() const { - return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSCjsModule(); + return IsHeapObject() && GetTaggedObject()->GetClass()->IsCjsModule(); } -inline bool JSTaggedValue::IsJSCjsRequire() const +inline bool JSTaggedValue::IsCjsRequire() const { - return IsHeapObject() && GetTaggedObject()->GetClass()->IsJSCjsRequire(); + return IsHeapObject() && GetTaggedObject()->GetClass()->IsCjsRequire(); } inline bool JSTaggedValue::IsTSFunctionType() const @@ -1279,4 +1320,4 @@ inline JSTaggedNumber JSTaggedValue::StringToDouble(JSTaggedValue tagged) return JSTaggedNumber(d); } } // namespace panda::ecmascript -#endif // ECMASCRIPT_TAGGED_VALUE__INL_H +#endif // ECMASCRIPT_TAGGED_VALUE_INL_H diff --git a/ecmascript/js_tagged_value.cpp b/ecmascript/js_tagged_value.cpp index 5a94d046d7d27cce7020673d49efad20cfe5dcbc..e4d8cab4d512f457b85521728b04a0255dedb0f5 100644 --- a/ecmascript/js_tagged_value.cpp +++ b/ecmascript/js_tagged_value.cpp @@ -20,6 +20,8 @@ #include "ecmascript/interpreter/interpreter.h" #include "ecmascript/js_api_arraylist.h" #include "ecmascript/js_api_deque.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightmap.h" #include "ecmascript/js_api_linked_list.h" #include "ecmascript/js_api_list.h" #include "ecmascript/js_api_plain_array.h" @@ -339,10 +341,11 @@ JSTaggedValue JSTaggedValue::ToPrimitive(JSThread *thread, const JSHandleIsUndefined()) { JSTaggedValue value = GetTypeString(thread, type).GetTaggedValue(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, exoticToprim, tagged, undefined, 1); - info.SetCallArg(value); - JSTaggedValue valueResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); + info->SetCallArg(value); + JSTaggedValue valueResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); if (!valueResult.IsECMAObject()) { return valueResult; @@ -372,9 +375,9 @@ JSTaggedValue JSTaggedValue::OrdinaryToPrimitive(JSThread *thread, const JSHandl JSHandle entryfunc = GetProperty(thread, tagged, keyString).GetValue(); if (entryfunc->IsCallable()) { JSHandle undefined = globalConst->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, entryfunc, tagged, undefined, 0); - JSTaggedValue valueResult = JSFunction::Call(&info); + JSTaggedValue valueResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception()); if (!valueResult.IsECMAObject()) { return valueResult; @@ -500,7 +503,11 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &key) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Obj is not a valid object", + std::string keyStr = base::StringHelper::ToStdString(*(ToString(thread, key))); + std::string objStr = base::StringHelper::ToStdString(*(ToString(thread, obj))); + std::string message = "Cannot read property "; + message.append(keyStr).append(" of ").append(objStr); + THROW_TYPE_ERROR_AND_RETURN(thread, message.c_str(), OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); @@ -525,7 +532,10 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &obj, uint32_t key) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Obj is not a valid object", + std::string objStr = base::StringHelper::ToStdString(*(ToString(thread, obj))); + std::string message = "Cannot read property "; + message.append(ToCString(key)).append(" of ").append(objStr); + THROW_TYPE_ERROR_AND_RETURN(thread, message.c_str(), OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } @@ -550,7 +560,11 @@ OperationResult JSTaggedValue::GetProperty(JSThread *thread, const JSHandle &key, const JSHandle &receiver) { if (obj->IsUndefined() || obj->IsNull() || obj->IsHole()) { - THROW_TYPE_ERROR_AND_RETURN(thread, "Obj is not a valid object", + std::string keyStr = base::StringHelper::ToStdString(*(ToString(thread, key))); + std::string objStr = base::StringHelper::ToStdString(*(ToString(thread, obj))); + std::string message = "Cannot read property "; + message.append(keyStr).append(" of ").append(objStr); + THROW_TYPE_ERROR_AND_RETURN(thread, message.c_str(), OperationResult(thread, JSTaggedValue::Exception(), PropertyMetaData(false))); } ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); @@ -587,6 +601,8 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle success = JSTypedArray::SetProperty(thread, obj, key, value, mayThrow); } else if (obj->IsModuleNamespace()) { success = ModuleNamespace::SetProperty(thread, mayThrow); + } else if (obj->IsSpecialContainer()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property on Container", false); } else { success = JSObject::SetProperty(thread, obj, key, value, mayThrow); } @@ -614,6 +630,8 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle success = JSTypedArray::SetProperty(thread, obj, keyHandle, value, mayThrow); } else if (obj->IsModuleNamespace()) { success = ModuleNamespace::SetProperty(thread, mayThrow); + } else if (obj->IsSpecialContainer()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property on Container", false); } else { success = JSObject::SetProperty(thread, obj, key, value, mayThrow); } @@ -642,6 +660,8 @@ bool JSTaggedValue::SetProperty(JSThread *thread, const JSHandle success = JSTypedArray::SetProperty(thread, obj, key, value, receiver, mayThrow); } else if (obj->IsModuleNamespace()) { success = ModuleNamespace::SetProperty(thread, mayThrow); + } else if (obj->IsSpecialContainer()) { + THROW_TYPE_ERROR_AND_RETURN(thread, "Cannot set property on Container", false); } else { success = JSObject::SetProperty(thread, obj, key, value, receiver, mayThrow); } @@ -951,6 +971,8 @@ bool JSTaggedValue::HasContainerProperty(JSThread *thread, const JSHandle linkedList = JSHandle::Cast(obj); return linkedList->Has(key.GetTaggedValue()); } + case JSType::JS_API_LIGHT_WEIGHT_MAP: + case JSType::JS_API_LIGHT_WEIGHT_SET: case JSType::JS_API_TREE_MAP: case JSType::JS_API_TREE_SET: { return JSObject::HasProperty(thread, JSHandle(obj), key); @@ -973,6 +995,13 @@ JSHandle JSTaggedValue::GetOwnContainerPropertyKeys(JSThread *threa case JSType::JS_API_ARRAY_LIST: { return JSAPIArrayList::OwnKeys(thread, JSHandle::Cast(obj)); } + case JSType::JS_API_LIGHT_WEIGHT_MAP: { + return JSHandle(thread, + JSHandle::Cast(obj)->GetValues()); + } + case JSType::JS_API_LIGHT_WEIGHT_SET: { + return JSObject::GetOwnPropertyKeys(thread, JSHandle(obj)); + } case JSType::JS_API_QUEUE: { return JSAPIQueue::OwnKeys(thread, JSHandle::Cast(obj)); } diff --git a/ecmascript/js_tagged_value.h b/ecmascript/js_tagged_value.h index f013b8393a0593b192c106e0348840faf1b22a45..b4343d33bee9d677d9384fc946e662a0394835a7 100644 --- a/ecmascript/js_tagged_value.h +++ b/ecmascript/js_tagged_value.h @@ -82,38 +82,39 @@ static inline double ReinterpretTaggedTypeToDouble(JSTaggedType value) class JSTaggedValue { public: - static constexpr size_t TAG_BITS_SIZE = 16; + static constexpr size_t TAG_BITS_SIZE = 16; // 16 means bit numbers of 0xFFFF static constexpr size_t TAG_BITS_SHIFT = BitNumbers() - TAG_BITS_SIZE; static_assert((TAG_BITS_SHIFT + TAG_BITS_SIZE) == sizeof(JSTaggedType) * CHAR_BIT, "Insufficient bits!"); - static constexpr JSTaggedType TAG_MASK = ((1ULL << TAG_BITS_SIZE) - 1ULL) << TAG_BITS_SHIFT; - static constexpr JSTaggedType TAG_INT = 0xFFFFULL << TAG_BITS_SHIFT; + static constexpr JSTaggedType TAG_MARK = 0xFFFFULL << TAG_BITS_SHIFT; + // int tag + static constexpr JSTaggedType TAG_INT = TAG_MARK; + // object tag static constexpr JSTaggedType TAG_OBJECT = 0x0000ULL << TAG_BITS_SHIFT; - - static constexpr JSTaggedType TAG_SPECIAL_MASK = 0xFFULL; - static constexpr TaggedType TAG_HEAPOBJECT_BOOLEAN = TAG_INT | 0x06ULL; - static constexpr TaggedType TAG_WEAK = TAG_INT | 0x07ULL; - static constexpr TaggedType TAG_SPECIAL_MARK = TAG_INT | 0x02ULL; - static constexpr JSTaggedType TAG_SPECIAL_VALUE = 0x02ULL; + // weak object tag + static constexpr JSTaggedType TAG_WEAK = TAG_OBJECT | 0x01ULL; + // special tag + static constexpr JSTaggedType TAG_NULL = 0x01ULL; + static constexpr JSTaggedType TAG_SPECIAL = 0x02ULL; static constexpr JSTaggedType TAG_BOOLEAN = 0x04ULL; - static constexpr JSTaggedType TAG_BOOLEAN_MASK = 0x06ULL; - static constexpr TaggedType TAG_NULL = 0x01ULL; - static constexpr TaggedType TAG_EXCEPTION = 0x08ULL; - static constexpr JSTaggedType TAG_WEAK_FILTER = 0x03ULL; - static constexpr JSTaggedType VALUE_HOLE = TAG_OBJECT | 0x05ULL; - static constexpr JSTaggedType TAG_WEAK_MASK = TAG_OBJECT | 0x01ULL; - static constexpr JSTaggedType VALUE_NULL = TAG_OBJECT | TAG_SPECIAL_VALUE | TAG_NULL; - static constexpr JSTaggedType VALUE_FALSE = - TAG_OBJECT | TAG_BOOLEAN | TAG_SPECIAL_VALUE | static_cast(false); - static constexpr JSTaggedType VALUE_TRUE = - TAG_OBJECT | TAG_BOOLEAN | TAG_SPECIAL_VALUE | static_cast(true); + static constexpr JSTaggedType TAG_EXCEPTION = 0x08ULL; + // tag mark + static constexpr JSTaggedType TAG_SPECIAL_MARK = TAG_MARK | TAG_SPECIAL; + static constexpr JSTaggedType TAG_BOOLEAN_MARK = TAG_SPECIAL | TAG_BOOLEAN; + static constexpr JSTaggedType TAG_HEAPOBJECT_MARK = TAG_MARK | TAG_SPECIAL | TAG_BOOLEAN; + static constexpr JSTaggedType TAG_WEAK_MARK = TAG_HEAPOBJECT_MARK | TAG_WEAK; + // special value + static constexpr JSTaggedType VALUE_HOLE = 0x05ULL; + static constexpr JSTaggedType VALUE_NULL = TAG_OBJECT | TAG_SPECIAL | TAG_NULL; + static constexpr JSTaggedType VALUE_FALSE = TAG_BOOLEAN_MARK | static_cast(false); + static constexpr JSTaggedType VALUE_TRUE = TAG_BOOLEAN_MARK | static_cast(true); + static constexpr JSTaggedType VALUE_UNDEFINED = TAG_SPECIAL; + static constexpr JSTaggedType VALUE_EXCEPTION = TAG_SPECIAL | TAG_EXCEPTION; static constexpr JSTaggedType VALUE_ZERO = TAG_INT | 0x00ULL; - static constexpr JSTaggedType VALUE_UNDEFINED = TAG_OBJECT | TAG_SPECIAL_VALUE; - static constexpr JSTaggedType VALUE_EXCEPTION = TAG_OBJECT | TAG_SPECIAL_VALUE | TAG_EXCEPTION; static constexpr size_t DOUBLE_ENCODE_OFFSET_BIT = 48; static constexpr JSTaggedType DOUBLE_ENCODE_OFFSET = 1ULL << DOUBLE_ENCODE_OFFSET_BIT; - static JSTaggedValue Cast(ObjectHeader *object) + static JSTaggedValue Cast(TaggedObject *object) { return JSTaggedValue(object); } @@ -145,9 +146,7 @@ public: } constexpr explicit JSTaggedValue(bool v) - : value_(static_cast(v) | TAG_OBJECT | TAG_BOOLEAN | TAG_SPECIAL_VALUE) - { - } + : value_(static_cast(v) | TAG_BOOLEAN_MARK) {} explicit JSTaggedValue(double v) { @@ -156,8 +155,6 @@ public: value_ = ReinterpretDoubleToTaggedType(v) + DOUBLE_ENCODE_OFFSET; } - explicit JSTaggedValue(const ObjectHeader *v) : value_(static_cast(ToUintPtr(v))) {} - explicit JSTaggedValue(const TaggedObject *v) : value_(static_cast(ToUintPtr(v))) {} explicit JSTaggedValue(int64_t v) @@ -175,27 +172,27 @@ public: inline void CreateWeakRef() { - ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK_FILTER) == 0U), + ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == 0U), "The least significant two bits of JSTaggedValue are not zero."); - value_ = value_ | TAG_WEAK_MASK; + value_ = value_ | TAG_WEAK; } inline void RemoveWeakTag() { - ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK_MASK) == 1U), "The tagged value is not a weak ref."); - value_ = value_ & (~TAG_WEAK_FILTER); + ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == TAG_WEAK), "The tagged value is not a weak ref."); + value_ = value_ & (~TAG_WEAK); } inline JSTaggedValue CreateAndGetWeakRef() { - ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK_FILTER) == 0U), + ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == 0U), "The least significant two bits of JSTaggedValue are not zero."); - return JSTaggedValue(value_ | TAG_WEAK_MASK); + return JSTaggedValue(value_ | TAG_WEAK); } inline bool IsWeak() const { - return ((value_ & TAG_WEAK) == 0x01ULL);; + return ((value_ & TAG_WEAK_MARK) == TAG_WEAK); } inline bool IsDouble() const @@ -205,27 +202,27 @@ public: inline bool IsInt() const { - return (value_ & TAG_MASK) == TAG_INT; + return (value_ & TAG_MARK) == TAG_INT; } inline bool IsSpecial() const { - return ((value_ & TAG_SPECIAL_MARK) == TAG_SPECIAL_VALUE) || IsHole(); + return ((value_ & TAG_SPECIAL_MARK) == TAG_SPECIAL) || IsHole(); } inline bool IsObject() const { - return ((value_ & TAG_MASK) == TAG_OBJECT); + return ((value_ & TAG_MARK) == TAG_OBJECT); } inline TaggedObject *GetWeakReferentUnChecked() const { - return reinterpret_cast(GetRawData() & (~TAG_WEAK_MASK)); + return reinterpret_cast(value_ & (~TAG_WEAK)); } inline bool IsHeapObject() const { - return ((value_ & TAG_HEAPOBJECT_BOOLEAN) == 0U); + return ((value_ & TAG_HEAPOBJECT_MARK) == 0U); } inline double GetDouble() const @@ -237,7 +234,7 @@ public: inline int GetInt() const { ASSERT_PRINT(IsInt(), "can not convert JSTaggedValue to Int :" << std::hex << value_); - return static_cast(value_ & (~TAG_MASK)); + return static_cast(value_ & (~TAG_MARK)); } inline JSTaggedType GetRawData() const @@ -245,24 +242,17 @@ public: return value_; } - inline ObjectHeader *GetHeapObject() const - { - ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK_FILTER) == 0U), - "can not convert JSTaggedValue to HeapObject :" << std::hex << value_); - return reinterpret_cast(value_); - } - // This function returns the heap object pointer which may have the weak tag. - inline ObjectHeader *GetRawHeapObject() const + inline TaggedObject *GetRawHeapObject() const { ASSERT_PRINT(IsHeapObject(), "can not convert JSTaggedValue to HeapObject :" << std::hex << value_); - return reinterpret_cast(value_); + return reinterpret_cast(value_); } - inline ObjectHeader *GetWeakReferent() const + inline TaggedObject *GetWeakReferent() const { ASSERT_PRINT(IsWeak(), "can not convert JSTaggedValue to WeakRef HeapObject :" << std::hex << value_); - return reinterpret_cast(value_ & (~TAG_WEAK_MASK)); + return reinterpret_cast(value_ & (~TAG_WEAK)); } static inline JSTaggedType Cast(void *ptr) @@ -293,7 +283,7 @@ public: inline bool IsUndefinedOrNull() const { - return ((value_ & TAG_HEAPOBJECT_BOOLEAN) == TAG_SPECIAL_VALUE); + return ((value_ & TAG_HEAPOBJECT_MARK) == TAG_SPECIAL); } inline bool IsHole() const @@ -324,7 +314,7 @@ public: inline bool IsWeakForHeapObject() const { - return (GetRawData() & TAG_WEAK_MASK) == 1U; + return (value_ & TAG_WEAK) == 1U; } static inline constexpr JSTaggedValue False() @@ -364,7 +354,9 @@ public: inline TaggedObject *GetTaggedObject() const { - return reinterpret_cast(GetHeapObject()); + ASSERT_PRINT(IsHeapObject() && ((value_ & TAG_WEAK) == 0U), + "can not convert JSTaggedValue to HeapObject :" << std::hex << value_); + return reinterpret_cast(value_); } inline TaggedObject *GetRawTaggedObject() const @@ -550,6 +542,10 @@ public: bool IsPromiseCapability() const; bool IsPromiseIteratorRecord() const; bool IsPromiseRecord() const; + bool IsJSPromiseAnyRejectElementFunction() const; + bool IsJSPromiseAllSettledElementFunction() const; + bool IsJSPromiseFinallyFunction() const; + bool IsJSPromiseValueThunkOrThrowerFunction() const; bool IsResolvingFunctionsRecord() const; bool IsCompletionRecord() const; bool IsDataView() const; @@ -569,6 +565,10 @@ public: // non ECMA standard jsapis bool IsJSAPIArrayList() const; bool IsJSAPIArrayListIterator() const; + bool IsJSAPILightWeightMap() const; + bool IsJSAPILightWeightMapIterator() const; + bool IsJSAPILightWeightSet() const; + bool IsJSAPILightWeightSetIterator() const; bool IsJSAPITreeMap() const; bool IsJSAPITreeSet() const; bool IsJSAPITreeMapIterator() const; @@ -605,9 +605,9 @@ public: bool IsTSFunctionType() const; bool IsTSArrayType() const; - bool IsJSCjsExports() const; - bool IsJSCjsModule() const; - bool IsJSCjsRequire() const; + bool IsCjsExports() const; + bool IsCjsModule() const; + bool IsCjsRequire() const; bool IsModuleRecord() const; bool IsSourceTextModule() const; bool IsImportEntry() const; diff --git a/ecmascript/js_thread.cpp b/ecmascript/js_thread.cpp index 9ae09ffcdf2bfbb6cbcd2eca69880a2e7cc3f802..5bba91675e0103efe3dbe67fea216a7520cfdfdb 100644 --- a/ecmascript/js_thread.cpp +++ b/ecmascript/js_thread.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ #include "ecmascript/js_thread.h" -#include "ecmascript/compiler/llvm/llvm_stackmap_parser.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "ecmascript/ecma_param_configuration.h" #include "ecmascript/global_env_constants-inl.h" #include "ecmascript/ic/properties_cache.h" @@ -34,9 +34,10 @@ JSThread *JSThread::Create(EcmaVM *vm) jsThread->nativeAreaAllocator_ = vm->GetNativeAreaAllocator(); jsThread->heapRegionAllocator_ = vm->GetHeapRegionAllocator(); // algin with 16 + size_t maxStackSize = vm->GetEcmaParamConfiguration().GetMaxStackSize(); jsThread->glueData_.frameBase_ = static_cast( - vm->GetNativeAreaAllocator()->Allocate(sizeof(JSTaggedType) * MAX_STACK_SIZE)); - jsThread->glueData_.currentFrame_ = jsThread->glueData_.frameBase_ + MAX_STACK_SIZE; + vm->GetNativeAreaAllocator()->Allocate(sizeof(JSTaggedType) * maxStackSize)); + jsThread->glueData_.currentFrame_ = jsThread->glueData_.frameBase_ + maxStackSize; EcmaInterpreter::InitStackFrame(jsThread); return jsThread; } @@ -60,7 +61,8 @@ JSThread::~JSThread() handleScopeStorageNext_ = handleScopeStorageEnd_ = nullptr; GetEcmaVM()->GetChunk()->Delete(globalStorage_); - GetNativeAreaAllocator()->Free(glueData_.frameBase_, sizeof(JSTaggedType) * MAX_STACK_SIZE); + GetNativeAreaAllocator()->Free(glueData_.frameBase_, sizeof(JSTaggedType) * + vm_->GetEcmaParamConfiguration().GetMaxStackSize()); glueData_.frameBase_ = nullptr; nativeAreaAllocator_ = nullptr; heapRegionAllocator_ = nullptr; @@ -130,6 +132,9 @@ void JSThread::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) FrameHandler frameHandler(this); frameHandler.Iterate(v0, v1); // visit tagged handle storage roots +#if ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK + size_t handleCount = 0; +#endif if (currentHandleStorageIndex_ != -1) { int32_t nid = currentHandleStorageIndex_; for (int32_t i = 0; i <= nid; ++i) { @@ -137,14 +142,29 @@ void JSThread::Iterate(const RootVisitor &v0, const RootRangeVisitor &v1) auto start = node->data(); auto end = (i != nid) ? &(node->data()[NODE_BLOCK_SIZE]) : handleScopeStorageNext_; v1(ecmascript::Root::ROOT_HANDLE, ObjectSlot(ToUintPtr(start)), ObjectSlot(ToUintPtr(end))); +#if ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK + handleCount += (ToUintPtr(end) - ToUintPtr(start)) / sizeof(JSTaggedType); +#endif } } + +#if ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK + size_t globalCount = 0; + globalStorage_->IterateUsageGlobal([v0, &globalCount](EcmaGlobalStorage::Node *node) { +#else globalStorage_->IterateUsageGlobal([v0](EcmaGlobalStorage::Node *node) { +#endif JSTaggedValue value(node->GetObject()); if (value.IsHeapObject()) { v0(ecmascript::Root::ROOT_HANDLE, ecmascript::ObjectSlot(node->GetObjectAddress())); } +#if ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK + globalCount++; +#endif }); +#if ECMASCRIPT_ENABLE_HANDLE_LEAK_CHECK + LOG_ECMA(INFO) << "Iterate root handle count:" << handleCount << ", global handle count:" << globalCount; +#endif } void JSThread::IterateWeakEcmaGlobalStorage(const WeakRootVisitor &visitor) @@ -208,7 +228,7 @@ void JSThread::ShrinkHandleStorage(int prevIndex) #if ECMASCRIPT_ENABLE_ZAP_MEM uintptr_t size = ToUintPtr(handleScopeStorageEnd_) - ToUintPtr(handleScopeStorageNext_); if (memset_s(handleScopeStorageNext_, size, 0, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } for (int32_t i = currentHandleStorageIndex_ + 1; i < lastIndex; i++) { @@ -216,7 +236,7 @@ void JSThread::ShrinkHandleStorage(int prevIndex) NODE_BLOCK_SIZE * sizeof(JSTaggedType), 0, NODE_BLOCK_SIZE * sizeof(JSTaggedType)) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -294,7 +314,7 @@ void JSThread::CheckJSTaggedType(JSTaggedType value) const { if (JSTaggedValue(value).IsHeapObject() && !GetEcmaVM()->GetHeap()->IsAlive(reinterpret_cast(value))) { - LOG(FATAL, RUNTIME) << "value:" << value << " is invalid!"; + LOG_FULL(FATAL) << "value:" << value << " is invalid!"; } } diff --git a/ecmascript/js_thread.h b/ecmascript/js_thread.h index 6a766a6112546586ea07a4feea709d8ba53aba1c..be6ed4c37eb71a9dfb3624bf34357260bd765ea8 100644 --- a/ecmascript/js_thread.h +++ b/ecmascript/js_thread.h @@ -27,6 +27,7 @@ #include "ecmascript/frames.h" #include "ecmascript/global_env_constants.h" #include "ecmascript/mem/visitor.h" +#include "libpandabase/os/thread.h" namespace panda::ecmascript { class EcmaHandleScope; @@ -449,16 +450,6 @@ public: return gcState_; } - void SetCheckAndCallEnterState(bool checkAndCallEnterState) - { - checkAndCallEnterState_ = checkAndCallEnterState; - } - - bool GetCheckAndCallEnterState() const - { - return checkAndCallEnterState_; - } - void EnableAsmInterpreter() { isAsmInterpreter_ = true; @@ -502,7 +493,18 @@ public: void CollectBCOffsetInfo(); + void SetCheckAndCallEnterState(bool state) + { + finalizationCheckState_ = state; + } + + bool GetCheckAndCallEnterState() const + { + return finalizationCheckState_; + } + struct GlueData : public base::AlignedStruct { enum class Index : size_t { - ExceptionIndex = 0, + BCStubEntriesIndex = 0, + ExceptionIndex, GlobalObjIndex, CurrentFrameIndex, LeaveFrameIndex, LastFpIndex, NewSpaceAllocationTopAddressIndex, NewSpaceAllocationEndAddressIndex, - BCStubEntriesIndex, RTStubEntriesIndex, COStubEntriesIndex, BCDebuggerStubEntriesIndex, @@ -606,6 +607,7 @@ public: return GetOffset(Index::FrameBaseIndex)>(isArch32); } + alignas(EAS) BCStubEntries bcStubEntries_; alignas(EAS) JSTaggedValue exception_ {JSTaggedValue::Hole()}; alignas(EAS) JSTaggedValue globalObject_ {JSTaggedValue::Hole()}; alignas(EAS) JSTaggedType *currentFrame_ {nullptr}; @@ -613,7 +615,6 @@ public: alignas(EAS) JSTaggedType *lastFp_ {nullptr}; alignas(EAS) const uintptr_t *newSpaceAllocationTopAddress_ {nullptr}; alignas(EAS) const uintptr_t *newSpaceAllocationEndAddress_ {nullptr}; - alignas(EAS) BCStubEntries bcStubEntries_; alignas(EAS) RTStubEntries rtStubEntries_; alignas(EAS) COStubEntries coStubEntries_; alignas(EAS) BCDebuggerStubEntries bcDebuggerStubEntries_; @@ -632,6 +633,7 @@ private: static const uint32_t NODE_BLOCK_SIZE_LOG2 = 10; static const uint32_t NODE_BLOCK_SIZE = 1U << NODE_BLOCK_SIZE_LOG2; static constexpr int32_t MIN_HANDLE_STORAGE_SIZE = 2; + GlueData glueData_; std::atomic id_; EcmaVM *vm_ {nullptr}; @@ -655,9 +657,9 @@ private: VmThreadControl *vmThreadControl_ {nullptr}; bool enablePrintBCOffset_ {false}; bool stableArrayElementsGuardians_ {true}; - GlueData glueData_; - bool checkAndCallEnterState_ {false}; + bool finalizationCheckState_ {false}; + friend class EcmaHandleScope; friend class GlobalHandleCollection; }; diff --git a/ecmascript/js_typed_array.h b/ecmascript/js_typed_array.h index b422d096efa5a5d705753b7e861c9f3b2cc96657..fbfc27b76db47cde39a6308792a673263ba64d67 100644 --- a/ecmascript/js_typed_array.h +++ b/ecmascript/js_typed_array.h @@ -24,7 +24,7 @@ namespace panda::ecmascript { enum class ContentType : uint8_t { None = 1, Number, BigInt }; class JSTypedArray : public JSObject { public: - static JSTypedArray *Cast(ObjectHeader *object) + static JSTypedArray *Cast(TaggedObject *object) { #if ECMASCRIPT_ENABLE_CAST_CHECK if (!(JSTaggedValue(object).IsTypedArray() || JSTaggedValue(object).IsJSTypedArray())) { diff --git a/ecmascript/js_vm/BUILD.gn b/ecmascript/js_vm/BUILD.gn index c0c909f268520edba1990f53d78974d6103e56c3..f885b08cf2f0563c530b4b68f3555052f20f48cf 100644 --- a/ecmascript/js_vm/BUILD.gn +++ b/ecmascript/js_vm/BUILD.gn @@ -11,7 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (!defined(ark_independent_build)) { +if (!defined(ark_standalone_build)) { import("//ark/js_runtime/js_runtime_config.gni") import("//build/ohos.gni") } else { @@ -33,7 +33,7 @@ source_set("ark_js_vm_set") { ] } -if (!defined(ark_independent_build)) { +if (!defined(ark_standalone_build)) { ohos_executable("ark_js_vm") { deps = [ ":ark_js_vm_set" ] diff --git a/ecmascript/js_vm/main.cpp b/ecmascript/js_vm/main.cpp index c39560aa1d1befe3b6ee4cc393656879b860a0b3..dd0d86393160ee8403415d7d7923c48a8e3f43da 100644 --- a/ecmascript/js_vm/main.cpp +++ b/ecmascript/js_vm/main.cpp @@ -27,7 +27,6 @@ #include "ecmascript/mem/mem_controller.h" #include "ecmascript/napi/include/jsnapi.h" #include "generated/base_options.h" -#include "handle_scope.h" #include "libpandabase/os/native_stack.h" #include "libpandabase/utils/pandargs.h" #include "libpandabase/utils/span.h" @@ -38,18 +37,18 @@ void BlockSignals() #if defined(PANDA_TARGET_UNIX) sigset_t set; if (sigemptyset(&set) == -1) { - LOG(ERROR, RUNTIME) << "sigemptyset failed"; + LOG_ECMA(ERROR) << "sigemptyset failed"; return; } int rc = 0; if (rc < 0) { - LOG(ERROR, RUNTIME) << "sigaddset failed"; + LOG_ECMA(ERROR) << "sigaddset failed"; return; } if (panda::os::native_stack::g_PandaThreadSigmask(SIG_BLOCK, &set, nullptr) != 0) { - LOG(ERROR, RUNTIME) << "g_PandaThreadSigmask failed"; + LOG_ECMA(ERROR) << "g_PandaThreadSigmask failed"; } #endif // PANDA_TARGET_UNIX } @@ -109,16 +108,18 @@ int Main(const int argc, const char **argv) return -1; } - LocalScope scope(vm); - std::string entry = entrypoint.GetValue(); - - arg_list_t fileNames = files.GetValue(); - for (const auto &fileName : fileNames) { - auto res = JSNApi::Execute(vm, fileName, entry); - if (!res) { - std::cerr << "Cannot execute panda file '" << fileName << "' with entry '" << entry << "'" << std::endl; - ret = false; - break; + { + LocalScope scope(vm); + std::string entry = entrypoint.GetValue(); + + arg_list_t fileNames = files.GetValue(); + for (const auto &fileName : fileNames) { + auto res = JSNApi::Execute(vm, fileName, entry); + if (!res) { + std::cerr << "Cannot execute panda file '" << fileName << "' with entry '" << entry << "'" << std::endl; + ret = false; + break; + } } } diff --git a/ecmascript/js_weak_container.h b/ecmascript/js_weak_container.h index e7f276c78226d43f1d9263cd18e78627855254d0..3e32375944b9cf9c02514aef54f1c0ed326cbdcb 100644 --- a/ecmascript/js_weak_container.h +++ b/ecmascript/js_weak_container.h @@ -22,7 +22,7 @@ namespace panda::ecmascript { class JSWeakMap : public JSObject { public: - static JSWeakMap *Cast(ObjectHeader *object) + static JSWeakMap *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSWeakMap()); return static_cast(object); @@ -48,7 +48,7 @@ public: class JSWeakSet : public JSObject { public: - static JSWeakSet *Cast(ObjectHeader *object) + static JSWeakSet *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSWeakSet()); return static_cast(object); diff --git a/ecmascript/js_weak_ref.h b/ecmascript/js_weak_ref.h index 493766c117121c26e53c2bc19964d0cca46ac737..16d87cf4eb87e93cf707468893f5e2acd792a801 100644 --- a/ecmascript/js_weak_ref.h +++ b/ecmascript/js_weak_ref.h @@ -21,7 +21,7 @@ namespace panda::ecmascript { class JSWeakRef : public JSObject { public: - static JSWeakRef *Cast(ObjectHeader *object) + static JSWeakRef *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsJSWeakRef()); return static_cast(object); diff --git a/ecmascript/jspandafile/accessor/module_data_accessor.cpp b/ecmascript/jspandafile/accessor/module_data_accessor.cpp index 01c15fd36f6118f148ac02530e4f793b50150762..0b551bdf1cbc7caaa79a6715a97e848359b2c486 100644 --- a/ecmascript/jspandafile/accessor/module_data_accessor.cpp +++ b/ecmascript/jspandafile/accessor/module_data_accessor.cpp @@ -14,7 +14,6 @@ */ #include "ecmascript/jspandafile/accessor/module_data_accessor.h" -#include "libpandafile/file_items.h" #include "libpandafile/helpers.h" namespace panda::ecmascript::jspandafile { diff --git a/ecmascript/jspandafile/debug_info_extractor.cpp b/ecmascript/jspandafile/debug_info_extractor.cpp index edf18e932c864f110ac8b7caf8ca0d519e18a986..927fec44d9812f67b9eeef38b6c7bd9d98c8fb0c 100644 --- a/ecmascript/jspandafile/debug_info_extractor.cpp +++ b/ecmascript/jspandafile/debug_info_extractor.cpp @@ -243,7 +243,7 @@ const std::string &DebugInfoExtractor::GetSourceFile(panda_file::File::EntityId { auto iter = methods_.find(methodId.GetOffset()); if (iter == methods_.end()) { - LOG(FATAL, DEBUGGER) << "Get source file of unknown method id: " << methodId.GetOffset(); + LOG_DEBUGGER(FATAL) << "Get source file of unknown method id: " << methodId.GetOffset(); } return iter->second.sourceFile; } @@ -252,7 +252,7 @@ const std::string &DebugInfoExtractor::GetSourceCode(panda_file::File::EntityId { auto iter = methods_.find(methodId.GetOffset()); if (iter == methods_.end()) { - LOG(FATAL, DEBUGGER) << "Get source code of unknown method id: " << methodId.GetOffset(); + LOG_DEBUGGER(FATAL) << "Get source code of unknown method id: " << methodId.GetOffset(); } return iter->second.sourceCode; } diff --git a/ecmascript/jspandafile/js_pandafile.h b/ecmascript/jspandafile/js_pandafile.h index e38d5ebc8ab80a9c01104268938ac8f1ba8dde40..f449c66898a10fc23bc2807f0e3d51801232ce6a 100644 --- a/ecmascript/jspandafile/js_pandafile.h +++ b/ecmascript/jspandafile/js_pandafile.h @@ -17,11 +17,11 @@ #define ECMASCRIPT_JSPANDAFILE_JS_PANDAFILE_H #include "ecmascript/common.h" +#include "ecmascript/js_function.h" #include "ecmascript/js_method.h" #include "ecmascript/jspandafile/constpool_value.h" #include "ecmascript/mem/c_containers.h" #include "libpandafile/file.h" -#include "libpandabase/utils/logger.h" namespace panda { namespace panda_file { @@ -122,6 +122,30 @@ public: return typeSummaryIndex_; } + uint32_t GetFileUniqId() const + { + return static_cast(GetPandaFile()->GetUniqId()); + } + + inline void SetUniqueMethodMap(const JSMethod *method, const uint8_t *insans) + { + if (method != nullptr) { + auto offset = method->GetMethodId().GetOffset(); + if (pcToUniqMethodOffset_.find(insans) == pcToUniqMethodOffset_.end()) { + pcToUniqMethodOffset_.emplace(insans, offset); + } + dupMethodOffsetToUniqMethodOffset_.emplace(offset, pcToUniqMethodOffset_.at(insans)); + } + } + + inline uint32_t GetUniqueMethod(const JSHandle &func) const + { + auto method = func->GetMethod(); + ASSERT(method != nullptr); + auto methodOffset = method->GetMethodId().GetOffset(); + return dupMethodOffsetToUniqMethodOffset_.at(methodOffset); + } + private: void Initialize(); uint32_t constpoolIndex_ {0}; @@ -130,6 +154,8 @@ private: uint32_t mainMethodIndex_ {0}; JSMethod *methods_ {nullptr}; CUnorderedMap methodMap_; + CUnorderedMap dupMethodOffsetToUniqMethodOffset_; + CUnorderedMap pcToUniqMethodOffset_; const panda_file::File *pf_ {nullptr}; CString desc_; bool isModule_ {false}; diff --git a/ecmascript/jspandafile/js_pandafile_manager.cpp b/ecmascript/jspandafile/js_pandafile_manager.cpp index 0ca7ae9309cfa82f14bf97950df0b34912442276..0e7b52919eabc01dfb0b9a5838c2c3c37986e4de 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.cpp +++ b/ecmascript/jspandafile/js_pandafile_manager.cpp @@ -208,7 +208,7 @@ void JSPandaFileManager::ReleaseJSPandaFile(const JSPandaFile *jsPandaFile) tooling::JSPtExtractor *JSPandaFileManager::GetJSPtExtractor(const JSPandaFile *jsPandaFile) { - LOG_IF(jsPandaFile == nullptr, FATAL, ECMASCRIPT) << "GetJSPtExtractor error, js pandafile is nullptr"; + LOG_ECMA_IF(jsPandaFile == nullptr, FATAL) << "GetJSPtExtractor error, js pandafile is nullptr"; os::memory::LockHolder lock(jsPandaFileLock_); ASSERT(loadedJSPandaFiles_.find(jsPandaFile) != loadedJSPandaFiles_.end()); diff --git a/ecmascript/jspandafile/js_pandafile_manager.h b/ecmascript/jspandafile/js_pandafile_manager.h index dc817f14680168bd749e31f429f6eb77fb337345..65deb8d42a6ce914de8ada51d64113ff43ca1a09 100644 --- a/ecmascript/jspandafile/js_pandafile_manager.h +++ b/ecmascript/jspandafile/js_pandafile_manager.h @@ -21,7 +21,6 @@ #include "ecmascript/jspandafile/panda_file_translator.h" #include "ecmascript/tooling/backend/js_pt_extractor.h" #include "libpandafile/file.h" -#include "libpandabase/utils/logger.h" namespace panda { namespace panda_file { diff --git a/ecmascript/jspandafile/literal_data_extractor.cpp b/ecmascript/jspandafile/literal_data_extractor.cpp index 7467a19fe312bf95a789da72ed48cd7da0cc1b7a..b85a469eb80ca87a1dac5689a641768da2ae36ef 100644 --- a/ecmascript/jspandafile/literal_data_extractor.cpp +++ b/ecmascript/jspandafile/literal_data_extractor.cpp @@ -35,7 +35,7 @@ void LiteralDataExtractor::ExtractObjectDatas(JSThread *thread, const JSPandaFil { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - LOG_ECMA(DEBUG) << "Panda File" << jsPandaFile->GetJSPandaFileDesc(); + LOG_ECMA(VERBOSE) << "Panda File" << jsPandaFile->GetJSPandaFileDesc(); const panda_file::File *pf = jsPandaFile->GetPandaFile(); panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId(); panda_file::LiteralDataAccessor lda(*pf, literalArraysId); @@ -121,7 +121,7 @@ JSHandle LiteralDataExtractor::GetDatasIgnoreType(JSThread *thread, { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - LOG_ECMA(DEBUG) << "Panda File" << jsPandaFile->GetJSPandaFileDesc(); + LOG_ECMA(VERBOSE) << "Panda File" << jsPandaFile->GetJSPandaFileDesc(); const panda_file::File *pf = jsPandaFile->GetPandaFile(); panda_file::File::EntityId literalArraysId = pf->GetLiteralArraysId(); panda_file::LiteralDataAccessor lda(*pf, literalArraysId); diff --git a/ecmascript/jspandafile/panda_file_translator.cpp b/ecmascript/jspandafile/panda_file_translator.cpp index 7142e205ec6bd4522911bca1f4ff04f04b382b5a..f8067a7c3e260087c751a04de68dd3f366e42435 100644 --- a/ecmascript/jspandafile/panda_file_translator.cpp +++ b/ecmascript/jspandafile/panda_file_translator.cpp @@ -13,8 +13,9 @@ * limitations under the License. */ -#include "panda_file_translator.h" +#include "ecmascript/jspandafile/panda_file_translator.h" +#include "ecmascript/file_loader.h" #include "ecmascript/global_env.h" #include "ecmascript/interpreter/interpreter.h" #include "ecmascript/jspandafile/class_info_extractor.h" @@ -29,7 +30,6 @@ #include "ecmascript/ts_types/ts_type_table.h" #include "ecmascript/ts_types/ts_loader.h" #include "libpandabase/mem/mem.h" -#include "libpandabase/utils/logger.h" #include "libpandabase/utils/utf.h" #include "libpandafile/bytecode_instruction-inl.h" #include "libpandafile/class_data_accessor-inl.h" @@ -52,13 +52,14 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri reinterpret_cast(methodName.c_str())}; std::set translatedCode; Span classIndexes = jsPandaFile->GetClasses(); + const bool isLoadedAOT = jsPandaFile->IsLoadedAOT(); for (const uint32_t index : classIndexes) { panda_file::File::EntityId classId(index); if (pf->IsExternal(classId)) { continue; } panda_file::ClassDataAccessor cda(*pf, classId); - cda.EnumerateMethods([jsPandaFile, &translatedCode, &sd, methods, &methodIdx, pf, &methodPcInfos] + cda.EnumerateMethods([jsPandaFile, &translatedCode, &sd, methods, &methodIdx, pf, &methodPcInfos, &isLoadedAOT] (panda_file::MethodDataAccessor &mda) { auto codeId = mda.GetCodeId(); ASSERT(codeId.has_value()); @@ -81,6 +82,9 @@ void PandaFileTranslator::TranslateClasses(JSPandaFile *jsPandaFile, const CStri TranslateBytecode(jsPandaFile, codeSize, insns, method, methodPcInfos); } jsPandaFile->SetMethodToMap(method); + if (isLoadedAOT) { + jsPandaFile->SetUniqueMethodMap(method, insns); + } }); } } @@ -132,6 +136,8 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle generatorDynclass = JSHandle::Cast(env->GetGeneratorFunctionClass()); const CUnorderedMap &constpoolMap = jsPandaFile->GetConstpoolMap(); + const bool isLoadedAOT = jsPandaFile->IsLoadedAOT(); + auto fileLoader = vm->GetFileLoader(); for (const auto &it : constpoolMap) { ConstPoolValue value(it.second); if (value.GetConstpoolType() == ConstPoolType::STRING) { @@ -147,6 +153,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, dynclass, FunctionKind::BASE_CONSTRUCTOR); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntry(jsPandaFile, jsFunc); + } constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); jsFunc->SetConstantPool(thread, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::NC_FUNCTION) { @@ -156,6 +165,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, normalDynclass, FunctionKind::NORMAL_FUNCTION); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntry(jsPandaFile, jsFunc); + } constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); jsFunc->SetConstantPool(thread, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::GENERATOR_FUNCTION) { @@ -165,6 +177,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, generatorDynclass, FunctionKind::GENERATOR_FUNCTION); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntry(jsPandaFile, jsFunc); + } // 26.3.4.3 prototype // Whenever a GeneratorFunction instance is created another ordinary object is also created and // is the initial value of the generator function's "prototype" property. @@ -183,6 +198,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, asyncDynclass, FunctionKind::ASYNC_FUNCTION); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntry(jsPandaFile, jsFunc); + } constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); jsFunc->SetConstantPool(thread, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::CLASS_FUNCTION) { @@ -198,6 +216,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSHandle jsFunc = factory->NewJSFunctionByDynClass(method, normalDynclass, FunctionKind::NORMAL_FUNCTION); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntry(jsPandaFile, jsFunc); + } constpool->Set(thread, value.GetConstpoolIndex(), jsFunc.GetTaggedValue()); jsFunc->SetConstantPool(thread, constpool.GetTaggedValue()); } else if (value.GetConstpoolType() == ConstPoolType::OBJECT_LITERAL) { @@ -206,7 +227,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSMutableHandle properties(thread, JSTaggedValue::Undefined()); LiteralDataExtractor::ExtractObjectDatas(thread, jsPandaFile, index, elements, properties); JSHandle obj = JSObject::CreateObjectFromProperties(thread, properties); - + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntryForLiteral(jsPandaFile, properties); + } JSMutableHandle key(thread, JSTaggedValue::Undefined()); JSMutableHandle valueHandle(thread, JSTaggedValue::Undefined()); size_t elementsLen = elements->GetLength(); @@ -223,6 +246,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile size_t index = it.first; JSHandle literal = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, static_cast(index)); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntryForLiteral(jsPandaFile, literal); + } uint32_t length = literal->GetLength(); JSHandle arr(JSArray::ArrayCreate(thread, JSTaggedNumber(length))); @@ -232,6 +258,9 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile size_t index = it.first; JSHandle literal = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, static_cast(index)); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntryForLiteral(jsPandaFile, literal); + } constpool->Set(thread, value.GetConstpoolIndex(), literal.GetTaggedValue()); } } @@ -242,7 +271,7 @@ JSTaggedValue PandaFileTranslator::ParseConstPool(EcmaVM *vm, const JSPandaFile JSPandaFileManager::GetInstance()); constpool->Set(thread, constpoolIndex, jsPandaFilePointer.GetTaggedValue()); - DefineClassInConstPool(thread, constpool); + DefineClassesInConstPool(thread, constpool, jsPandaFile); return constpool.GetTaggedValue(); } @@ -302,7 +331,7 @@ void PandaFileTranslator::FixOpcode(uint8_t *pc) break; default: if (*pc != static_cast(BytecodeInstruction::Opcode::ECMA_LDNAN_PREF_NONE)) { - LOG_ECMA(FATAL) << "Is not an Ecma Opcode opcode: " << static_cast(opcode); + LOG_FULL(FATAL) << "Is not an Ecma Opcode opcode: " << static_cast(opcode); UNREACHABLE(); } *pc = *(pc + 1); @@ -374,7 +403,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, ui uint8_t size = sizeof(uint32_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(pc + FixInstructionIndex::FIX_ONE, size, &index, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } break; @@ -384,7 +413,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, ui uint8_t size = sizeof(uint16_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(pc + FixInstructionIndex::FIX_TWO, size, &u16Index, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } break; @@ -395,7 +424,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, ui uint8_t size = sizeof(uint32_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(pc + FixInstructionIndex::FIX_TWO, size, &index, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } break; @@ -406,7 +435,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, ui uint8_t size = sizeof(uint16_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(pc + FixInstructionIndex::FIX_TWO, size, &u16Index, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } break; @@ -419,7 +448,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, ui ASSERT(static_cast(index) == index); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(pc + FixInstructionIndex::FIX_TWO, size, &index, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } break; @@ -430,7 +459,7 @@ void PandaFileTranslator::FixInstructionId32(const BytecodeInstruction &inst, ui uint8_t size = sizeof(uint16_t); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(pc + FixInstructionIndex::FIX_FOUR, size, &u16Index, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } break; @@ -533,10 +562,13 @@ void PandaFileTranslator::TranslateBytecode(JSPandaFile *jsPandaFile, uint32_t i } } -void PandaFileTranslator::DefineClassInConstPool(JSThread *thread, JSHandle constpool) +void PandaFileTranslator::DefineClassesInConstPool(JSThread *thread, JSHandle constpool, + const JSPandaFile *jsPandaFile) { uint32_t length = constpool->GetLength(); uint32_t index = 0; + const bool isLoadedAOT = jsPandaFile->IsLoadedAOT(); + auto fileLoader = thread->GetEcmaVM()->GetFileLoader(); while (index < length - 1) { JSTaggedValue value = constpool->Get(index); if (!value.IsClassInfoExtractor()) { @@ -553,6 +585,9 @@ void PandaFileTranslator::DefineClassInConstPool(JSThread *thread, JSHandle literal(thread, nextValue); ClassInfoExtractor::BuildClassInfoExtractorFromLiteral(thread, extractor, literal); JSHandle cls = ClassHelper::DefineClassTemplate(thread, extractor, constpool); + if (isLoadedAOT) { + fileLoader->SetAOTFuncEntry(jsPandaFile, cls); + } constpool->Set(thread, index, cls); index += 2; // 2: pair of extractor and literal } diff --git a/ecmascript/jspandafile/panda_file_translator.h b/ecmascript/jspandafile/panda_file_translator.h index 802a7adb08b68e2b9a2786e806426c1b99d93657..33ddaa8cc5f51d86ed370e11c496b76958dcee5b 100644 --- a/ecmascript/jspandafile/panda_file_translator.h +++ b/ecmascript/jspandafile/panda_file_translator.h @@ -60,7 +60,8 @@ private: static void FixOpcode(uint8_t *pc); static void UpdateICOffset(JSMethod *method, uint8_t *pc); static JSTaggedValue ParseConstPool(EcmaVM *vm, const JSPandaFile *jsPandaFile); - static void DefineClassInConstPool(JSThread *thread, JSHandle constpool); + static void DefineClassesInConstPool(JSThread *thread, JSHandle constpool, + const JSPandaFile *jsPandaFile); }; } // namespace panda::ecmascript #endif // ECMASCRIPT_JSPANDAFILE_PANDA_FILE_TRANSLATOR_H diff --git a/ecmascript/jspandafile/program_object.h b/ecmascript/jspandafile/program_object.h index 4b8a79dc6a4207510ffd172e03c73d06f01e9b99..54f365d2473f57db3c869cfadef9e792aee3847a 100644 --- a/ecmascript/jspandafile/program_object.h +++ b/ecmascript/jspandafile/program_object.h @@ -37,7 +37,7 @@ public: class ConstantPool : public TaggedArray { public: - static ConstantPool *Cast(ObjectHeader *object) + static ConstantPool *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsTaggedArray()); return static_cast(object); diff --git a/ecmascript/layout_info.cpp b/ecmascript/layout_info.cpp index 2fa3d9be91b7818e7bd7b94ca6ed16489871e365..9302197324cd96fc34367935f39db13421adc362 100644 --- a/ecmascript/layout_info.cpp +++ b/ecmascript/layout_info.cpp @@ -15,6 +15,7 @@ #include "ecmascript/layout_info-inl.h" #include "ecmascript/ecma_string.h" +#include "ecmascript/js_object-inl.h" #include "ecmascript/js_symbol.h" #include "ecmascript/mem/assert_scope.h" @@ -42,7 +43,8 @@ void LayoutInfo::AddKey(const JSThread *thread, [[maybe_unused]] int index, cons SetSortedIndex(thread, insertIndex, number); } -void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray) +void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, + const JSHandle object) { ASSERT(end <= NumberOfElements()); ASSERT_PRINT(offset + end <= static_cast(keyArray->GetLength()), @@ -53,6 +55,9 @@ void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedA for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString()) { + if (IsUninitializedProperty(object, i)) { + continue; + } keyArray->Set(thread, enumKeys + offset, key); enumKeys++; } @@ -69,19 +74,22 @@ void LayoutInfo::GetAllKeys(const JSThread *thread, int end, int offset, TaggedA } } -void LayoutInfo::GetAllKeys([[maybe_unused]] const JSThread *thread, int end, std::vector &keyVector) +void LayoutInfo::GetAllKeys(int end, std::vector &keyVector, const JSHandle object) { ASSERT(end <= NumberOfElements()); for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString() || key.IsSymbol()) { + if (IsUninitializedProperty(object, i)) { + continue; + } keyVector.emplace_back(key); } } } void LayoutInfo::GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, - uint32_t *keys) + uint32_t *keys, const JSHandle object) { ASSERT(end <= NumberOfElements()); ASSERT_PRINT(offset + end <= static_cast(keyArray->GetLength()), @@ -92,6 +100,9 @@ void LayoutInfo::GetAllEnumKeys(const JSThread *thread, int end, int offset, Tag for (int i = 0; i < end; i++) { JSTaggedValue key = GetKey(i); if (key.IsString() && GetAttr(i).IsEnumerable()) { + if (IsUninitializedProperty(object, i)) { + continue; + } keyArray->Set(thread, enumKeys + offset, key); enumKeys++; } @@ -99,20 +110,14 @@ void LayoutInfo::GetAllEnumKeys(const JSThread *thread, int end, int offset, Tag *keys += enumKeys; } -void LayoutInfo::GetAllNames(const JSThread *thread, int end, const JSHandle &keyArray, - uint32_t *length) +bool LayoutInfo::IsUninitializedProperty(const JSHandle object, uint32_t index) { - DISALLOW_GARBAGE_COLLECTION; - int arrayIndex = 0; - for (int i = 0; i < end; i++) { - JSTaggedValue key = GetKey(i); - if (key.IsString()) { - PropertyAttributes attr = GetAttr(i); - if (attr.IsEnumerable()) { - keyArray->Set(thread, arrayIndex++, key); - } - } + PropertyAttributes attr = GetAttr(index); + if (!attr.IsInlinedProps()) { + return false; } - *length += arrayIndex; + + JSTaggedValue val = object->GetPropertyInlinedProps(attr.GetOffset()); + return val.IsHole(); } } // namespace panda::ecmascript diff --git a/ecmascript/layout_info.h b/ecmascript/layout_info.h index 8696cf39d5f6fc74491b97c10dda08e28e4274ff..c11ef78488bb561368f3d463019dc977a55d4fa9 100644 --- a/ecmascript/layout_info.h +++ b/ecmascript/layout_info.h @@ -33,7 +33,7 @@ public: static constexpr int NUMBER_OF_PROPERTIES_INDEX = 0; static constexpr int ELEMENTS_START_INDEX = 1; - inline static LayoutInfo *Cast(ObjectHeader *obj) + inline static LayoutInfo *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsTaggedArray()); return reinterpret_cast(obj); @@ -78,12 +78,16 @@ public: int FindElementWithCache(JSThread *thread, JSHClass *cls, JSTaggedValue key, int propertiesNumber); int BinarySearch(JSTaggedValue key, int propertiesNumber); - void GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray); - void GetAllKeys(const JSThread *thread, int end, std::vector &keyVector); - void GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, uint32_t *keys); - void GetAllNames(const JSThread *thread, int end, const JSHandle &keyArray, uint32_t *length); + void GetAllKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, + const JSHandle object); + void GetAllKeys(int end, std::vector &keyVector, const JSHandle object); + void GetAllEnumKeys(const JSThread *thread, int end, int offset, TaggedArray *keyArray, uint32_t *keys, + const JSHandle object); DECL_DUMP() + +private: + bool IsUninitializedProperty(const JSHandle object, uint32_t index); }; } // namespace panda::ecmascript diff --git a/ecmascript/lexical_env.h b/ecmascript/lexical_env.h index 4aa0ff4b71617548228fdfc731b890ea8d6f2b65..57cbc3d8aeb354145b9a7503ea355208def1b858 100644 --- a/ecmascript/lexical_env.h +++ b/ecmascript/lexical_env.h @@ -25,7 +25,7 @@ public: static constexpr uint32_t SCOPE_INFO_INDEX = 1; static constexpr uint32_t RESERVED_ENV_LENGTH = 2; - static LexicalEnv *Cast(ObjectHeader *object) + static LexicalEnv *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsTaggedArray()); return static_cast(object); diff --git a/ecmascript/linked_hash_table.cpp b/ecmascript/linked_hash_table.cpp index 1c86cebf4130cc3bf00c226d5f63f575ad036929..8803df775e85b16a5dff0eced64a77197e482711 100644 --- a/ecmascript/linked_hash_table.cpp +++ b/ecmascript/linked_hash_table.cpp @@ -88,42 +88,6 @@ JSHandle LinkedHashTable::InsertWeakRef(const JSTh return newTable; } -template -void LinkedHashTable::Rehash(const JSThread *thread, Derived *newTable) -{ - ASSERT_PRINT(newTable != nullptr && newTable->Capacity() > NumberOfElements(), "can not rehash to new table"); - // Rehash elements to new table - int numberOfAllElements = NumberOfElements() + NumberOfDeletedElements(); - int desEntry = 0; - int currentDeletedElements = 0; - SetNextTable(thread, JSTaggedValue(newTable)); - for (int i = 0; i < numberOfAllElements; i++) { - int fromIndex = static_cast(EntryToIndex(i)); - JSTaggedValue key = GetElement(fromIndex); - if (key.IsHole()) { - // store num_of_deleted_element before entry i; it will be used when iterator update. - currentDeletedElements++; - SetDeletedNum(thread, i, JSTaggedValue(currentDeletedElements)); - continue; - } - - if (key.IsWeak()) { - // If the key is a weak reference, we use the weak referent to calculate the new index in the new table. - key.RemoveWeakTag(); - } - - int bucket = static_cast(newTable->HashToBucket(LinkedHash::Hash(key))); - newTable->InsertNewEntry(thread, bucket, desEntry); - int desIndex = static_cast(newTable->EntryToIndex(desEntry)); - for (int j = 0; j < HashObject::ENTRY_SIZE; j++) { - newTable->SetElement(thread, desIndex + j, GetElement(fromIndex + j)); - } - desEntry++; - } - newTable->SetNumberOfElements(thread, NumberOfElements()); - newTable->SetNumberOfDeletedElements(thread, 0); -} - template JSHandle LinkedHashTable::GrowCapacity(const JSThread *thread, const JSHandle &table, int numberOfAddedElements) @@ -273,20 +237,20 @@ int LinkedHash::Hash(JSTaggedValue key) key = JSTaggedValue(0); } if (key.IsSymbol()) { - auto symbolString = JSSymbol::Cast(key.GetHeapObject()); + auto symbolString = JSSymbol::Cast(key.GetTaggedObject()); return symbolString->GetHashField(); } if (key.IsString()) { - auto keyString = reinterpret_cast(key.GetHeapObject()); + auto keyString = reinterpret_cast(key.GetTaggedObject()); return keyString->GetHashcode(); } if (key.IsECMAObject()) { - int32_t hash = ECMAObject::Cast(key.GetHeapObject())->GetHash(); + int32_t hash = ECMAObject::Cast(key.GetTaggedObject())->GetHash(); if (hash == 0) { uint64_t keyValue = key.GetRawData(); hash = static_cast( GetHash32(reinterpret_cast(&keyValue), sizeof(keyValue) / sizeof(uint8_t))); - ECMAObject::Cast(key.GetHeapObject())->SetHash(hash); + ECMAObject::Cast(key.GetTaggedObject())->SetHash(hash); } return hash; } diff --git a/ecmascript/linked_hash_table.h b/ecmascript/linked_hash_table.h index 882bd806ff96c54a9f79dc799eee398ff3e5ab3f..5413c1a491316a561f320e6d51c2d76530fcb11b 100644 --- a/ecmascript/linked_hash_table.h +++ b/ecmascript/linked_hash_table.h @@ -64,8 +64,6 @@ public: static JSHandle Shrink(const JSThread *thread, const JSHandle &table, int additionalCapacity = 0); - void Rehash(const JSThread *thread, Derived *newTable); - inline bool HasSufficientCapacity(int numOfAddElements) const { int numberOfElements = NumberOfElements(); @@ -214,6 +212,41 @@ public: return 0; } + inline void Rehash(const JSThread *thread, Derived *newTable) + { + ASSERT_PRINT(newTable != nullptr && newTable->Capacity() > NumberOfElements(), "can not rehash to new table"); + // Rehash elements to new table + int numberOfAllElements = NumberOfElements() + NumberOfDeletedElements(); + int desEntry = 0; + int currentDeletedElements = 0; + SetNextTable(thread, JSTaggedValue(newTable)); + for (int i = 0; i < numberOfAllElements; i++) { + int fromIndex = static_cast(EntryToIndex(i)); + JSTaggedValue key = GetElement(fromIndex); + if (key.IsHole()) { + // store num_of_deleted_element before entry i; it will be used when iterator update. + currentDeletedElements++; + SetDeletedNum(thread, i, JSTaggedValue(currentDeletedElements)); + continue; + } + + if (key.IsWeak()) { + // If the key is a weak reference, we use the weak referent to calculate the new index in the new table. + key.RemoveWeakTag(); + } + + int bucket = static_cast(newTable->HashToBucket(LinkedHash::Hash(key))); + newTable->InsertNewEntry(thread, bucket, desEntry); + int desIndex = static_cast(newTable->EntryToIndex(desEntry)); + for (int j = 0; j < HashObject::ENTRY_SIZE; j++) { + newTable->SetElement(thread, desIndex + j, GetElement(fromIndex + j)); + } + desEntry++; + } + newTable->SetNumberOfElements(thread, NumberOfElements()); + newTable->SetNumberOfDeletedElements(thread, 0); + } + protected: inline JSTaggedValue GetElement(int index) const { @@ -302,7 +335,7 @@ public: class LinkedHashMap : public LinkedHashTable { public: - static LinkedHashMap *Cast(ObjectHeader *obj) + static LinkedHashMap *Cast(TaggedObject *obj) { return static_cast(obj); } @@ -342,7 +375,7 @@ public: class LinkedHashSet : public LinkedHashTable { public: - static LinkedHashSet *Cast(ObjectHeader *obj) + static LinkedHashSet *Cast(TaggedObject *obj) { return static_cast(obj); } diff --git a/ecmascript/compiler/llvm/llvm_stackmap_parser.cpp b/ecmascript/llvm_stackmap_parser.cpp similarity index 65% rename from ecmascript/compiler/llvm/llvm_stackmap_parser.cpp rename to ecmascript/llvm_stackmap_parser.cpp index 747568e3c964a2bd582ca210ab1d26b4e55a1c6c..cb124ff72c4e8abade436dfcb4818173b90aff05 100644 --- a/ecmascript/compiler/llvm/llvm_stackmap_parser.cpp +++ b/ecmascript/llvm_stackmap_parser.cpp @@ -13,7 +13,7 @@ * limitations under the License. */ -#include "ecmascript/compiler/llvm/llvm_stackmap_parser.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "ecmascript/compiler/assembler/assembler.h" #include "ecmascript/frames.h" #include "ecmascript/mem/slots.h" @@ -42,149 +42,103 @@ std::string LocationTy::TypeToString(Kind loc) const const CallSiteInfo* LLVMStackMapParser::GetCallSiteInfoByPc(uintptr_t callSiteAddr) const { - for (auto &callSiteInfo: pc2CallSiteInfoVec_) { - auto it = callSiteInfo.find(callSiteAddr); - if (it != callSiteInfo.end()) { + for (auto &pc2CallSiteInfo: pc2CallSiteInfoVec_) { + auto it = pc2CallSiteInfo.find(callSiteAddr); + if (it != pc2CallSiteInfo.end()) { return &(it->second); } } return nullptr; } -void LLVMStackMapParser::PrintCallSiteInfo(const CallSiteInfo *infos, OptimizedLeaveFrame *frame) const +void LLVMStackMapParser::PrintCallSiteSlotAddr(const CallSiteInfo& callsiteInfo, uintptr_t callSiteSp, + uintptr_t callsiteFp) const { - if (!IsLogEnabled()) { - return; - } - - int i = 0; - uintptr_t address = 0; - uintptr_t base = 0; - uintptr_t derived = 0; - for (auto &info: *infos) { - if (info.first == GCStackMapRegisters::SP) { - uintptr_t rsp = frame->GetCallSiteSp(); - address = rsp + info.second; - COMPILER_LOG(DEBUG) << std::dec << "SP_DWARF_REG_NUM: info.second:" << info.second - << std::hex << "rsp :" << rsp; - } else if (info.first == GCStackMapRegisters::FP) { - uintptr_t fp = frame->callsiteFp; - address = fp + info.second; - COMPILER_LOG(DEBUG) << std::dec << "FP_DWARF_REG_NUM: info.second:" << info.second - << std::hex << "rfp :" << fp; - } else { - COMPILER_LOG(DEBUG) << "REG_NUM : info.first:" << info.first; - UNREACHABLE(); + bool flag = (callsiteInfo.size() % 2 != 0); + size_t j = flag ? 1 : 0; // skip first element when size is odd number + for (; j < callsiteInfo.size(); j += 2) { // 2: base and derived + const DwarfRegAndOffsetType baseInfo = callsiteInfo[j]; + const DwarfRegAndOffsetType derivedInfo = callsiteInfo[j + 1]; + LOG_COMPILER(VERBOSE) << std::hex << " callSiteSp:0x" << callSiteSp << " callsiteFp:" << callsiteFp; + LOG_COMPILER(VERBOSE) << std::dec << "base DWARF_REG:" << baseInfo.first + << " OFFSET:" << baseInfo.second; + uintptr_t base = GetStackSlotAddress(baseInfo, callSiteSp, callsiteFp); + uintptr_t derived = GetStackSlotAddress(derivedInfo, callSiteSp, callsiteFp); + if (base != derived) { + LOG_COMPILER(VERBOSE) << std::dec << "derived DWARF_REG:" << derivedInfo.first + << " OFFSET:" << derivedInfo.second; } - - if (IsDeriveredPointer(i)) { - derived = reinterpret_cast(address); - if (base == derived) { - COMPILER_LOG(INFO) << std::hex << "visit base:" << base << " base Value: " << - *reinterpret_cast(base); - } else { - COMPILER_LOG(INFO) << std::hex << "push base:" << base << " base Value: " << - *reinterpret_cast(base) << " derived:" << derived; - } - } else { - base = reinterpret_cast(address); - } - i++; } } +void LLVMStackMapParser::PrintCallSiteInfo(const CallSiteInfo *infos, OptimizedLeaveFrame *frame) const +{ + uintptr_t callSiteSp = frame->GetCallSiteSp(); + uintptr_t callsiteFp = frame->callsiteFp; + ASSERT(infos != nullptr); + PrintCallSiteSlotAddr(*infos, callSiteSp, callsiteFp); +} -void LLVMStackMapParser::PrintCallSiteInfo(const CallSiteInfo *infos, uintptr_t *fp, uintptr_t curPc) const +void LLVMStackMapParser::PrintCallSiteInfo(const CallSiteInfo *infos, uintptr_t callsiteFp, uintptr_t callSiteSp) const { if (!IsLogEnabled()) { return; } - int i = 0; - uintptr_t address = 0; - uintptr_t base = 0; - uintptr_t derived = 0; - - uintptr_t callsiteFp = *fp; - uintptr_t callSiteSp = FrameHandler::GetPrevFrameCallSiteSp(reinterpret_cast(fp), curPc); - - for (auto &info: *infos) { - if (info.first == GCStackMapRegisters::SP) { - address = callSiteSp + info.second; - } else if (info.first == GCStackMapRegisters::FP) { - address = callsiteFp + info.second; - } else { - UNREACHABLE(); - } + CallSiteInfo callsiteInfo = *infos; + PrintCallSiteSlotAddr(*infos, callSiteSp, callsiteFp); +} - if (IsDeriveredPointer(i)) { - derived = reinterpret_cast(address); - if (base == derived) { - COMPILER_LOG(DEBUG) << std::hex << "visit base:" << base << " base Value: " << - *reinterpret_cast(base); - } else { - COMPILER_LOG(DEBUG) << std::hex << "push base:" << base << " base Value: " << - *reinterpret_cast(base) << " derived:" << derived; - } - } else { - base = reinterpret_cast(address); - } - i++; +uintptr_t LLVMStackMapParser::GetStackSlotAddress(const DwarfRegAndOffsetType info, + uintptr_t callSiteSp, uintptr_t callsiteFp) const +{ + uintptr_t address = 0; + if (info.first == GCStackMapRegisters::SP) { + address = callSiteSp + info.second; + } else if (info.first == GCStackMapRegisters::FP) { + address = callsiteFp + info.second; + } else { + UNREACHABLE(); } + return address; } -bool LLVMStackMapParser::IsDeriveredPointer(int callsitetime) const +void LLVMStackMapParser::CollectBaseAndDerivedPointers(const CallSiteInfo* infos, std::set &baseSet, + ChunkMap *data, [[maybe_unused]] bool isVerifying, + uintptr_t callsiteFp, uintptr_t callSiteSp) const { - return static_cast(callsitetime) & 1; + bool flag = (infos->size() % 2 != 0); + size_t j = flag ? 1 : 0; // skip first element when size is odd number + for (; j < infos->size(); j += 2) { // 2: base and derived + const DwarfRegAndOffsetType& baseInfo = infos->at(j); + const DwarfRegAndOffsetType& derivedInfo = infos->at(j + 1); + uintptr_t base = GetStackSlotAddress(baseInfo, callSiteSp, callsiteFp); + uintptr_t derived = GetStackSlotAddress(derivedInfo, callSiteSp, callsiteFp); + baseSet.emplace(base); + if (base != derived) { +#if ECMASCRIPT_ENABLE_HEAP_VERIFY + if (!isVerifying) { +#endif + data->emplace(std::make_pair(base, derived), *reinterpret_cast(base)); +#if ECMASCRIPT_ENABLE_HEAP_VERIFY + } +#endif + } + } } -bool LLVMStackMapParser::CollectStackMapSlots(uintptr_t callSiteAddr, uintptr_t frameFp, +bool LLVMStackMapParser::CollectGCSlots(uintptr_t callSiteAddr, uintptr_t callsiteFp, std::set &baseSet, ChunkMap *data, [[maybe_unused]] bool isVerifying, - uintptr_t curPc) const + uintptr_t callSiteSp) const { const CallSiteInfo *infos = GetCallSiteInfoByPc(callSiteAddr); if (infos == nullptr) { return false; } - - uintptr_t *fp = reinterpret_cast(frameFp); - uintptr_t callsiteFp = *fp; - uintptr_t callSiteSp = FrameHandler::GetPrevFrameCallSiteSp(reinterpret_cast(frameFp), curPc); - uintptr_t address = 0; - uintptr_t base = 0; - uintptr_t derived = 0; - int i = 0; + ASSERT(callsiteFp != callSiteSp); + CollectBaseAndDerivedPointers(infos, baseSet, data, isVerifying, callsiteFp, callSiteSp); if (IsLogEnabled()) { - PrintCallSiteInfo(infos, fp, curPc); - } - - for (auto &info: *infos) { - if (info.first == GCStackMapRegisters::SP) { - address = callSiteSp + info.second; - } else if (info.first == GCStackMapRegisters::FP) { - address = callsiteFp + info.second; - } else { - UNREACHABLE(); - } - - if (IsDeriveredPointer(i)) { - derived = reinterpret_cast(address); - if (base == derived) { - baseSet.emplace(base); - } else { -#if ECMASCRIPT_ENABLE_HEAP_VERIFY - if (!isVerifying) { -#endif - data->emplace(std::make_pair(base, derived), *reinterpret_cast(base)); -#if ECMASCRIPT_ENABLE_HEAP_VERIFY - } -#endif - } - } else { - base = reinterpret_cast(address); - baseSet.emplace(base); - } - i++; + PrintCallSiteInfo(infos, callsiteFp, callSiteSp); } return true; } @@ -203,7 +157,7 @@ void LLVMStackMapParser::CalcCallSite() uintptr_t callsite = address + instructionOffset; uint64_t patchPointID = recordHead.PatchPointID; if (loc.location == LocationTy::Kind::INDIRECT) { - COMPILER_OPTIONAL_LOG(DEBUG) << "DwarfRegNum:" << loc.DwarfRegNum << " loc.OffsetOrSmallConstant:" + OPTIONAL_LOG_COMPILER(DEBUG) << "DwarfRegNum:" << loc.DwarfRegNum << " loc.OffsetOrSmallConstant:" << loc.OffsetOrSmallConstant << "address:" << address << " instructionOffset:" << instructionOffset << " callsite:" << " patchPointID :" << std::hex << patchPointID << callsite; @@ -236,7 +190,7 @@ void LLVMStackMapParser::CalcCallSite() bool LLVMStackMapParser::CalculateStackMap(std::unique_ptr stackMapAddr) { if (!stackMapAddr) { - COMPILER_LOG(ERROR) << "stackMapAddr nullptr error ! "; + LOG_COMPILER(ERROR) << "stackMapAddr nullptr error ! "; return false; } dataInfo_ = std::make_unique(std::move(stackMapAddr)); @@ -290,13 +244,13 @@ bool LLVMStackMapParser::CalculateStackMap(std::unique_ptr stackMapA } // update functionAddress from host side to device side - COMPILER_OPTIONAL_LOG(DEBUG) << "stackmap calculate update funcitonaddress "; + OPTIONAL_LOG_COMPILER(DEBUG) << "stackmap calculate update funcitonaddress "; for (size_t i = 0; i < llvmStackMap_.StkSizeRecords.size(); i++) { uintptr_t hostAddr = llvmStackMap_.StkSizeRecords[i].functionAddress; uintptr_t deviceAddr = hostAddr - hostCodeSectionAddr + deviceCodeSectionAddr; llvmStackMap_.StkSizeRecords[i].functionAddress = deviceAddr; - COMPILER_OPTIONAL_LOG(DEBUG) << std::dec << i << "th function " << std::hex << hostAddr << " ---> " + OPTIONAL_LOG_COMPILER(DEBUG) << std::dec << i << "th function " << std::hex << hostAddr << " ---> " << deviceAddr; } CalcCallSite(); diff --git a/ecmascript/compiler/llvm/llvm_stackmap_parser.h b/ecmascript/llvm_stackmap_parser.h similarity index 73% rename from ecmascript/compiler/llvm/llvm_stackmap_parser.h rename to ecmascript/llvm_stackmap_parser.h index e209cb516fc2038b55aad27ef720dafbd0d2f625..89a9fbd73e0d8c298bf1a23166fef84341ea2c45 100644 --- a/ecmascript/compiler/llvm/llvm_stackmap_parser.h +++ b/ecmascript/llvm_stackmap_parser.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef ECMASCRIPT_COMPILER_LLVM_LLVMSTACKPARSE_H -#define ECMASCRIPT_COMPILER_LLVM_LLVMSTACKPARSE_H +#ifndef ECMASCRIPT_LLVM_STACKMAP_PARSER_H +#define ECMASCRIPT_LLVM_STACKMAP_PARSER_H #include #include @@ -43,9 +43,9 @@ struct Header { uint16_t Reserved1; // Reserved (expected to be 0) void Print() const { - COMPILER_LOG(DEBUG) << "----- head ----"; - COMPILER_LOG(DEBUG) << " version:" << static_cast(stackmapversion); - COMPILER_LOG(DEBUG) << "+++++ head ++++"; + LOG_COMPILER(DEBUG) << "----- head ----"; + LOG_COMPILER(DEBUG) << " version:" << static_cast(stackmapversion); + LOG_COMPILER(DEBUG) << "+++++ head ++++"; } }; @@ -56,9 +56,9 @@ struct StkSizeRecordTy { uint64_t recordCount; void Print() const { - COMPILER_LOG(DEBUG) << " functionAddress:0x" << std::hex << functionAddress; - COMPILER_LOG(DEBUG) << " stackSize:0x" << std::hex << stackSize; - COMPILER_LOG(DEBUG) << " recordCount:" << std::hex << recordCount; + LOG_COMPILER(DEBUG) << " functionAddress:0x" << std::hex << functionAddress; + LOG_COMPILER(DEBUG) << " stackSize:0x" << std::hex << stackSize; + LOG_COMPILER(DEBUG) << " recordCount:" << std::hex << recordCount; } }; #pragma pack() @@ -67,7 +67,7 @@ struct ConstantsTy { uintptr_t LargeConstant; void Print() const { - COMPILER_LOG(DEBUG) << " LargeConstant:0x" << std::hex << LargeConstant; + LOG_COMPILER(DEBUG) << " LargeConstant:0x" << std::hex << LargeConstant; } }; @@ -78,10 +78,10 @@ struct StkMapRecordHeadTy { uint16_t NumLocations; void Print() const { - COMPILER_LOG(DEBUG) << " PatchPointID:0x" << std::hex << PatchPointID; - COMPILER_LOG(DEBUG) << " instructionOffset:0x" << std::hex << InstructionOffset; - COMPILER_LOG(DEBUG) << " Reserved:0x" << std::hex << Reserved; - COMPILER_LOG(DEBUG) << " NumLocations:0x" << std::hex << NumLocations; + LOG_COMPILER(DEBUG) << " PatchPointID:0x" << std::hex << PatchPointID; + LOG_COMPILER(DEBUG) << " instructionOffset:0x" << std::hex << InstructionOffset; + LOG_COMPILER(DEBUG) << " Reserved:0x" << std::hex << Reserved; + LOG_COMPILER(DEBUG) << " NumLocations:0x" << std::hex << NumLocations; } }; @@ -105,10 +105,10 @@ struct LocationTy { void Print() const { - COMPILER_LOG(DEBUG) << TypeToString(location); - COMPILER_LOG(DEBUG) << ", size:" << std::dec << LocationSize; - COMPILER_LOG(DEBUG) << "\tDwarfRegNum:" << DwarfRegNum; - COMPILER_LOG(DEBUG) << "\t OffsetOrSmallConstant:" << OffsetOrSmallConstant; + LOG_COMPILER(DEBUG) << TypeToString(location); + LOG_COMPILER(DEBUG) << ", size:" << std::dec << LocationSize; + LOG_COMPILER(DEBUG) << "\tDwarfRegNum:" << DwarfRegNum; + LOG_COMPILER(DEBUG) << "\t OffsetOrSmallConstant:" << OffsetOrSmallConstant; } }; @@ -118,9 +118,9 @@ struct LiveOutsTy { uint8_t SizeinBytes; void Print() const { - COMPILER_LOG(DEBUG) << " Dwarf RegNum:" << DwarfRegNum; - COMPILER_LOG(DEBUG) << " Reserved:" << Reserved; - COMPILER_LOG(DEBUG) << " SizeinBytes:" << SizeinBytes; + LOG_COMPILER(DEBUG) << " Dwarf RegNum:" << DwarfRegNum; + LOG_COMPILER(DEBUG) << " Reserved:" << Reserved; + LOG_COMPILER(DEBUG) << " SizeinBytes:" << SizeinBytes; } }; @@ -133,12 +133,12 @@ struct StkMapRecordTy { head.Print(); auto size = Locations.size(); for (size_t i = 0; i < size; i++) { - COMPILER_LOG(DEBUG) << " #" << std::dec << i << ":"; + LOG_COMPILER(DEBUG) << " #" << std::dec << i << ":"; Locations[i].Print(); } size = LiveOuts.size(); for (size_t i = 0; i < size; i++) { - COMPILER_LOG(DEBUG) << " liveOuts[" << i << "] info:"; + LOG_COMPILER(DEBUG) << " liveOuts[" << i << "] info:"; } } }; @@ -176,15 +176,15 @@ struct LLVMStackMap { { head.Print(); for (size_t i = 0; i < StkSizeRecords.size(); i++) { - COMPILER_LOG(DEBUG) << "stkSizeRecord[" << i << "] info:"; + LOG_COMPILER(DEBUG) << "stkSizeRecord[" << i << "] info:"; StkSizeRecords[i].Print(); } for (size_t i = 0; i < Constants.size(); i++) { - COMPILER_LOG(DEBUG) << "constants[" << i << "] info:"; + LOG_COMPILER(DEBUG) << "constants[" << i << "] info:"; Constants[i].Print(); } for (size_t i = 0; i < StkMapRecord.size(); i++) { - COMPILER_LOG(DEBUG) << "StkMapRecord[" << i << "] info:"; + LOG_COMPILER(DEBUG) << "StkMapRecord[" << i << "] info:"; StkMapRecord[i].Print(); } } @@ -192,11 +192,6 @@ struct LLVMStackMap { class LLVMStackMapParser { public: - static LLVMStackMapParser& GetInstance(bool enableLog = false) - { - static LLVMStackMapParser instance(enableLog); - return instance; - } bool PUBLIC_API CalculateStackMap(std::unique_ptr stackMapAddr); bool PUBLIC_API CalculateStackMap(std::unique_ptr stackMapAddr, uintptr_t hostCodeSectionAddr, uintptr_t deviceCodeSectionAddr); @@ -207,11 +202,10 @@ public: } } const CallSiteInfo *GetCallSiteInfoByPc(uintptr_t funcAddr) const; - bool CollectStackMapSlots(uintptr_t callSiteAddr, uintptr_t frameFp, + bool CollectGCSlots(uintptr_t callSiteAddr, uintptr_t callsiteFp, std::set &baseSet, ChunkMap *data, [[maybe_unused]] bool isVerifying, - uintptr_t curPc) const; - + uintptr_t callSiteSp) const; bool IsLogEnabled() const { return enableLog_; @@ -219,20 +213,19 @@ public: void PUBLIC_API CalculateFuncFpDelta(Func2FpDelta info); int PUBLIC_API GetFuncFpDelta(uintptr_t callsitePc) const; - ConstInfo GetConstInfo(uintptr_t callsite) + ConstInfo GetConstInfo(uintptr_t callsite) const { // next optimization can be performed via sorted/map to accelerate the search for (auto &pc2ConstInfo : pc2ConstInfoVec_) { auto it = pc2ConstInfo.find(callsite); if (it != pc2ConstInfo.end()) { - return pc2ConstInfo[callsite]; + return pc2ConstInfo.at(callsite); } } return {}; } -private: - explicit LLVMStackMapParser(bool enableLog) + explicit LLVMStackMapParser(bool enableLog = false) { pc2CallSiteInfoVec_.clear(); dataInfo_ = nullptr; @@ -249,11 +242,18 @@ private: fun2FpDelta_.clear(); pc2ConstInfoVec_.clear(); } +private: void CalcCallSite(); - bool IsDeriveredPointer(int callsitetime) const; void PrintCallSiteInfo(const CallSiteInfo *infos, OptimizedLeaveFrame *frame) const; - void PrintCallSiteInfo(const CallSiteInfo *infos, uintptr_t *fp, uintptr_t curPc) const; + void PrintCallSiteInfo(const CallSiteInfo *infos, uintptr_t callSiteFp, uintptr_t callSiteSp) const; int FindFpDelta(uintptr_t funcAddr, uintptr_t callsitePc) const; + inline uintptr_t GetStackSlotAddress(const DwarfRegAndOffsetType info, + uintptr_t callSiteSp, uintptr_t callsiteFp) const; + void CollectBaseAndDerivedPointers(const CallSiteInfo *infos, std::set &baseSet, + ChunkMap *data, [[maybe_unused]] bool isVerifying, + uintptr_t callsiteFp, uintptr_t callSiteSp) const; + void PrintCallSiteSlotAddr(const CallSiteInfo& callsiteInfo, uintptr_t callSiteSp, + uintptr_t callsiteFp) const; struct LLVMStackMap llvmStackMap_; std::vector pc2CallSiteInfoVec_; @@ -264,4 +264,4 @@ private: std::vector pc2ConstInfoVec_; }; } // namespace panda::ecmascript::kungfu -#endif // ECMASCRIPT_COMPILER_LLVM_LLVMSTACKPARSE_H \ No newline at end of file +#endif // ECMASCRIPT_LLVM_STACKMAP_PARSER_H \ No newline at end of file diff --git a/ecmascript/log.h b/ecmascript/log.h new file mode 100644 index 0000000000000000000000000000000000000000..c433c54624bb3b9ab68bd4f19dacc3e408f1842a --- /dev/null +++ b/ecmascript/log.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_LOG_H +#define ECMASCRIPT_LOG_H + +#include + +#include "hilog/log.h" + +constexpr static unsigned int DOMAIN = 0xD003F00; +constexpr static auto TAG = "ArkCompiler"; +constexpr static OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, DOMAIN, TAG}; + +#if ECMASCRIPT_ENABLE_VERBOSE_LEVEL_LOG +// print Debug level log if enable Verbose log +#define LOG_VERBOSE LOG_DEBUG +#else +#define LOG_VERBOSE LOG_LEVEL_MIN +#endif + +namespace panda::ecmascript { +template +class Log { +public: + Log() = default; + ~Log() + { + if constexpr (level == LOG_LEVEL_MIN) { + // print nothing + } else if constexpr (level == LOG_DEBUG) { + OHOS::HiviewDFX::HiLog::Debug(LABEL, "%{public}s", stream_.str().c_str()); + } else if constexpr (level == LOG_INFO) { + OHOS::HiviewDFX::HiLog::Info(LABEL, "%{public}s", stream_.str().c_str()); + } else if constexpr (level == LOG_WARN) { + OHOS::HiviewDFX::HiLog::Warn(LABEL, "%{public}s", stream_.str().c_str()); + } else if constexpr (level == LOG_ERROR) { + OHOS::HiviewDFX::HiLog::Error(LABEL, "%{public}s", stream_.str().c_str()); + } else { + OHOS::HiviewDFX::HiLog::Fatal(LABEL, "%{public}s", stream_.str().c_str()); + } + } + template + std::ostream &operator <<(type input) + { + stream_ << input; + return stream_; + } + +private: + std::ostringstream stream_; +}; +} // namespace panda::ecmascript + +#define HILOG_ECMA(level) HiLogIsLoggable(DOMAIN, TAG, LOG_##level) && panda::ecmascript::Log() + +#endif // ECMASCRIPT_LOG_H diff --git a/ecmascript/log_wrapper.h b/ecmascript/log_wrapper.h new file mode 100644 index 0000000000000000000000000000000000000000..b6956cf34fde4a9f3386c8088244f3ccc9e2202a --- /dev/null +++ b/ecmascript/log_wrapper.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_LOG_WRAPPER_H +#define ECMASCRIPT_LOG_WRAPPER_H + +#ifdef ENABLE_HILOG + +#include "ecmascript/log.h" + +#define LOG_ECMA(level) HILOG_ECMA(level) + +#else // ENABLE_HILOG + +#include "libpandabase/utils/logger.h" + +// HILOG use WARN, but panda use WARNING +#define _LOG_WARN(component, p) _LOG_WARNING(component, p) +// print Verbose log as Debug in host +#define _LOG_VERBOSE(component, p) _LOG_DEBUG(component, p) + +#define LOG_ECMA(level) LOG(level, ECMASCRIPT) + +#endif // ENABLE_HILOG + +#define LOG_FULL(level) LOG_ECMA(level) << __func__ << ":" << __LINE__ << " " +#define LOG_GC(level) LOG_ECMA(level) << " gc: " +#define LOG_INTERPRETER(level) LOG_ECMA(level) << " interpreter: " +#define LOG_COMPILER(level) LOG_ECMA(level) << " compiler: " +#define LOG_DEBUGGER(level) LOG_ECMA(level) << " debugger: " +#define LOG_ECMA_IF(cond, level) (cond) && LOG_ECMA(level) + +#endif // ECMASCRIPT_LOG_WRAPPER_H diff --git a/ecmascript/mem/chunk.h b/ecmascript/mem/chunk.h index e79c0764e0057cb131084f855b06ede4cf4fdcae..a3d4e2d3b29c17f8589e62dfd0d5927e43a7bc5d 100644 --- a/ecmascript/mem/chunk.h +++ b/ecmascript/mem/chunk.h @@ -17,6 +17,7 @@ #define ECMASCRIPT_MEM_CHUNK_H #include "ecmascript/common.h" +#include "ecmascript/log_wrapper.h" #include "ecmascript/mem/ecma_list.h" #include "ecmascript/mem/area.h" diff --git a/ecmascript/mem/clock_scope.h b/ecmascript/mem/clock_scope.h index 73c4a3684e0e2771f0b2e708aa339620535aaac4..e0ef998a791990cdacbbd250803bd9d83a0b401b 100644 --- a/ecmascript/mem/clock_scope.h +++ b/ecmascript/mem/clock_scope.h @@ -18,7 +18,6 @@ #include "time.h" #include "chrono" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript { class ClockScope { diff --git a/ecmascript/mem/concurrent_marker.cpp b/ecmascript/mem/concurrent_marker.cpp index df40e0a50a3f74f0db2ce83e21343f437a2dfb16..532433f6ca647fa575e77f23a0e1d9ac878666fd 100644 --- a/ecmascript/mem/concurrent_marker.cpp +++ b/ecmascript/mem/concurrent_marker.cpp @@ -54,7 +54,7 @@ void ConcurrentMarker::EnableConcurrentMarking(EnableConcurrentMarkType type) void ConcurrentMarker::Mark() { - ECMA_GC_LOG() << "ConcurrentMarker: Concurrent Marking Begin"; + LOG_GC(DEBUG) << "ConcurrentMarker: Concurrent Marking Begin"; ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "ConcurrentMarker::Mark"); MEM_ALLOCATE_AND_GC_TRACE(vm_, ConcurrentMarking); ClockScope scope; @@ -68,13 +68,12 @@ void ConcurrentMarker::Mark() void ConcurrentMarker::Finish() { - size_t aliveSize = 0; - workManager_->Finish(aliveSize); + workManager_->Finish(); } void ConcurrentMarker::ReMark() { - ECMA_GC_LOG() << "ConcurrentMarker: Remarking Begin"; + LOG_GC(DEBUG) << "ConcurrentMarker: Remarking Begin"; MEM_ALLOCATE_AND_GC_TRACE(vm_, ReMarking); ClockScope scope; Marker *nonMovableMarker = heap_->GetNonMovableMarker(); diff --git a/ecmascript/mem/free_object_list.cpp b/ecmascript/mem/free_object_list.cpp index 711238a6f724ad067cf6e447ac250cecef38f805..fb48ef7f4aec993bd0d515d43bc566729985613f 100644 --- a/ecmascript/mem/free_object_list.cpp +++ b/ecmascript/mem/free_object_list.cpp @@ -136,7 +136,7 @@ void FreeObjectList::Free(uintptr_t start, size_t size, bool isAdd) Region *region = Region::ObjectAddressToRange(reinterpret_cast(start)); auto set = region->GetFreeObjectSet(type); if (set == nullptr) { - LOG_ECMA(FATAL) << "The set of region is nullptr"; + LOG_FULL(FATAL) << "The set of region is nullptr"; return; } set->Free(start, size); diff --git a/ecmascript/mem/full_gc.cpp b/ecmascript/mem/full_gc.cpp index 5360eab5604bffc65e6ae0ec0d326f8f83255efa..5a67a68207b727972807fd7510516e1a8f460542 100644 --- a/ecmascript/mem/full_gc.cpp +++ b/ecmascript/mem/full_gc.cpp @@ -37,7 +37,7 @@ void FullGC::RunPhases() ClockScope clockScope; if (heap_->CheckOngoingConcurrentMarking()) { - ECMA_GC_LOG() << "FullGC after ConcurrentMarking"; + LOG_GC(DEBUG) << "FullGC after ConcurrentMarking"; heap_->GetConcurrentMarker()->Reset(); // HPPGC use mark result to move TaggedObject. } Initialize(); @@ -47,7 +47,15 @@ void FullGC::RunPhases() heap_->GetEcmaVM()->GetEcmaGCStats()->StatisticFullGC(clockScope.GetPauseTime(), youngAndOldAliveSize_, youngSpaceCommitSize_, oldSpaceCommitSize_, nonMoveSpaceFreeSize_, nonMoveSpaceCommitSize_); - ECMA_GC_LOG() << "FullGC::RunPhases " << clockScope.TotalSpentTime(); + LOG_GC(DEBUG) << "FullGC::RunPhases " << clockScope.TotalSpentTime(); +} + +void FullGC::RunPhasesForAppSpawn() +{ + auto marker = reinterpret_cast(heap_->GetCompressGCMarker()); + marker->SetAppSpawn(true); + RunPhases(); + marker->SetAppSpawn(false); } void FullGC::Initialize() @@ -141,7 +149,7 @@ void FullGC::Finish() { ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "FullGC::Finish"); heap_->Resume(FULL_GC); - workManager_->Finish(youngAndOldAliveSize_); + youngAndOldAliveSize_ = workManager_->Finish(); heap_->GetSweeper()->TryFillSweptRegion(); } } // namespace panda::ecmascript diff --git a/ecmascript/mem/full_gc.h b/ecmascript/mem/full_gc.h index d4afe5a7356a98088260f3dbdb889924dd30c1e2..1f14684183a9a5ea672a3db0ed74159705bb465b 100644 --- a/ecmascript/mem/full_gc.h +++ b/ecmascript/mem/full_gc.h @@ -31,7 +31,7 @@ public: NO_MOVE_SEMANTIC(FullGC); void RunPhases() override; - + void RunPhasesForAppSpawn(); protected: void Initialize() override; void Mark() override; diff --git a/ecmascript/mem/gc_bitset.h b/ecmascript/mem/gc_bitset.h index 1f25e1f9b2d9ea6d54665c87e0717cd526ac67d1..199c121cbb8fd8cfe0f7d5b1e7389dc1ea9053dc 100644 --- a/ecmascript/mem/gc_bitset.h +++ b/ecmascript/mem/gc_bitset.h @@ -73,6 +73,16 @@ public: } } + void SetAllBits(size_t bitSize) + { + GCBitsetWord *words = Words(); + uint32_t wordCount = static_cast(WordCount(bitSize)); + GCBitsetWord mask = 0; + for (uint32_t i = 0; i < wordCount; i++) { + words[i] = ~mask; + } + } + template bool SetBit(uintptr_t offset); diff --git a/ecmascript/mem/gc_stats.cpp b/ecmascript/mem/gc_stats.cpp index 8067e9a2d666b15755de1a3c0e36bf4f6ccd8ba5..bdfdad1e216bf22d338041e45bf2ad52da2e786b 100644 --- a/ecmascript/mem/gc_stats.cpp +++ b/ecmascript/mem/gc_stats.cpp @@ -21,7 +21,7 @@ namespace panda::ecmascript { void GCStats::PrintStatisticResult(bool force) { - LOG(INFO, RUNTIME) << "/******************* GCStats statistic: *******************/"; + LOG_GC(INFO) << "/******************* GCStats statistic: *******************/"; PrintSemiStatisticResult(force); PrintPartialStatisticResult(force); PrintCompressStatisticResult(force); @@ -32,8 +32,8 @@ void GCStats::PrintSemiStatisticResult(bool force) { if ((force && semiGCCount_ != 0) || (!force && semiGCCount_ != lastSemiGCCount_)) { lastSemiGCCount_ = semiGCCount_; - LOG(INFO, RUNTIME) << " STWYoungGC statistic: total semi gc count " << semiGCCount_; - LOG(INFO, RUNTIME) << " MIN pause time: " << PrintTimeMilliseconds(semiGCMinPause_) << "ms" + LOG_GC(INFO) << " STWYoungGC statistic: total semi gc count " << semiGCCount_; + LOG_GC(INFO) << " MIN pause time: " << PrintTimeMilliseconds(semiGCMinPause_) << "ms" << " MAX pause time: " << PrintTimeMilliseconds(semiGCMaxPause_) << "ms" << " total pause time: " << PrintTimeMilliseconds(semiGCTotalPause_) << "ms" << " average pause time: " << PrintTimeMilliseconds(semiGCTotalPause_ / semiGCCount_) @@ -52,8 +52,8 @@ void GCStats::PrintPartialStatisticResult(bool force) { if ((force && partialGCCount_ != 0) || (!force && lastOldGCCount_ != partialGCCount_)) { lastOldGCCount_ = partialGCCount_; - LOG(INFO, RUNTIME) << " PartialGC with non-concurrent mark statistic: total old gc count " << partialGCCount_; - LOG(INFO, RUNTIME) << " Pause time statistic:: MIN pause time: " << PrintTimeMilliseconds(partialGCMinPause_) + LOG_GC(INFO) << " PartialGC with non-concurrent mark statistic: total old gc count " << partialGCCount_; + LOG_GC(INFO) << " Pause time statistic:: MIN pause time: " << PrintTimeMilliseconds(partialGCMinPause_) << "ms" << " MAX pause time: " << PrintTimeMilliseconds(partialGCMaxPause_) << "ms" << " total pause time: " << PrintTimeMilliseconds(partialGCTotalPause_) << "ms" @@ -67,9 +67,9 @@ void GCStats::PrintPartialStatisticResult(bool force) if ((force && partialConcurrentMarkGCCount_ != 0) || (!force && lastOldConcurrentMarkGCCount_ != partialConcurrentMarkGCCount_)) { lastOldConcurrentMarkGCCount_ = partialConcurrentMarkGCCount_; - LOG(INFO, RUNTIME) << " PartialCollector with concurrent mark statistic: total old gc count " + LOG_GC(INFO) << " PartialCollector with concurrent mark statistic: total old gc count " << partialConcurrentMarkGCCount_; - LOG(INFO, RUNTIME) << " Pause time statistic:: Current GC pause time: " + LOG_GC(INFO) << " Pause time statistic:: Current GC pause time: " << PrintTimeMilliseconds(partialConcurrentMarkGCPauseTime_) << "ms" << " Concurrent mark pause time: " << PrintTimeMilliseconds(partialConcurrentMarkMarkPause_) << "ms" @@ -96,8 +96,8 @@ void GCStats::PrintCompressStatisticResult(bool force) { if ((force && fullGCCount_ != 0) || (!force && fullGCCount_ != lastFullGCCount_)) { lastFullGCCount_ = fullGCCount_; - LOG(INFO, RUNTIME) << " FullGC statistic: total compress gc count " << fullGCCount_; - LOG(INFO, RUNTIME) + LOG_GC(INFO) << " FullGC statistic: total compress gc count " << fullGCCount_; + LOG_GC(INFO) << " MIN pause time: " << PrintTimeMilliseconds(fullGCMinPause_) << "ms" << " MAX pause time: " << PrintTimeMilliseconds(fullGCMaxPause_) << "ms" << " total pause time: " << PrintTimeMilliseconds(fullGCTotalPause_) << "ms" @@ -122,8 +122,8 @@ void GCStats::PrintHeapStatisticResult(bool force) if (force && heap_ != nullptr) { NativeAreaAllocator *nativeAreaAllocator = heap_->GetNativeAreaAllocator(); HeapRegionAllocator *heapRegionAllocator = heap_->GetHeapRegionAllocator(); - LOG(INFO, RUNTIME) << "/******************* Memory statistic: *******************/"; - LOG(INFO, RUNTIME) << " Anno memory usage size: " << sizeToMB(heapRegionAllocator->GetAnnoMemoryUsage()) + LOG_GC(INFO) << "/******************* Memory statistic: *******************/"; + LOG_GC(INFO) << " Anno memory usage size: " << sizeToMB(heapRegionAllocator->GetAnnoMemoryUsage()) << "MB" << " anno memory max usage size: " << sizeToMB(heapRegionAllocator->GetMaxAnnoMemoryUsage()) << "MB" @@ -131,7 +131,7 @@ void GCStats::PrintHeapStatisticResult(bool force) << "MB" << " native memory max usage size: " << sizeToMB(nativeAreaAllocator->GetMaxNativeMemoryUsage()) << "MB"; - LOG(INFO, RUNTIME) << " Semi space commit size: " << sizeToMB(heap_->GetNewSpace()->GetCommittedSize()) << "MB" + LOG_GC(INFO) << " Semi space commit size: " << sizeToMB(heap_->GetNewSpace()->GetCommittedSize()) << "MB" << " semi space heap object size: " << sizeToMB(heap_->GetNewSpace()->GetHeapObjectSize()) << "MB" << " old space commit size: " @@ -223,9 +223,9 @@ void GCStats::StatisticFullGC(Duration time, size_t youngAndOldAliveSize, size_t void GCStats::CheckIfLongTimePause() { if (currentPauseTime_ > longPauseTime_) { - LOG(INFO, RUNTIME) << "Has checked a long time gc; gc type = " << currentGcType_ << "; pause time = " + LOG_GC(INFO) << "Has checked a long time gc; gc type = " << currentGcType_ << "; pause time = " << currentPauseTime_ << "ms"; - LOG(INFO, RUNTIME) << "/******************* GCStats statistic: *******************/"; + LOG_GC(INFO) << "/******************* GCStats statistic: *******************/"; PrintSemiStatisticResult(true); PrintPartialStatisticResult(true); PrintCompressStatisticResult(true); diff --git a/ecmascript/mem/gc_stats.h b/ecmascript/mem/gc_stats.h index 5c988fa1e700bc8a48cf19f114f4f5cfff4e3c1a..79d545dd1e5154e127b853a56cc8b4328ccf027b 100644 --- a/ecmascript/mem/gc_stats.h +++ b/ecmascript/mem/gc_stats.h @@ -16,9 +16,10 @@ #ifndef ECMASCRIPT_MEM_GC_STATS_H #define ECMASCRIPT_MEM_GC_STATS_H +#include +#include #include "time.h" -#include "chrono" -#include "libpandabase/utils/logger.h" +#include "libpandabase/macros.h" namespace panda::ecmascript { class Heap; diff --git a/ecmascript/mem/heap-inl.h b/ecmascript/mem/heap-inl.h index 038df36734c8f362f4afb93f4c7cda81dcaeca4b..52f2e4f1794eff28015fff97fdeddd77fe6062ce 100644 --- a/ecmascript/mem/heap-inl.h +++ b/ecmascript/mem/heap-inl.h @@ -189,6 +189,28 @@ TaggedObject *Heap::AllocateOldOrHugeObject(JSHClass *hclass, size_t size) return object; } +TaggedObject *Heap::AllocateReadOnlyOrHugeObject(JSHClass *hclass) +{ + size_t size = hclass->GetObjectSize(); + return AllocateReadOnlyOrHugeObject(hclass, size); +} + +TaggedObject *Heap::AllocateReadOnlyOrHugeObject(JSHClass *hclass, size_t size) +{ + size = AlignUp(size, static_cast(MemAlignment::MEM_ALIGN_OBJECT)); + if (size > MAX_REGULAR_HEAP_OBJECT_SIZE) { + return AllocateHugeObject(hclass, size); + } + auto object = reinterpret_cast(readOnlySpace_->Allocate(size)); + if (UNLIKELY(object == 0)) { + ThrowOutOfMemoryError(size, "AllocateReadOnlyOrHugeObject"); + UNREACHABLE(); + } + object->SetClass(hclass); + OnAllocateEvent(reinterpret_cast(object)); + return object; +} + TaggedObject *Heap::AllocateNonMovableOrHugeObject(JSHClass *hclass) { size_t size = hclass->GetObjectSize(); diff --git a/ecmascript/mem/heap.cpp b/ecmascript/mem/heap.cpp index a3855aa2079f690cb75ae0a187ba2ff07b198074..226de13437aaa4911bb838422f0c1764b5e600e1 100644 --- a/ecmascript/mem/heap.cpp +++ b/ecmascript/mem/heap.cpp @@ -51,9 +51,10 @@ Heap::Heap(EcmaVM *ecmaVm) : ecmaVm_(ecmaVm), thread_(ecmaVm->GetJSThread()), void Heap::Initialize() { memController_ = new MemController(this); - - size_t minSemiSpaceCapacity = std::max(DEFAULT_SEMI_SPACE_SIZE, CONSTRAINT_MIN_SEMI_SPACE_SIZE); - size_t maxSemiSpaceCapacity = std::min(MAX_SEMI_SPACE_SIZE, CONSTRAINT_MAX_SEMI_SPACE_SIZE); + auto &config = ecmaVm_->GetEcmaParamConfiguration(); + size_t maxHeapSize = config.GetMaxHeapSize(); + size_t minSemiSpaceCapacity = config.GetMinSemiSpaceSize(); + size_t maxSemiSpaceCapacity = config.GetMaxSemiSpaceSize(); activeSemiSpace_ = new SemiSpace(this, minSemiSpaceCapacity, maxSemiSpaceCapacity); activeSemiSpace_->Restart(); activeSemiSpace_->SetWaterLine(); @@ -63,35 +64,39 @@ void Heap::Initialize() inactiveSemiSpace_ = new SemiSpace(this, minSemiSpaceCapacity, maxSemiSpaceCapacity); // not set up from space - size_t nonmovableSpaceCapacity = std::max(DEFAULT_NONMOVABLE_SPACE_SIZE, CONSTRAINT_MIN_NONMOVABLE_SPACE_SIZE); + size_t readOnlySpaceCpacity = config.GetDefaultReadOnlySpaceSize(); + readOnlySpace_ = new ReadOnlySpace(this, readOnlySpaceCpacity, readOnlySpaceCpacity); + size_t nonmovableSpaceCapacity = config.GetDefaultNonMovableSpaceSize(); if (ecmaVm_->GetJSOptions().WasSetMaxNonmovableSpaceCapacity()) { nonmovableSpaceCapacity = ecmaVm_->GetJSOptions().MaxNonmovableSpaceCapacity(); } nonMovableSpace_ = new NonMovableSpace(this, nonmovableSpaceCapacity, nonmovableSpaceCapacity); nonMovableSpace_->Initialize(); - size_t snapshotSpaceCapacity = std::max(DEFAULT_SNAPSHOT_SPACE_SIZE, CONSTRAINT_MIN_SNAPSHOT_SPACE_SIZE); - snapshotSpace_ = new SnapshotSpace(this, snapshotSpaceCapacity, MAX_SNAPSHOT_SPACE_SIZE); - size_t machineCodeSpaceCapacity = std::max(DEFAULT_MACHINECODE_SPACE_SIZE, CONSTRAINT_MIN_MACHINECODE_SPACE_SIZE); + size_t snapshotSpaceCapacity = config.GetDefaultSnapshotSpaceSize(); + snapshotSpace_ = new SnapshotSpace(this, snapshotSpaceCapacity, snapshotSpaceCapacity); + size_t machineCodeSpaceCapacity = config.GetDefaultMachineCodeSpaceSize(); machineCodeSpace_ = new MachineCodeSpace(this, machineCodeSpaceCapacity, machineCodeSpaceCapacity); machineCodeSpace_->Initialize(); size_t capacities = minSemiSpaceCapacity * 2 + nonmovableSpaceCapacity + snapshotSpaceCapacity + machineCodeSpaceCapacity; - if (MAX_HEAP_SIZE < capacities || MAX_HEAP_SIZE - capacities < MIN_OLD_SPACE_LIMIT) { - LOG_ECMA_MEM(FATAL) << "HeapSize is too small to initialize oldspace, heapSize = " << MAX_HEAP_SIZE; + if (maxHeapSize < capacities || maxHeapSize - capacities < MIN_OLD_SPACE_LIMIT) { + LOG_ECMA_MEM(FATAL) << "HeapSize is too small to initialize oldspace, heapSize = " << maxHeapSize; } - size_t oldSpaceCapacity = MAX_HEAP_SIZE - capacities; - globalSpaceAllocLimit_ = MAX_HEAP_SIZE - minSemiSpaceCapacity; + size_t oldSpaceCapacity = maxHeapSize - capacities; + globalSpaceAllocLimit_ = maxHeapSize - minSemiSpaceCapacity; oldSpace_ = new OldSpace(this, oldSpaceCapacity, oldSpaceCapacity); compressSpace_ = new OldSpace(this, oldSpaceCapacity, oldSpaceCapacity); oldSpace_->Initialize(); - hugeObjectSpace_ = new HugeObjectSpace(heapRegionAllocator_, oldSpaceCapacity, oldSpaceCapacity); + + size_t hugeObjectSpaceCapacity = config.GetDefaultHugeObjectSpaceSize(); + hugeObjectSpace_ = new HugeObjectSpace(heapRegionAllocator_, hugeObjectSpaceCapacity, hugeObjectSpaceCapacity); maxEvacuateTaskCount_ = Taskpool::GetCurrentTaskpool()->GetTotalThreadNum(); maxMarkTaskCount_ = std::min(ecmaVm_->GetJSOptions().GetGcThreadNum(), maxEvacuateTaskCount_ - 1); - LOG(INFO, RUNTIME) << "heap initialize: heap size = " << MAX_HEAP_SIZE + LOG_GC(INFO) << "heap initialize: heap size = " << maxHeapSize << ", semispace capacity = " << minSemiSpaceCapacity << ", nonmovablespace capacity = " << nonmovableSpaceCapacity << ", snapshotspace capacity = " << snapshotSpaceCapacity @@ -127,6 +132,10 @@ void Heap::Initialize() void Heap::Destroy() { Prepare(); + if (workManager_ != nullptr) { + delete workManager_; + workManager_ = nullptr; + } if (activeSemiSpace_ != nullptr) { activeSemiSpace_->Destroy(); delete activeSemiSpace_; @@ -167,9 +176,12 @@ void Heap::Destroy() delete hugeObjectSpace_; hugeObjectSpace_ = nullptr; } - if (workManager_ != nullptr) { - delete workManager_; - workManager_ = nullptr; + + if (readOnlySpace_ != nullptr) { + readOnlySpace_->ClearReadOnly(); + readOnlySpace_->Destroy(); + delete readOnlySpace_; + readOnlySpace_ = nullptr; } if (stwYoungGC_ != nullptr) { delete stwYoungGC_; @@ -239,8 +251,15 @@ void Heap::Resume(TriggerGCType gcType) } if (activeSemiSpace_->AdjustCapacity(inactiveSemiSpace_->GetAllocatedSizeSinceGC())) { // if activeSpace capacity changes, oldSpace maximumCapacity should change, too. - size_t delta = activeSemiSpace_->GetInitialCapacity() - inactiveSemiSpace_->GetInitialCapacity(); - size_t oldSpaceMaxLimit = oldSpace_->GetMaximumCapacity() - delta * 2; + size_t multiple = 2; + size_t oldSpaceMaxLimit = 0; + if (activeSemiSpace_->GetInitialCapacity() >= inactiveSemiSpace_->GetInitialCapacity()) { + size_t delta = activeSemiSpace_->GetInitialCapacity() - inactiveSemiSpace_->GetInitialCapacity(); + oldSpaceMaxLimit = oldSpace_->GetMaximumCapacity() - delta * multiple; + } else { + size_t delta = inactiveSemiSpace_->GetInitialCapacity() - activeSemiSpace_->GetInitialCapacity(); + oldSpaceMaxLimit = oldSpace_->GetMaximumCapacity() + delta * multiple; + } oldSpace_->SetMaximumCapacity(oldSpaceMaxLimit); inactiveSemiSpace_->SetInitialCapacity(activeSemiSpace_->GetInitialCapacity()); } @@ -256,6 +275,11 @@ void Heap::Resume(TriggerGCType gcType) } } +void Heap::CompactHeapBeforeFork() +{ + fullGC_->RunPhasesForAppSpawn(); +} + TriggerGCType Heap::SelectGCType() const { // If concurrent mark is enabled, the TryTriggerConcurrentMarking decide which GC to choose. @@ -281,7 +305,7 @@ void Heap::CollectGarbage(TriggerGCType gcType) sweeper_->EnsureAllTaskFinished(); auto failCount = Verification(this).VerifyAll(); if (failCount > 0) { - LOG(FATAL, GC) << "Before gc heap corrupted and " << failCount << " corruptions"; + LOG_GC(FATAL) << "Before gc heap corrupted and " << failCount << " corruptions"; } isVerifying_ = false; #endif @@ -294,8 +318,8 @@ void Heap::CollectGarbage(TriggerGCType gcType) } size_t originalNewSpaceSize = activeSemiSpace_->GetHeapObjectSize(); memController_->StartCalculationBeforeGC(); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "Heap::CollectGarbage, gcType = " << gcType - << " global CommittedSize " << GetCommittedSize() + LOG_GC(INFO) << "Heap::CollectGarbage, gcType = " << gcType; + OPTIONAL_LOG(ecmaVm_, ERROR) << " global CommittedSize " << GetCommittedSize() << " global limit " << globalSpaceAllocLimit_; switch (gcType) { case TriggerGCType::YOUNG_GC: @@ -343,7 +367,7 @@ void Heap::CollectGarbage(TriggerGCType gcType) // Only when the gc type is not semiGC and after the old space sweeping has been finished, // the limits of old space and global space can be recomputed. RecomputeLimits(); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << " GC after: is full mark" << IsFullMark() + OPTIONAL_LOG(ecmaVm_, ERROR) << " GC after: is full mark" << IsFullMark() << " global CommittedSize " << GetCommittedSize() << " global limit " << globalSpaceAllocLimit_; markType_ = MarkType::MARK_YOUNG; @@ -362,13 +386,11 @@ void Heap::CollectGarbage(TriggerGCType gcType) sweeper_->EnsureAllTaskFinished(); failCount = Verification(this).VerifyAll(); if (failCount > 0) { - LOG(FATAL, GC) << "After gc heap corrupted and " << failCount << " corruptions"; + LOG_GC(FATAL) << "After gc heap corrupted and " << failCount << " corruptions"; } isVerifying_ = false; #endif - if (!thread_->GetCheckAndCallEnterState()) { - JSFinalizationRegistry::CheckAndCall(thread_); - } + JSFinalizationRegistry::CheckAndCall(thread_); } void Heap::ThrowOutOfMemoryError(size_t size, std::string functionName) @@ -416,8 +438,9 @@ void Heap::AdjustOldSpaceLimit() if (oldSpaceLimitAdjusted_) { return; } + size_t minGrowingStep = ecmaVm_->GetEcmaParamConfiguration().GetMinGrowingStep(); size_t oldSpaceAllocLimit = GetOldSpace()->GetInitialCapacity(); - size_t newOldSpaceAllocLimit = std::max(oldSpace_->GetHeapObjectSize() + MIN_GROWING_STEP, + size_t newOldSpaceAllocLimit = std::max(oldSpace_->GetHeapObjectSize() + minGrowingStep, static_cast(oldSpaceAllocLimit * memController_->GetAverageSurvivalRate())); if (newOldSpaceAllocLimit <= oldSpaceAllocLimit) { GetOldSpace()->SetInitialCapacity(newOldSpaceAllocLimit); @@ -425,12 +448,12 @@ void Heap::AdjustOldSpaceLimit() oldSpaceLimitAdjusted_ = true; } - size_t newGlobalSpaceAllocLimit = std::max(GetHeapObjectSize() + MIN_GROWING_STEP, + size_t newGlobalSpaceAllocLimit = std::max(GetHeapObjectSize() + minGrowingStep, static_cast(globalSpaceAllocLimit_ * memController_->GetAverageSurvivalRate())); if (newGlobalSpaceAllocLimit < globalSpaceAllocLimit_) { globalSpaceAllocLimit_ = newGlobalSpaceAllocLimit; } - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "AdjustOldSpaceLimit oldSpaceAllocLimit_" << oldSpaceAllocLimit + OPTIONAL_LOG(ecmaVm_, ERROR) << "AdjustOldSpaceLimit oldSpaceAllocLimit_" << oldSpaceAllocLimit << " globalSpaceAllocLimit_" << globalSpaceAllocLimit_; } @@ -461,15 +484,16 @@ void Heap::RecomputeLimits() size_t newSpaceCapacity = activeSemiSpace_->GetInitialCapacity(); double growingFactor = memController_->CalculateGrowingFactor(gcSpeed, mutatorSpeed); - size_t maxOldSpaceCapacity = oldSpace_->GetMaximumCapacity(); + // newOldSpaceLimit should consider committedSize of hugeObjectSpace + size_t maxOldSpaceCapacity = oldSpace_->GetMaximumCapacity() - hugeObjectSpace_->GetCommittedSize(); auto newOldSpaceLimit = memController_->CalculateAllocLimit(oldSpaceSize, MIN_OLD_SPACE_LIMIT, maxOldSpaceCapacity, newSpaceCapacity, growingFactor); - size_t maxGlobalSize = MAX_HEAP_SIZE - newSpaceCapacity; - auto newGlobalSpaceLimit = memController_->CalculateAllocLimit(GetHeapObjectSize(), DEFAULT_HEAP_SIZE, + size_t maxGlobalSize = ecmaVm_->GetEcmaParamConfiguration().GetMaxHeapSize() - newSpaceCapacity; + auto newGlobalSpaceLimit = memController_->CalculateAllocLimit(GetHeapObjectSize(), MIN_HEAP_SIZE, maxGlobalSize, newSpaceCapacity, growingFactor); globalSpaceAllocLimit_ = newGlobalSpaceLimit; oldSpace_->SetInitialCapacity(newOldSpaceLimit); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "RecomputeLimits oldSpaceAllocLimit_" << newOldSpaceLimit + OPTIONAL_LOG(ecmaVm_, ERROR) << "RecomputeLimits oldSpaceAllocLimit_" << newOldSpaceLimit << " globalSpaceAllocLimit_" << globalSpaceAllocLimit_; } @@ -490,7 +514,7 @@ bool Heap::CheckOngoingConcurrentMarking() GetNonMovableMarker()->ProcessMarkStack(MAIN_THREAD_INDEX); WaitConcurrentMarkingFinished(); ecmaVm_->GetEcmaGCStats()->StatisticConcurrentMarkWait(clockScope.GetPauseTime()); - ECMA_GC_LOG() << "wait concurrent marking finish pause time " << clockScope.TotalSpentTime(); + LOG_GC(DEBUG) << "wait concurrent marking finish pause time " << clockScope.TotalSpentTime(); } memController_->RecordAfterConcurrentMark(IsFullMark(), concurrentMarker_); return true; @@ -522,7 +546,7 @@ void Heap::TryTriggerConcurrentMarking() if (oldSpaceConcurrentMarkSpeed == 0 || oldSpaceAllocSpeed == 0) { if (oldSpaceHeapObjectSize >= oldSpaceAllocLimit || globalHeapObjectSize >= globalSpaceAllocLimit_) { markType_ = MarkType::MARK_FULL; - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "Trigger the first full mark"; + OPTIONAL_LOG(ecmaVm_, ERROR) << "Trigger the first full mark"; TriggerConcurrentMarking(); return; } @@ -543,10 +567,11 @@ void Heap::TryTriggerConcurrentMarking() double newSpaceConcurrentMarkSpeed = memController_->GetNewSpaceConcurrentMarkSpeedPerMS(); if (newSpaceConcurrentMarkSpeed == 0 || newSpaceAllocSpeed == 0) { - if (activeSemiSpace_->GetCommittedSize() >= SEMI_SPACE_TRIGGER_CONCURRENT_MARK) { + auto &config = ecmaVm_->GetEcmaParamConfiguration(); + if (activeSemiSpace_->GetCommittedSize() >= config.GetSemiSpaceTriggerConcurrentMark()) { markType_ = MarkType::MARK_YOUNG; TriggerConcurrentMarking(); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "Trigger the first semi mark" << fullGCRequested_; + OPTIONAL_LOG(ecmaVm_, ERROR) << "Trigger the first semi mark" << fullGCRequested_; } return; } @@ -561,18 +586,18 @@ void Heap::TryTriggerConcurrentMarking() && oldSpaceMarkDuration < oldSpaceAllocToLimitDuration) { markType_ = MarkType::MARK_FULL; TriggerConcurrentMarking(); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "Trigger full mark by speed"; + OPTIONAL_LOG(ecmaVm_, ERROR) << "Trigger full mark by speed"; } else { if (oldSpaceHeapObjectSize >= oldSpaceAllocLimit || globalHeapObjectSize >= globalSpaceAllocLimit_) { markType_ = MarkType::MARK_FULL; TriggerConcurrentMarking(); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "Trigger full mark by limit"; + OPTIONAL_LOG(ecmaVm_, ERROR) << "Trigger full mark by limit"; } } } else if (newSpaceRemainSize < DEFAULT_REGION_SIZE) { markType_ = MarkType::MARK_YOUNG; TriggerConcurrentMarking(); - OPTIONAL_LOG(ecmaVm_, ERROR, ECMASCRIPT) << "Trigger semi mark"; + OPTIONAL_LOG(ecmaVm_, ERROR) << "Trigger semi mark"; } } @@ -595,14 +620,14 @@ void Heap::UpdateDerivedObjectInStack() uintptr_t baseOldObject = derived.second; uintptr_t *derivedAddr = reinterpret_cast(derived.first.second); #ifndef NDEBUG - LOG_ECMA(DEBUG) << std::hex << "fix base before:" << baseAddr << " base old Value: " << baseOldObject << + LOG_GC(DEBUG) << std::hex << "fix base before:" << baseAddr << " base old Value: " << baseOldObject << " derived:" << derivedAddr << " old Value: " << *derivedAddr << std::endl; #endif // derived is always bigger than base - *derivedAddr = reinterpret_cast(base.GetHeapObject()) + (*derivedAddr - baseOldObject); + *derivedAddr = reinterpret_cast(base.GetTaggedObject()) + (*derivedAddr - baseOldObject); #ifndef NDEBUG - LOG_ECMA(DEBUG) << std::hex << "fix base after:" << baseAddr << - " base New Value: " << base.GetHeapObject() << + LOG_GC(DEBUG) << std::hex << "fix base after:" << baseAddr << + " base New Value: " << base.GetTaggedObject() << " derived:" << derivedAddr << " New Value: " << *derivedAddr << std::endl; #endif } @@ -646,20 +671,20 @@ void Heap::IncreaseTaskCount() void Heap::ChangeGCParams(bool inBackground) { if (inBackground) { - LOG(INFO, RUNTIME) << "app is inBackground"; + LOG_GC(INFO) << "app is inBackground"; if (GetMemGrowingType() != MemGrowingType::PRESSURE) { SetMemGrowingType(MemGrowingType::CONSERVATIVE); - LOG(INFO, RUNTIME) << "Heap Growing Type CONSERVATIVE"; + LOG_GC(INFO) << "Heap Growing Type CONSERVATIVE"; } concurrentMarker_->EnableConcurrentMarking(EnableConcurrentMarkType::DISABLE); sweeper_->EnableConcurrentSweep(EnableConcurrentSweepType::DISABLE); maxMarkTaskCount_ = 1; maxEvacuateTaskCount_ = 1; } else { - LOG(INFO, RUNTIME) << "app is not inBackground"; + LOG_GC(INFO) << "app is not inBackground"; if (GetMemGrowingType() != MemGrowingType::PRESSURE) { SetMemGrowingType(MemGrowingType::HIGH_THROUGHPUT); - LOG(INFO, RUNTIME) << "Heap Growing Type HIGH_THROUGHPUT"; + LOG_GC(INFO) << "Heap Growing Type HIGH_THROUGHPUT"; } concurrentMarker_->EnableConcurrentMarking(EnableConcurrentMarkType::ENABLE); sweeper_->EnableConcurrentSweep(EnableConcurrentSweepType::ENABLE); @@ -672,10 +697,10 @@ void Heap::ChangeGCParams(bool inBackground) void Heap::NotifyMemoryPressure(bool inHighMemoryPressure) { if (inHighMemoryPressure) { - LOG(INFO, RUNTIME) << "app is inHighMemoryPressure"; + LOG_GC(INFO) << "app is inHighMemoryPressure"; SetMemGrowingType(MemGrowingType::PRESSURE); } else { - LOG(INFO, RUNTIME) << "app is not inHighMemoryPressure"; + LOG_GC(INFO) << "app is not inHighMemoryPressure"; SetMemGrowingType(MemGrowingType::CONSERVATIVE); } } @@ -746,14 +771,14 @@ size_t Heap::GetArrayBufferSize() const bool Heap::IsAlive(TaggedObject *object) const { if (!ContainObject(object)) { - LOG(ERROR, RUNTIME) << "The region is already free"; + LOG_GC(ERROR) << "The region is already free"; return false; } bool isFree = object->GetClass() != nullptr && FreeObject::Cast(ToUintPtr(object))->IsFreeObject(); if (isFree) { Region *region = Region::ObjectAddressToRange(object); - LOG(ERROR, RUNTIME) << "The object " << object << " in " + LOG_GC(ERROR) << "The object " << object << " in " << region->GetSpaceTypeName() << " already free"; } diff --git a/ecmascript/mem/heap.h b/ecmascript/mem/heap.h index ede9d15ec1b50ac6d38b636d35af91a4a7c10971..a7dc6ffc7d91962c39eaccdd81aa9333762c9c20 100644 --- a/ecmascript/mem/heap.h +++ b/ecmascript/mem/heap.h @@ -17,6 +17,7 @@ #define ECMASCRIPT_MEM_HEAP_H #include "ecmascript/base/config.h" +#include "ecmascript/frames.h" #include "ecmascript/js_thread.h" #include "ecmascript/mem/chunk_containers.h" #include "ecmascript/mem/linear_space.h" @@ -39,8 +40,6 @@ class ParallelEvacuator; class PartialGC; class STWYoungGC; -using DerivedDataKey = std::pair; - enum class MarkType : uint8_t { MARK_YOUNG, MARK_FULL @@ -61,7 +60,7 @@ public: void Destroy(); void Prepare(); void Resume(TriggerGCType gcType); - + void CompactHeapBeforeFork(); // fixme: Rename NewSpace to YoungSpace. // This is the active young generation space that the new objects are allocated in // or copied into (from the other semi space) during semi space GC. @@ -105,6 +104,11 @@ public: return snapshotSpace_; } + ReadOnlySpace *GetReadOnlySpace() const + { + return readOnlySpace_; + } + SparseSpace *GetSpaceWithType(MemSpaceType type) const { switch (type) { @@ -195,6 +199,8 @@ public: // Young inline TaggedObject *AllocateYoungOrHugeObject(JSHClass *hclass); inline TaggedObject *AllocateYoungOrHugeObject(JSHClass *hclass, size_t size); + inline TaggedObject *AllocateReadOnlyOrHugeObject(JSHClass *hclass); + inline TaggedObject *AllocateReadOnlyOrHugeObject(JSHClass *hclass, size_t size); inline TaggedObject *AllocateYoungOrHugeObject(size_t size); inline uintptr_t AllocateYoungSync(size_t size); inline TaggedObject *TryAllocateYoungGeneration(JSHClass *hclass, size_t size); @@ -387,6 +393,10 @@ public: return isVerifying_; } #endif + static bool ShouldMoveToRoSpace(JSTaggedValue value) + { + return value.IsString() && !Region::ObjectAddressToRange(value.GetTaggedObject())->InHugeObjectSpace(); + } private: void ThrowOutOfMemoryError(size_t size, std::string functionName); @@ -442,7 +452,7 @@ private: // Old generation spaces where some long living objects are allocated or promoted. OldSpace *oldSpace_ {nullptr}; OldSpace *compressSpace_ {nullptr}; - + ReadOnlySpace *readOnlySpace_ {nullptr}; // Spaces used for special kinds of objects. NonMovableSpace *nonMovableSpace_ {nullptr}; MachineCodeSpace *machineCodeSpace_ {nullptr}; diff --git a/ecmascript/mem/heap_region_allocator.cpp b/ecmascript/mem/heap_region_allocator.cpp index b9c44647a451376cea8ca9dbb28bc59db98bd677..74835f1917661890dbc32f6a1015202ed7894e60 100644 --- a/ecmascript/mem/heap_region_allocator.cpp +++ b/ecmascript/mem/heap_region_allocator.cpp @@ -36,7 +36,7 @@ Region *HeapRegionAllocator::AllocateAlignedRegion(Space *space, size_t capacity } #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(mapMem, capacity, 0, capacity) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif @@ -44,7 +44,7 @@ Region *HeapRegionAllocator::AllocateAlignedRegion(Space *space, size_t capacity uintptr_t mem = ToUintPtr(mapMem); // Check that the address is 256K byte aligned - LOG_IF(AlignUp(mem, PANDA_POOL_ALIGNMENT_IN_BYTES) != mem, FATAL, RUNTIME) << "region not align by 256KB"; + LOG_ECMA_IF(AlignUp(mem, PANDA_POOL_ALIGNMENT_IN_BYTES) != mem, FATAL) << "region not align by 256KB"; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) uintptr_t begin = AlignUp(mem + sizeof(Region), static_cast(MemAlignment::MEM_ALIGN_REGION)); @@ -63,7 +63,7 @@ void HeapRegionAllocator::FreeRegion(Region *region) region->Invalidate(); #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(ToVoidPtr(allocateBase), size, INVALID_VALUE, size) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif diff --git a/ecmascript/mem/heap_region_allocator.h b/ecmascript/mem/heap_region_allocator.h index f3230c9601208e3412833eccee8462ace74d0cd3..1925f8e91328dfde83763be9e09b4f95d50e6c4d 100644 --- a/ecmascript/mem/heap_region_allocator.h +++ b/ecmascript/mem/heap_region_allocator.h @@ -19,7 +19,6 @@ #include #include "ecmascript/mem/mem.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript { class JSThread; diff --git a/ecmascript/mem/linear_space.cpp b/ecmascript/mem/linear_space.cpp index 872f64bb4b4d205248fbbfeed6ab2c601390aada..e4cfef10d367b6cd1589323718866062192d9f11 100644 --- a/ecmascript/mem/linear_space.cpp +++ b/ecmascript/mem/linear_space.cpp @@ -41,7 +41,7 @@ uintptr_t LinearSpace::Allocate(size_t size, bool isPromoted) object = allocator_.Allocate(size); } else if (heap_->GetJSThread()->IsMarking()) { // Temporary adjust semi space capacity - overShootSize_ = SEMI_SPACE_OVERSHOOT_SIZE; + overShootSize_ = heap_->GetEcmaVM()->GetEcmaParamConfiguration().GetSemiSpaceOvershootSize(); if (Expand(isPromoted)) { object = allocator_.Allocate(size); } @@ -239,4 +239,7 @@ size_t SemiSpace::GetAllocatedSizeSinceGC(uintptr_t top) const SnapshotSpace::SnapshotSpace(Heap *heap, size_t initialCapacity, size_t maximumCapacity) : LinearSpace(heap, MemSpaceType::SNAPSHOT_SPACE, initialCapacity, maximumCapacity) {} + +ReadOnlySpace::ReadOnlySpace(Heap *heap, size_t initialCapacity, size_t maximumCapacity) + : LinearSpace(heap, MemSpaceType::READ_ONLY_SPACE, initialCapacity, maximumCapacity) {} } // namespace panda::ecmascript diff --git a/ecmascript/mem/linear_space.h b/ecmascript/mem/linear_space.h index ed98e7c73af3012e492cd93fbfccbf4f429eaed0..07f464b9cb3483441e5ed48c4e893b81746081dc 100644 --- a/ecmascript/mem/linear_space.h +++ b/ecmascript/mem/linear_space.h @@ -22,6 +22,8 @@ namespace panda::ecmascript { class LinearSpace : public Space { public: explicit LinearSpace(Heap *heap, MemSpaceType type, size_t initialCapacity, size_t maximumCapacity); + NO_COPY_SEMANTIC(LinearSpace); + NO_MOVE_SEMANTIC(LinearSpace); uintptr_t Allocate(size_t size, bool isPromoted = false); bool Expand(bool isPromoted); void Stop(); @@ -105,5 +107,29 @@ public: private: size_t liveObjectSize_ {0}; }; + +class ReadOnlySpace : public LinearSpace { +public: + explicit ReadOnlySpace(Heap *heap, size_t initialCapacity, size_t maximumCapacity); + ~ReadOnlySpace() override = default; + void SetReadOnly() + { + auto cb = [](Region *region) { + region->SetReadOnlyAndMarked(); + }; + EnumerateRegions(cb); + } + + void ClearReadOnly() + { + auto cb = [](Region *region) { + region->ClearReadOnly(); + }; + EnumerateRegions(cb); + } + + NO_COPY_SEMANTIC(ReadOnlySpace); + NO_MOVE_SEMANTIC(ReadOnlySpace); +}; } // namespace panda::ecmascript #endif // ECMASCRIPT_MEM_LINEAR_SPACE_H diff --git a/ecmascript/mem/machine_code.h b/ecmascript/mem/machine_code.h index ad4bf55eda9d7f2c8605a20828af22b880ba852b..58b3eb5bd645795ced09df56076a574ebace3a55 100644 --- a/ecmascript/mem/machine_code.h +++ b/ecmascript/mem/machine_code.h @@ -27,7 +27,7 @@ class MachineCode : public TaggedObject { public: NO_COPY_SEMANTIC(MachineCode); NO_MOVE_SEMANTIC(MachineCode); - static MachineCode *Cast(ObjectHeader *object) + static MachineCode *Cast(TaggedObject *object) { ASSERT(JSTaggedValue(object).IsMachineCodeObject()); return static_cast(object); diff --git a/ecmascript/mem/mem.h b/ecmascript/mem/mem.h index d10da9d629385d395dcee896f238e0b3da33b8bf..1b214cf766b7325d0cbf2323ffb95a4540875ebb 100644 --- a/ecmascript/mem/mem.h +++ b/ecmascript/mem/mem.h @@ -18,13 +18,16 @@ #include +#ifndef PANDA_TARGET_WINDOWS +#include +#endif + #include "ecmascript/ecma_param_configuration.h" #include "ecmascript/mem/tagged_object.h" #include "libpandabase/mem/mem.h" -#include "libpandabase/utils/logger.h" // NOLINTNEXTLINE(cppcoreguidelines-macro-usage, bugprone-lambda-function-name) -#define LOG_ECMA_MEM(type) LOG(type, ECMASCRIPT) << __func__ << " Line:" << __LINE__ << " " +#define LOG_ECMA_MEM(level) LOG_GC(level) << __func__ << ":" << __LINE__ << " " namespace panda::ecmascript { enum class MemAlignment : uint8_t { @@ -37,24 +40,19 @@ enum class MemAlignmentLog2 : uint8_t { MEM_ALIGN_REGION_LOG2 = 4, }; -static constexpr size_t SEMI_SPACE_TRIGGER_CONCURRENT_MARK = 1.5_MB; -static constexpr size_t SEMI_SPACE_OVERSHOOT_SIZE = 2_MB; - -static constexpr size_t CONSTRAINT_MIN_SEMI_SPACE_SIZE = 1_MB; -static constexpr size_t CONSTRAINT_MAX_SEMI_SPACE_SIZE = 16_MB; -static constexpr size_t CONSTRAINT_MIN_NONMOVABLE_SPACE_SIZE = 1_MB; -static constexpr size_t CONSTRAINT_MIN_SNAPSHOT_SPACE_SIZE = 256_KB; -static constexpr size_t CONSTRAINT_MIN_MACHINECODE_SPACE_SIZE = 4_MB; - -static constexpr size_t MIN_MEM_POOL_CAPACITY = 32_MB; +static constexpr size_t LARGE_POOL_SIZE = 480_MB; +static constexpr size_t MEDIUM_POOL_SIZE = 256_MB; +static constexpr size_t LOW_POOL_SIZE = 64_MB; +static constexpr size_t MIN_MEM_POOL_CAPACITY = 64_MB; static constexpr size_t PHY_SIZE_MULTIPLE = 4; +static constexpr size_t WORKER_NUM = 7; +static constexpr size_t STANDARD_POOL_SIZE = WORKER_NUM * DEFAULT_WORKER_HEAP_SIZE + DEFAULT_HEAP_SIZE; static constexpr size_t MIN_OLD_SPACE_LIMIT = 2_MB; -static constexpr size_t MIN_GROWING_STEP = 16_MB; static constexpr size_t REGION_SIZE_LOG2 = 18U; -static constexpr size_t DEFAULT_HEAP_SIZE = 5_MB; +static constexpr size_t MIN_HEAP_SIZE = 5_MB; static constexpr size_t DEFAULT_REGION_SIZE = 1U << REGION_SIZE_LOG2; static constexpr size_t DEFAULT_REGION_MASK = DEFAULT_REGION_SIZE - 1; diff --git a/ecmascript/mem/mem_controller.cpp b/ecmascript/mem/mem_controller.cpp index 49594d713ea51d38ef7c38ec8144c49406ea443e..0f8d0e43a0eb3a9883c377a0f76d3bf5bade1f3d 100644 --- a/ecmascript/mem/mem_controller.cpp +++ b/ecmascript/mem/mem_controller.cpp @@ -20,19 +20,21 @@ #include "ecmascript/mem/parallel_evacuator.h" namespace panda::ecmascript { -MemController::MemController(Heap *heap) : heap_(heap), allocTimeMs_(GetSystemTimeInMs()) {} +MemController::MemController(Heap *heap) : heap_(heap), allocTimeMs_(GetSystemTimeInMs()) +{ + minAllocLimitGrowingStep_ = heap->GetEcmaVM()->GetEcmaParamConfiguration().GetMinAllocLimitGrowingStep(); +} double MemController::CalculateAllocLimit(size_t currentSize, size_t minSize, size_t maxSize, size_t newSpaceCapacity, double factor) const { const uint64_t limit = std::max(static_cast(currentSize * factor), - static_cast(currentSize) + MIN_AllOC_LIMIT_GROWING_STEP) + + static_cast(currentSize) + minAllocLimitGrowingStep_) + newSpaceCapacity; const uint64_t limitAboveMinSize = std::max(limit, minSize); const uint64_t halfToMaxSize = (static_cast(currentSize) + maxSize) / 2; auto result = static_cast(std::min(limitAboveMinSize, halfToMaxSize)); - // Avoid the limit is larger than maxSize - newSpaceCapacity. It may cause old space merge OOM. result = static_cast(std::min(result, maxSize)); return result; } @@ -69,7 +71,7 @@ double MemController::CalculateGrowingFactor(double gcSpeed, double mutatorSpeed double factor = (a < b * maxGrowingFactor) ? a / b : maxGrowingFactor; factor = std::min(maxGrowingFactor, factor); factor = std::max(factor, minGrowingFactor); - OPTIONAL_LOG(heap_->GetEcmaVM(), ERROR, ECMASCRIPT) << "CalculateGrowingFactor gcSpeed" + OPTIONAL_LOG(heap_->GetEcmaVM(), ERROR) << "CalculateGrowingFactor gcSpeed" << gcSpeed << " mutatorSpeed" << mutatorSpeed << " factor" << factor; return factor; } diff --git a/ecmascript/mem/mem_controller.h b/ecmascript/mem/mem_controller.h index ca6b0568614076babdde4a70c5b49ef160989a6d..55a45f7fde46bc1c0593a311adc9e59564495e26 100644 --- a/ecmascript/mem/mem_controller.h +++ b/ecmascript/mem/mem_controller.h @@ -135,6 +135,7 @@ private: const BytesAndDuration &initial, const double timeMs); Heap* heap_; + size_t minAllocLimitGrowingStep_ {0}; double gcStartTime_ {0.0}; double gcEndTime_ {0.0}; diff --git a/ecmascript/mem/mem_map_allocator.cpp b/ecmascript/mem/mem_map_allocator.cpp index 360450aa36661e33666016f2fc9d13e3622fe2a3..384976d39dc9b9a2e7ced23b0228dfe539bd9397 100644 --- a/ecmascript/mem/mem_map_allocator.cpp +++ b/ecmascript/mem/mem_map_allocator.cpp @@ -14,8 +14,8 @@ */ #include "ecmascript/mem/mem_map_allocator.h" -#include "mem/runslots.h" #if defined(PANDA_TARGET_WINDOWS) +#include #include #elif defined(PANDA_TARGET_MACOS) #include "sys/sysctl.h" @@ -48,7 +48,7 @@ namespace panda::ecmascript { MemMap MemMapAllocator::Allocate(size_t size, size_t alignment, bool isRegular) { if (UNLIKELY(memMapTotalSize_ + size > capacity_)) { - LOG(ERROR, RUNTIME) << "memory map overflow"; + LOG_GC(ERROR) << "memory map overflow"; return MemMap(); } MemMap mem; @@ -91,7 +91,7 @@ MemMap MemMapAllocator::PageMap(size_t size, size_t alignment) #else void *result = mmap(allocSize, -1, 0); #endif - LOG_IF(result == nullptr, FATAL, ECMASCRIPT); + LOG_ECMA_IF(result == nullptr, FATAL) << "mmap fail"; auto alignResult = AlignUp(reinterpret_cast(result), alignment); #ifdef PANDA_TARGET_UNIX size_t leftSize = alignResult - reinterpret_cast(result); @@ -107,9 +107,9 @@ void MemMapAllocator::AdapterSuitablePoolCapacity() { #ifdef PANDA_TARGET_WINDOWS MEMORYSTATUSEX status; - status.dwLength = sizeof(status); + status.dwLength = sizeof(MEMORYSTATUSEX); GlobalMemoryStatusEx(&status); - long physSize = status.ullTotalPhys; + DWORDLONG physSize = status.ullTotalPhys; #elif PANDA_TARGET_MACOS static constexpr int MIB_LENGTH = 2; int mib[2]; @@ -118,15 +118,22 @@ void MemMapAllocator::AdapterSuitablePoolCapacity() int64_t size = 0; size_t bufferLength = sizeof(size); if (sysctl(mib, MIB_LENGTH, &size, &bufferLength, NULL, 0) != 0) { - LOG(FATAL, RUNTIME) << "sysctl error"; + LOG_GC(FATAL) << "sysctl error"; } - long physSize = static_cast(size); + size_t physSize = static_cast(size); #else auto pages = sysconf(_SC_PHYS_PAGES); auto pageSize = sysconf(_SC_PAGE_SIZE); - long physSize = pages * pageSize; + size_t physSize = pages * pageSize; #endif capacity_ = std::max(physSize / PHY_SIZE_MULTIPLE, MIN_MEM_POOL_CAPACITY); - LOG(INFO, RUNTIME) << "Auto adapter memory pool capacity:" << capacity_; + if (capacity_ > LARGE_POOL_SIZE) { + capacity_ = std::max(capacity_, STANDARD_POOL_SIZE); + } else if (capacity_ >= MEDIUM_POOL_SIZE) { + capacity_ = std::min(capacity_, STANDARD_POOL_SIZE); + } else if (capacity_ >= LOW_POOL_SIZE) { + capacity_ = std::max(capacity_, 128_MB); + } + LOG_GC(INFO) << "Ark Auto adapter memory pool capacity:" << capacity_; } } // namespace panda::ecmascript diff --git a/ecmascript/mem/mem_map_allocator.h b/ecmascript/mem/mem_map_allocator.h index 77a0013d793c7efc4c80f0ff15bf31d3cd67ea8e..f3a4b00c4fd4cc25ddfb4895a03e75e50d8b4466 100644 --- a/ecmascript/mem/mem_map_allocator.h +++ b/ecmascript/mem/mem_map_allocator.h @@ -48,7 +48,12 @@ #undef STRICT #endif +#ifdef VOID +#undef VOID #endif +#endif + +#include "ecmascript/log_wrapper.h" namespace panda::ecmascript { class MemMap { @@ -127,6 +132,7 @@ public: void InsertMemMap(MemMap memMap) { + os::memory::LockHolder lock(lock_); memMapVector_.emplace_back(memMap); } @@ -216,6 +222,27 @@ public: memMapPool_.Finalize(); } + size_t GetCapacity() + { + return capacity_; + } + + void IncreaseAndCheckReserved(size_t size) + { + if (reserved_ + size > capacity_) { + LOG_GC(ERROR) << "pool is empty, reserved = " << reserved_ << ", capacity_ = " + << capacity_ << ", size = " << size; + } + reserved_ += size; + LOG_GC(DEBUG) << "Ark IncreaseAndCheckReserved reserved = " << reserved_ << ", capacity_ = " << capacity_; + } + + void DecreaseReserved(size_t size) + { + reserved_ -= size; + LOG_GC(DEBUG) << "Ark DecreaseReserved reserved = " << reserved_ << ", capacity_ = " << capacity_; + } + static MemMapAllocator *GetInstance() { static MemMapAllocator vmAllocator_; @@ -255,6 +282,7 @@ private: MemMapFreeList memMapFreeList_; std::atomic_size_t memMapTotalSize_ {0}; size_t capacity_ {0}; + size_t reserved_ {0}; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_MEM_MEM_MAP_ALLOCATOR_H diff --git a/ecmascript/mem/native_area_allocator.cpp b/ecmascript/mem/native_area_allocator.cpp index 3eaed4bbaa3452f5eb597e0d4e2edbdc1aec69e4..01adf373a074314a233d7cda6f71377990e17d3d 100644 --- a/ecmascript/mem/native_area_allocator.cpp +++ b/ecmascript/mem/native_area_allocator.cpp @@ -44,7 +44,7 @@ Area *NativeAreaAllocator::AllocateArea(size_t capacity) } #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(mem, capacity, 0, capacity) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif @@ -68,7 +68,7 @@ void NativeAreaAllocator::FreeArea(Area *area) DecreaseNativeMemoryUsage(size); #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(area, size, INVALID_VALUE, size) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif @@ -84,7 +84,7 @@ void NativeAreaAllocator::Free(void *mem, size_t size) DecreaseNativeMemoryUsage(size); #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(mem, size, INVALID_VALUE, size) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif @@ -107,7 +107,7 @@ void *NativeAreaAllocator::AllocateBuffer(size_t size) } #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(ptr, size, INVALID_VALUE, size) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif @@ -130,7 +130,7 @@ void NativeAreaAllocator::FreeBuffer(void *mem) #if ECMASCRIPT_ENABLE_ZAP_MEM if (memset_s(mem, size, INVALID_VALUE, size) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } #endif diff --git a/ecmascript/mem/native_area_allocator.h b/ecmascript/mem/native_area_allocator.h index 180d688624e699105e35440ace29770c1377311b..3b277e936b2efdccf8eff5ea8cbcb87a6b2d5183 100644 --- a/ecmascript/mem/native_area_allocator.h +++ b/ecmascript/mem/native_area_allocator.h @@ -19,9 +19,9 @@ #include #include "ecmascript/common.h" +#include "ecmascript/log_wrapper.h" #include "ecmascript/mem/mem.h" #include "ecmascript/mem/area.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript { class PUBLIC_API NativeAreaAllocator { diff --git a/ecmascript/mem/object_xray.h b/ecmascript/mem/object_xray.h index a553823ef162727f86c36d326ae9422d1e39b439..03ac24255204a20752a6dbf196781b7a0ad70506 100644 --- a/ecmascript/mem/object_xray.h +++ b/ecmascript/mem/object_xray.h @@ -30,6 +30,10 @@ #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list.h" @@ -51,7 +55,6 @@ #include "ecmascript/js_array_iterator.h" #include "ecmascript/js_arraybuffer.h" #include "ecmascript/js_async_function.h" -#include "ecmascript/js_bigint.h" #include "ecmascript/js_collator.h" #include "ecmascript/js_dataview.h" #include "ecmascript/js_date.h" @@ -118,6 +121,7 @@ public: case JSType::JS_RANGE_ERROR: case JSType::JS_REFERENCE_ERROR: case JSType::JS_TYPE_ERROR: + case JSType::JS_AGGREGATE_ERROR: case JSType::JS_URI_ERROR: case JSType::JS_SYNTAX_ERROR: case JSType::JS_ITERATOR: @@ -182,6 +186,38 @@ public: } break; } + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: { + auto jsPromiseAnyRejectElementFunction = JSPromiseAnyRejectElementFunction::Cast(object); + jsPromiseAnyRejectElementFunction->VisitRangeSlot(visitor); + if (visitType == VisitType::SNAPSHOT_VISIT) { + jsPromiseAnyRejectElementFunction->VisitRangeSlotForNative(visitor); + } + break; + } + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: { + auto jsPromiseAllSettledElementFunction = JSPromiseAllSettledElementFunction::Cast(object); + jsPromiseAllSettledElementFunction->VisitRangeSlot(visitor); + if (visitType == VisitType::SNAPSHOT_VISIT) { + jsPromiseAllSettledElementFunction->VisitRangeSlotForNative(visitor); + } + break; + } + case JSType::JS_PROMISE_FINALLY_FUNCTION: { + auto jsPromiseFinallyFunction = JSPromiseFinallyFunction::Cast(object); + jsPromiseFinallyFunction->VisitRangeSlot(visitor); + if (visitType == VisitType::SNAPSHOT_VISIT) { + jsPromiseFinallyFunction->VisitRangeSlotForNative(visitor); + } + break; + } + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: { + auto jsPromiseValueThunkOrThrowerFunction = JSPromiseValueThunkOrThrowerFunction::Cast(object); + jsPromiseValueThunkOrThrowerFunction->VisitRangeSlot(visitor); + if (visitType == VisitType::SNAPSHOT_VISIT) { + jsPromiseValueThunkOrThrowerFunction->VisitRangeSlotForNative(visitor); + } + break; + } case JSType::JS_ASYNC_FUNCTION: { auto jsAsyncFunction = JSAsyncFunction::Cast(object); jsAsyncFunction->VisitRangeSlot(visitor); @@ -433,6 +469,18 @@ public: case JSType::JS_API_ARRAYLIST_ITERATOR: JSAPIArrayListIterator::Cast(object)->VisitRangeSlot(visitor); break; + case JSType::JS_API_LIGHT_WEIGHT_MAP: + JSAPILightWeightMap::Cast(object)->VisitRangeSlot(visitor); + break; + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: + JSAPILightWeightMapIterator::Cast(object)->VisitRangeSlot(visitor); + break; + case JSType::JS_API_LIGHT_WEIGHT_SET: + JSAPILightWeightSet::Cast(object)->VisitRangeSlot(visitor); + break; + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: + JSAPILightWeightSetIterator::Cast(object)->VisitRangeSlot(visitor); + break; case JSType::TS_OBJECT_TYPE: TSObjectType::Cast(object)->VisitRangeSlot(visitor); break; @@ -504,7 +552,6 @@ public: JSAPILinkedListIterator::Cast(object)->VisitRangeSlot(visitor); break; case JSType::BIGINT: - BigInt::Cast(object)->VisitRangeSlot(visitor); break; case JSType::SOURCE_TEXT_MODULE_RECORD: SourceTextModule::Cast(object)->VisitRangeSlot(visitor); @@ -522,13 +569,13 @@ public: ModuleNamespace::Cast(object)->VisitRangeSlot(visitor); break; case JSType::JS_CJS_EXPORTS: - JSCjsExports::Cast(object)->VisitRangeSlot(visitor); + CjsExports::Cast(object)->VisitRangeSlot(visitor); break; case JSType::JS_CJS_MODULE: - JSCjsModule::Cast(object)->VisitRangeSlot(visitor); + CjsModule::Cast(object)->VisitRangeSlot(visitor); break; case JSType::JS_CJS_REQUIRE: - JSCjsRequire::Cast(object)->VisitRangeSlot(visitor); + CjsRequire::Cast(object)->VisitRangeSlot(visitor); break; default: UNREACHABLE(); diff --git a/ecmascript/mem/parallel_evacuator.cpp b/ecmascript/mem/parallel_evacuator.cpp index 3fc375e246c352a6f9ca90f9614d24331a51e941..adaa14fa9a19d208a26404bf1e2319d658c0665b 100644 --- a/ecmascript/mem/parallel_evacuator.cpp +++ b/ecmascript/mem/parallel_evacuator.cpp @@ -23,7 +23,6 @@ #include "ecmascript/mem/mem.h" #include "ecmascript/mem/space-inl.h" #include "ecmascript/mem/tlab_allocator-inl.h" -#include "ecmascript/mem/utils.h" #include "ecmascript/mem/visitor.h" #include "ecmascript/mem/gc_stats.h" #include "ecmascript/ecma_string_table.h" @@ -130,9 +129,11 @@ void ParallelEvacuator::EvacuateRegion(TlabAllocator *allocator, Region *region) promotedSize += size; } } - LOG_IF(address == 0, FATAL, RUNTIME) << "Evacuate object failed:" << size; + LOG_ECMA_IF(address == 0, FATAL) << "Evacuate object failed:" << size; - Utils::Copy(ToVoidPtr(address), size, ToVoidPtr(ToUintPtr(mem)), size); + if (memcpy_s(ToVoidPtr(address), size, ToVoidPtr(ToUintPtr(mem)), size) != EOK) { + LOG_FULL(FATAL) << "memcpy_s failed"; + } Barriers::SetDynPrimitive(header, 0, MarkWord::FromForwardingAddress(address)); #if ECMASCRIPT_ENABLE_HEAP_VERIFY @@ -161,7 +162,7 @@ void ParallelEvacuator::VerifyHeapObject(TaggedObject *object) continue; } if (!objectRegion->Test(value.GetTaggedObject())) { - LOG(FATAL, RUNTIME) << "Miss mark value: " << value.GetTaggedObject() + LOG_GC(FATAL) << "Miss mark value: " << value.GetTaggedObject() << ", body address:" << slot.SlotAddress() << ", header address:" << object; } @@ -196,7 +197,7 @@ void ParallelEvacuator::UpdateReference() heap_->EnumerateSnapshotSpaceRegions([this] (Region *current) { AddWorkload(std::make_unique(this, current)); }); - LOG(DEBUG, RUNTIME) << "UpdatePointers statistic: younge space region compact moving count:" + LOG_GC(DEBUG) << "UpdatePointers statistic: younge space region compact moving count:" << youngeRegionMoveCount << "younge space region compact coping count:" << youngeRegionCopyCount << "old space region count:" << oldRegionCount; @@ -290,7 +291,7 @@ void ParallelEvacuator::UpdateRSet(Region *region) auto cb = [this](void *mem) -> bool { ObjectSlot slot(ToUintPtr(mem)); if (UpdateObjectSlot(slot)) { - Region *valueRegion = Region::ObjectAddressToRange(slot.GetTaggedObjectHeader()); + Region *valueRegion = Region::ObjectAddressToRange(slot.GetTaggedObject()); if (!valueRegion->InYoungSpace()) { return false; } diff --git a/ecmascript/mem/parallel_marker-inl.h b/ecmascript/mem/parallel_marker-inl.h index 23f8375e3fc2fe8bff6dc318434015a81c7a2735..31016cf4fdca58df0f0f7473e1ce3f79aec8e57b 100644 --- a/ecmascript/mem/parallel_marker-inl.h +++ b/ecmascript/mem/parallel_marker-inl.h @@ -23,7 +23,6 @@ #include "ecmascript/mem/heap.h" #include "ecmascript/mem/region-inl.h" #include "ecmascript/mem/tlab_allocator-inl.h" -#include "ecmascript/mem/utils.h" namespace panda::ecmascript { constexpr size_t HEAD_SIZE = TaggedObject::TaggedObjectSize(); @@ -160,8 +159,10 @@ inline uintptr_t MovableMarker::AllocateDstSpace(uint32_t threadId, size_t size, inline void MovableMarker::UpdateForwardAddressIfSuccess(uint32_t threadId, TaggedObject *object, JSHClass *klass, uintptr_t toAddress, size_t size, const MarkWord &markWord, ObjectSlot slot, bool isPromoted) { - Utils::Copy(ToVoidPtr(toAddress + HEAD_SIZE), size - HEAD_SIZE, ToVoidPtr(ToUintPtr(object) + HEAD_SIZE), - size - HEAD_SIZE); + if (memcpy_s(ToVoidPtr(toAddress + HEAD_SIZE), size - HEAD_SIZE, ToVoidPtr(ToUintPtr(object) + HEAD_SIZE), + size - HEAD_SIZE) != EOK) { + LOG_FULL(FATAL) << "memcpy_s failed"; + } workManager_->IncreaseAliveSize(threadId, size); if (isPromoted) { workManager_->IncreasePromotedSize(threadId, size); @@ -253,14 +254,34 @@ inline SlotStatus CompressGCMarker::MarkObject(uint32_t threadId, TaggedObject * return EvacuateObject(threadId, object, markWord, slot); } +inline uintptr_t CompressGCMarker::AllocateReadOnlySpace(size_t size) +{ + os::memory::LockHolder lock(mutex_); + uintptr_t forwardAddress = heap_->GetReadOnlySpace()->Allocate(size); + if (UNLIKELY(forwardAddress == 0)) { + LOG_ECMA_MEM(FATAL) << "Evacuate Read only Object: alloc failed: " + << " size: " << size; + UNREACHABLE(); + } + return forwardAddress; +} + inline SlotStatus CompressGCMarker::EvacuateObject(uint32_t threadId, TaggedObject *object, const MarkWord &markWord, ObjectSlot slot) { JSHClass *klass = markWord.GetJSHClass(); size_t size = klass->SizeFromJSHClass(object); bool isPromoted = true; - - uintptr_t forwardAddress = AllocateDstSpace(threadId, size, isPromoted); + uintptr_t forwardAddress = 0; + if (isAppSpawn_ && Heap::ShouldMoveToRoSpace(JSTaggedValue(object))) { + forwardAddress = AllocateReadOnlySpace(size); + if (JSTaggedValue(object).IsString()) { + // calculate and set hashcode for read-only ecmastring in advance + EcmaString::Cast(object)->GetHashcode(); + } + } else { + forwardAddress = AllocateDstSpace(threadId, size, isPromoted); + } ASSERT(isPromoted); bool result = Barriers::AtomicSetDynPrimitive(object, 0, markWord.GetValue(), MarkWord::FromForwardingAddress(forwardAddress)); diff --git a/ecmascript/mem/parallel_marker.cpp b/ecmascript/mem/parallel_marker.cpp index 45df33316e8dff87bc1f7378f142dc92f820ea1f..983d3d66bc1d8206e6c3f7d5edd4e5a9a7a08a70 100644 --- a/ecmascript/mem/parallel_marker.cpp +++ b/ecmascript/mem/parallel_marker.cpp @@ -146,10 +146,10 @@ void CompressGCMarker::ProcessMarkStack(uint32_t threadId) break; } - auto jsHclass = obj->GetClass(); + auto jsHClass = obj->GetClass(); ObjectSlot objectSlot(ToUintPtr(obj)); - MarkObject(threadId, jsHclass, objectSlot); - objXRay_.VisitObjectBody(obj, jsHclass, visitor); + MarkObject(threadId, jsHClass, objectSlot); + objXRay_.VisitObjectBody(obj, jsHClass, visitor); } } } // namespace panda::ecmascript diff --git a/ecmascript/mem/parallel_marker.h b/ecmascript/mem/parallel_marker.h index 0a54e793079b543bfdf878af3684dfc11c66f12f..ba8e73c0112aaaf93510f96c19da651c5b50cd25 100644 --- a/ecmascript/mem/parallel_marker.h +++ b/ecmascript/mem/parallel_marker.h @@ -21,7 +21,6 @@ #include "ecmascript/mem/object_xray.h" #include "ecmascript/mem/slots.h" #include "ecmascript/mem/work_manager.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript { class Heap; @@ -37,7 +36,7 @@ public: virtual void Initialize() { - ECMA_GC_LOG() << "Marker::Initialize do nothing"; + LOG_GC(DEBUG) << "Marker::Initialize do nothing"; } void MarkRoots(uint32_t threadId); @@ -47,20 +46,20 @@ public: virtual void ProcessMarkStack([[maybe_unused]] uint32_t threadId) { - LOG(FATAL, ECMASCRIPT) << "can not call this method"; + LOG_GC(FATAL) << "can not call this method"; } protected: // non move virtual inline void MarkObject([[maybe_unused]] uint32_t threadId, [[maybe_unused]] TaggedObject *object) { - LOG(FATAL, ECMASCRIPT) << "can not call this method"; + LOG_GC(FATAL) << "can not call this method"; } virtual inline SlotStatus MarkObject([[maybe_unused]] uint32_t threadId, [[maybe_unused]] TaggedObject *object, [[maybe_unused]] ObjectSlot slot) // move { - LOG(FATAL, ECMASCRIPT) << "can not call this method"; + LOG_GC(FATAL) << "can not call this method"; return SlotStatus::KEEP_SLOT; } @@ -70,7 +69,7 @@ protected: ObjectSlot end) = 0; virtual inline void RecordWeakReference([[maybe_unused]] uint32_t threadId, [[maybe_unused]] JSTaggedType *ref) { - LOG(FATAL, ECMASCRIPT) << "can not call this method"; + LOG_GC(FATAL) << "can not call this method"; } Heap *heap_ {nullptr}; @@ -135,6 +134,10 @@ private: class CompressGCMarker : public MovableMarker { public: explicit CompressGCMarker(Heap *heap) : MovableMarker(heap) {} + void SetAppSpawn(bool flag) + { + isAppSpawn_ = flag; + } protected: void ProcessMarkStack(uint32_t threadId) override; @@ -142,7 +145,12 @@ protected: inline SlotStatus EvacuateObject(uint32_t threadId, TaggedObject *object, const MarkWord &markWord, ObjectSlot slot) override; + inline uintptr_t AllocateReadOnlySpace(size_t size); inline void RecordWeakReference(uint32_t threadId, JSTaggedType *ref) override; + +private: + bool isAppSpawn_ {false}; + os::memory::Mutex mutex_; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_MEM_PARALLEL_MARKER_H diff --git a/ecmascript/mem/partial_gc.cpp b/ecmascript/mem/partial_gc.cpp index 271a0baf2c3ab43407afee8c1f018ad0fb267234..bf56d9c74472428fccd99cc2d2c46689d09208ae 100644 --- a/ecmascript/mem/partial_gc.cpp +++ b/ecmascript/mem/partial_gc.cpp @@ -41,21 +41,21 @@ void PartialGC::RunPhases() markingInProgress_ = heap_->CheckOngoingConcurrentMarking(); - ECMA_GC_LOG() << "markingInProgress_" << markingInProgress_; + LOG_GC(DEBUG) << "markingInProgress_" << markingInProgress_; Initialize(); Mark(); Sweep(); Evacuate(); Finish(); heap_->GetEcmaVM()->GetEcmaGCStats()->StatisticPartialGC(markingInProgress_, clockScope.GetPauseTime(), freeSize_); - ECMA_GC_LOG() << "PartialGC::RunPhases " << clockScope.TotalSpentTime(); + LOG_GC(DEBUG) << "PartialGC::RunPhases " << clockScope.TotalSpentTime(); } void PartialGC::Initialize() { ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "PartialGC::Initialize"); if (!markingInProgress_) { - LOG(INFO, RUNTIME) << "No ongoing Concurrent marking. Initializing..."; + LOG_GC(INFO) << "No ongoing Concurrent marking. Initializing..."; heap_->Prepare(); if (heap_->IsFullMark()) { heap_->GetOldSpace()->SelectCSet(); @@ -79,8 +79,7 @@ void PartialGC::Finish() auto marker = heap_->GetConcurrentMarker(); marker->Reset(false); } else { - size_t aliveSize = 0; - workManager_->Finish(aliveSize); + workManager_->Finish(); } if (heap_->IsFullMark()) { heap_->GetSweeper()->TryFillSweptRegion(); diff --git a/ecmascript/mem/region.h b/ecmascript/mem/region.h index c31b3b80fa2ce166c60fc981ce8e6fa060e012a8..919e8cb76f4caa559c0112b6b6208cc62728003d 100644 --- a/ecmascript/mem/region.h +++ b/ecmascript/mem/region.h @@ -16,11 +16,11 @@ #ifndef ECMASCRIPT_MEM_REGION_H #define ECMASCRIPT_MEM_REGION_H -#include "libpandabase/utils/aligned_storage.h" - #include "ecmascript/mem/free_object_list.h" #include "ecmascript/mem/gc_bitset.h" #include "ecmascript/mem/remembered_set.h" +#include "libpandabase/os/mutex.h" +#include "libpandabase/utils/aligned_storage.h" #include "securec.h" namespace panda { @@ -39,6 +39,7 @@ enum RegionSpaceFlag { IN_OLD_SPACE = 0x0B, IN_NON_MOVABLE_SPACE = 0x0C, IN_MACHINE_CODE_SPACE = 0x0D, + IN_READ_ONLY_SPACE = 0x0E, VALID_SPACE_MASK = 0xFF, }; @@ -74,6 +75,8 @@ static inline std::string ToSpaceTypeName(uint8_t space) return "non movable space"; case RegionSpaceFlag::IN_MACHINE_CODE_SPACE: return "machine code space"; + case RegionSpaceFlag::IN_READ_ONLY_SPACE: + return "read only space"; default: return "invalid space"; } @@ -101,6 +104,7 @@ public: wasted_(0) { flags_.spaceFlag_ = spaceType; + flags_.gcFlags_ = 0; bitsetSize_ = (spaceType == RegionSpaceFlag::IN_HUGE_OBJECT_SPACE) ? GCBitset::BYTE_PER_WORD : GCBitset::SizeOfGCBitset(end - begin); markGCBitset_ = new (ToVoidPtr(begin)) GCBitset(); @@ -263,6 +267,11 @@ public: return flags_.spaceFlag_ == RegionSpaceFlag::IN_SNAPSHOT_SPACE; } + bool InReadOnlySpace() const + { + return flags_.spaceFlag_ == RegionSpaceFlag::IN_READ_ONLY_SPACE; + } + bool InHeapSpace() const { uint8_t space = flags_.spaceFlag_; @@ -271,7 +280,8 @@ public: space == RegionSpaceFlag::IN_HUGE_OBJECT_SPACE || space == RegionSpaceFlag::IN_MACHINE_CODE_SPACE || space == RegionSpaceFlag::IN_NON_MOVABLE_SPACE || - space == RegionSpaceFlag::IN_SNAPSHOT_SPACE); + space == RegionSpaceFlag::IN_SNAPSHOT_SPACE || + space == RegionSpaceFlag::IN_READ_ONLY_SPACE); } bool InCollectSet() const @@ -347,6 +357,29 @@ public: return res; } + int SetReadOnlyAndMarked() + { + markGCBitset_->SetAllBits(bitsetSize_); + // NOLINT(hicpp-signed-bitwise) +#ifndef PANDA_TARGET_WINDOWS + int res = mprotect(reinterpret_cast(allocateBase_), GetCapacity(), PROT_READ); +#else + int res = 0; +#endif + return res; + } + + int ClearReadOnly() + { + // NOLINT(hicpp-signed-bitwise) +#ifndef PANDA_TARGET_WINDOWS + int res = mprotect(reinterpret_cast(allocateBase_), GetCapacity(), PROT_READ | PROT_WRITE); +#else + int res = 0; +#endif + return res; + } + void InitializeFreeObjectSets() { freeObjectSets_ = Span(new FreeObjectSet *[FreeObjectList::NumberOfSets()](), @@ -399,7 +432,7 @@ public: size_t AliveObject() const { - return aliveObject_; + return aliveObject_.load(std::memory_order_relaxed); } bool MostObjectAlive() const diff --git a/ecmascript/mem/slots.h b/ecmascript/mem/slots.h index faa359edc02b72a5cff95ad0a47552c3287a74c2..ec2755a1910964b3954808e336b6ff511a5d522d 100644 --- a/ecmascript/mem/slots.h +++ b/ecmascript/mem/slots.h @@ -44,7 +44,7 @@ public: *reinterpret_cast(slotAddress_) = value; } - TaggedObject *GetTaggedObjectHeader() const + TaggedObject *GetTaggedObject() const { return reinterpret_cast(GetTaggedType()); } diff --git a/ecmascript/mem/space-inl.h b/ecmascript/mem/space-inl.h index 4575f449d324de6cb848c33477aebf0c05eec6ca..e3df0c300f35716764b6b2985c819681ea96f3be 100644 --- a/ecmascript/mem/space-inl.h +++ b/ecmascript/mem/space-inl.h @@ -93,6 +93,9 @@ RegionSpaceFlag Space::GetRegionFlag() const case MemSpaceType::SNAPSHOT_SPACE: flags = RegionSpaceFlag::IN_SNAPSHOT_SPACE; break; + case MemSpaceType::READ_ONLY_SPACE: + flags = RegionSpaceFlag::IN_READ_ONLY_SPACE; + break; default: UNREACHABLE(); break; diff --git a/ecmascript/mem/space.cpp b/ecmascript/mem/space.cpp index 891842bae031e4fadb04d4853b424db9f35200d4..79a8bf6729b954f050496a5bf171e73d5b409aff 100644 --- a/ecmascript/mem/space.cpp +++ b/ecmascript/mem/space.cpp @@ -70,7 +70,7 @@ HugeObjectSpace::HugeObjectSpace(HeapRegionAllocator *heapRegionAllocator, uintptr_t HugeObjectSpace::Allocate(size_t objectSize, JSThread *thread) { - if (committedSize_ >= maximumCapacity_) { + if (committedSize_ + objectSize >= maximumCapacity_) { LOG_ECMA_MEM(INFO) << "Committed size " << committedSize_ << " of huge object space is too big."; return 0; } diff --git a/ecmascript/mem/space.h b/ecmascript/mem/space.h index 4cb4f85289fcd16c60b1bbe7efdcc13ba97a5137..afb80a70a474a1dc778f33ea8cf311bdad6075e5 100644 --- a/ecmascript/mem/space.h +++ b/ecmascript/mem/space.h @@ -35,6 +35,7 @@ enum MemSpaceType { SNAPSHOT_SPACE, COMPRESS_SPACE, LOCAL_SPACE, + READ_ONLY_SPACE, SPACE_TYPE_LAST, // Count of different types FREE_LIST_NUM = MACHINE_CODE_SPACE - OLD_SPACE + 1, @@ -57,6 +58,8 @@ static inline std::string ToSpaceTypeName(MemSpaceType type) return "snapshot space"; case COMPRESS_SPACE: return "compress space"; + case READ_ONLY_SPACE: + return "read only space"; default: return "unknown space"; } diff --git a/ecmascript/mem/sparse_space.cpp b/ecmascript/mem/sparse_space.cpp index 8d7defd29ca67f079e8aa481c8ddea766409790e..3d83404240d880d2f5f449698b4815e1960a1dfd 100644 --- a/ecmascript/mem/sparse_space.cpp +++ b/ecmascript/mem/sparse_space.cpp @@ -317,7 +317,6 @@ void OldSpace::Merge(LocalSpace *localSpace) localSpace->RemoveRegion(region); localSpace->DecreaseLiveObjectSize(region->AliveObject()); AddRegion(region); - region->MergeRSetForConcurrentSweeping(); IncreaseLiveObjectSize(region->AliveObject()); allocator_->CollectFreeObjectSet(region); }); @@ -374,7 +373,7 @@ void OldSpace::CheckRegionSize() size_t available = allocator_->GetAvailableSize(); size_t wasted = allocator_->GetWastedSize(); if (GetHeapObjectSize() + wasted + available != objectSize_) { - LOG(DEBUG, RUNTIME) << "Actual live object size:" << GetHeapObjectSize() + LOG_GC(DEBUG) << "Actual live object size:" << GetHeapObjectSize() << ", free object size:" << available << ", wasted size:" << wasted << ", but exception totoal size:" << objectSize_; diff --git a/ecmascript/mem/stw_young_gc.cpp b/ecmascript/mem/stw_young_gc.cpp index 272befc099b355bf21a428dbe936cd7377b4953e..3138a24cbbb77c29f01c66f7a1332dcb3aacfd90 100644 --- a/ecmascript/mem/stw_young_gc.cpp +++ b/ecmascript/mem/stw_young_gc.cpp @@ -42,7 +42,7 @@ void STWYoungGC::RunPhases() ECMA_BYTRACE_NAME(HITRACE_TAG_ARK, "STWYoungGC::RunPhases"); if (heap_->CheckOngoingConcurrentMarking()) { - ECMA_GC_LOG() << "STWYoungGC after ConcurrentMarking"; + LOG_GC(DEBUG) << "STWYoungGC after ConcurrentMarking"; heap_->GetConcurrentMarker()->Reset(); // HPPGC use mark result to move TaggedObject. } Initialize(); @@ -51,7 +51,7 @@ void STWYoungGC::RunPhases() Finish(); heap_->GetEcmaVM()->GetEcmaGCStats()->StatisticSTWYoungGC(clockScope.GetPauseTime(), semiCopiedSize_, promotedSize_, commitSize_); - ECMA_GC_LOG() << "STWYoungGC::RunPhases " << clockScope.TotalSpentTime(); + LOG_GC(DEBUG) << "STWYoungGC::RunPhases " << clockScope.TotalSpentTime(); } void STWYoungGC::Initialize() diff --git a/ecmascript/mem/tagged_object-inl.h b/ecmascript/mem/tagged_object-inl.h index 7cef1cf6c2b807e12c0f465c53dc6c649539f3e9..af5ca884b9174e71f0430d408014d57a1af199a5 100644 --- a/ecmascript/mem/tagged_object-inl.h +++ b/ecmascript/mem/tagged_object-inl.h @@ -27,7 +27,7 @@ namespace panda::ecmascript { inline void TaggedObject::SetClassWithoutBarrier(JSHClass *hclass) { - *reinterpret_cast(ToUintPtr(this)) = reinterpret_cast(hclass); + class_ = reinterpret_cast(hclass); } inline void TaggedObject::SetClass(JSHClass *hclass) @@ -42,7 +42,7 @@ inline void TaggedObject::SetClass(JSHandle hclass) inline JSHClass *TaggedObject::GetClass() const { - return reinterpret_cast(*reinterpret_cast(ToUintPtr(this))); + return reinterpret_cast(class_); } inline void TaggedObject::SynchronizedSetClass(JSHClass *hclass) diff --git a/ecmascript/mem/tagged_object.h b/ecmascript/mem/tagged_object.h index 2fcc35079e486b7b31ee37786deabd0bf97b1790..89c901875461153dc5c2fdb313591168afa36b12 100644 --- a/ecmascript/mem/tagged_object.h +++ b/ecmascript/mem/tagged_object.h @@ -17,7 +17,6 @@ #define ECMASCRIPT_TAGGED_OBJECT_HEADER_H #include "ecmascript/mem/mark_word.h" -#include "include/object_header.h" namespace panda::ecmascript { class JSHClass; @@ -25,9 +24,9 @@ template class JSHandle; class JSThread; -class TaggedObject : public ObjectHeader { +class TaggedObject { public: - static TaggedObject *Cast(ObjectHeader *header) + static TaggedObject *Cast(TaggedObject *header) { return static_cast(header); } @@ -47,6 +46,9 @@ public: } JSThread* GetJSThread() const; + +private: + MarkWordType class_; }; static_assert(TaggedObject::TaggedObjectSize() == sizeof(MarkWordType)); } // namespace panda::ecmascript diff --git a/ecmascript/mem/utils.h b/ecmascript/mem/utils.h deleted file mode 100644 index 780d06890328537cd1342bf6cd7d4263c24f8150..0000000000000000000000000000000000000000 --- a/ecmascript/mem/utils.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ECMASCRIPT_MEM_UTILS_H -#define ECMASCRIPT_MEM_UTILS_H - -#include "ecmascript/ecma_macros.h" -#include "securec.h" - -namespace panda::ecmascript { -class Utils { -public: - static ARK_INLINE void Copy(void *dest, size_t destCount, void *src, size_t count) - { - switch (count) { -#if !defined(PANDA_TARGET_WINDOWS) -#define COPY_BY_CONST(destCount, value) \ - case value: \ - if (memcpy_sp(dest, destCount, src, value) != EOK) { \ - LOG_ECMA(FATAL) << "memcpy_s failed"; \ - } \ - break; -#else -#define COPY_BY_CONST(destCount, value) \ - case value: \ - if (memcpy_s(dest, destCount, src, value) != EOK) { \ - LOG_ECMA(FATAL) << "memcpy_s failed"; \ - } \ - break; -#endif - COPY_BY_CONST(destCount, 16) - COPY_BY_CONST(destCount, 24) - COPY_BY_CONST(destCount, 32) - COPY_BY_CONST(destCount, 40) - COPY_BY_CONST(destCount, 48) - COPY_BY_CONST(destCount, 56) - COPY_BY_CONST(destCount, 64) - COPY_BY_CONST(destCount, 72) - COPY_BY_CONST(destCount, 80) - COPY_BY_CONST(destCount, 88) - COPY_BY_CONST(destCount, 96) - COPY_BY_CONST(destCount, 104) - COPY_BY_CONST(destCount, 112) - COPY_BY_CONST(destCount, 120) - COPY_BY_CONST(destCount, 128) -#undef COPY_BY_CONST - default: - if (memcpy_s(dest, destCount, src, count) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; - } - } - } -}; -} // namespace panda::ecmascript -#endif // ECMASCRIPT_MEM_UTILS_H diff --git a/ecmascript/mem/verification.cpp b/ecmascript/mem/verification.cpp index 873924ee4a863f6993d20dbaf5782558942219a8..a7813088be90d7db80985cdef7ea3418aba65e82 100644 --- a/ecmascript/mem/verification.cpp +++ b/ecmascript/mem/verification.cpp @@ -31,13 +31,13 @@ void VerifyObjectVisitor::VisitAllObjects(TaggedObject *obj) JSTaggedValue value(slot.GetTaggedType()); if (value.IsWeak()) { if (!heap_->IsAlive(value.GetTaggedWeakRef())) { - LOG(ERROR, RUNTIME) << "Heap verify detected a dead weak object " << value.GetTaggedObject() + LOG_GC(ERROR) << "Heap verify detected a dead weak object " << value.GetTaggedObject() << " at object:" << slot.SlotAddress(); ++(*failCount_); } } else if (value.IsHeapObject()) { if (!heap_->IsAlive(value.GetTaggedObject())) { - LOG(ERROR, RUNTIME) << "Heap verify detected a dead object at " << value.GetTaggedObject() + LOG_GC(ERROR) << "Heap verify detected a dead object at " << value.GetTaggedObject() << " at object:" << slot.SlotAddress(); ++(*failCount_); } @@ -69,7 +69,7 @@ size_t Verification::VerifyRoot() const }; objXRay_.VisitVMRoots(visit1, visit2); if (failCount > 0) { - LOG(ERROR, RUNTIME) << "VerifyRoot detects deadObject count is " << failCount; + LOG_GC(ERROR) << "VerifyRoot detects deadObject count is " << failCount; } return failCount; @@ -79,7 +79,7 @@ size_t Verification::VerifyHeap() const { size_t failCount = heap_->VerifyHeapObjects(); if (failCount > 0) { - LOG(ERROR, RUNTIME) << "VerifyHeap detects deadObject count is " << failCount; + LOG_GC(ERROR) << "VerifyHeap detects deadObject count is " << failCount; } return failCount; } diff --git a/ecmascript/mem/work_manager.cpp b/ecmascript/mem/work_manager.cpp index eeaf7cdd94fd001053f3dd9d94f2e710895d58e5..d88a9f1bcf6b4284c26de84189467dc9c92c61d4 100644 --- a/ecmascript/mem/work_manager.cpp +++ b/ecmascript/mem/work_manager.cpp @@ -39,11 +39,13 @@ WorkManager::WorkManager(Heap *heap, uint32_t threadNum) WorkManager::~WorkManager() { + Finish(); for (uint32_t i = 0; i < threadNum_; i++) { continuousQueue_[i]->Destroy(); delete continuousQueue_[i]; continuousQueue_[i] = nullptr; } + heap_->GetNativeAreaAllocator()->FreeBuffer( reinterpret_cast(workSpace_)); } @@ -103,13 +105,16 @@ bool WorkManager::PopWorkNodeFromGlobal(uint32_t threadId) return workStack_.Pop(&works_[threadId].outNode_); } -void WorkManager::Finish(size_t &aliveSize) +size_t WorkManager::Finish() { + size_t aliveSize = 0; for (uint32_t i = 0; i < threadNum_; i++) { WorkNodeHolder &holder = works_[i]; - holder.weakQueue_->FinishMarking(continuousQueue_[i]); - delete holder.weakQueue_; - holder.weakQueue_ = nullptr; + if (holder.weakQueue_ != nullptr) { + holder.weakQueue_->FinishMarking(continuousQueue_[i]); + delete holder.weakQueue_; + holder.weakQueue_ = nullptr; + } if (holder.allocator_ != nullptr) { holder.allocator_->Finalize(); delete holder.allocator_; @@ -124,11 +129,12 @@ void WorkManager::Finish(size_t &aliveSize) agedSpaces_.back())); agedSpaces_.pop_back(); } + return aliveSize; } void WorkManager::Finish(size_t &aliveSize, size_t &promotedSize) { - Finish(aliveSize); + aliveSize = Finish(); for (uint32_t i = 0; i < threadNum_; i++) { WorkNodeHolder &holder = works_[i]; promotedSize += holder.promotedSize_; diff --git a/ecmascript/mem/work_manager.h b/ecmascript/mem/work_manager.h index c436530186ce1d7e7e690af11e02db81bbe73078..a2b08ca6ee7c8343fa384eb6d6240d9d2b41ab1d 100644 --- a/ecmascript/mem/work_manager.h +++ b/ecmascript/mem/work_manager.h @@ -146,7 +146,7 @@ public: ~WorkManager(); void Initialize(TriggerGCType gcType, ParallelGCTaskPhase taskPhase); - void Finish(size_t &aliveSize); + size_t Finish(); void Finish(size_t &aliveSize, size_t &promotedSize); bool Push(uint32_t threadId, TaggedObject *object); diff --git a/ecmascript/module/js_module_manager.cpp b/ecmascript/module/js_module_manager.cpp index ec22610a71d70c42174d67fd5db41b2ccb2742bb..0a29303c25f9771eee3ac3a4810cf9e400ffc9f3 100644 --- a/ecmascript/module/js_module_manager.cpp +++ b/ecmascript/module/js_module_manager.cpp @@ -12,9 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "ecmascript/module/js_module_manager.h" +#include "ecmascript/file_loader.h" #include "ecmascript/global_env.h" #include "ecmascript/interpreter/frame_handler.h" #include "ecmascript/jspandafile/module_data_extractor.h" @@ -43,9 +43,9 @@ JSTaggedValue ModuleManager::GetModuleValueInner(JSTaggedValue key) { JSTaggedValue currentModule = GetCurrentModule(); if (currentModule.IsUndefined()) { - LOG_ECMA(FATAL) << "GetModuleValueInner currentModule failed"; + LOG_FULL(FATAL) << "GetModuleValueInner currentModule failed"; } - return SourceTextModule::Cast(currentModule.GetHeapObject())->GetModuleValue(vm_->GetJSThread(), key, false); + return SourceTextModule::Cast(currentModule.GetTaggedObject())->GetModuleValue(vm_->GetJSThread(), key, false); } JSTaggedValue ModuleManager::GetModuleValueOutter(JSTaggedValue key) @@ -53,9 +53,9 @@ JSTaggedValue ModuleManager::GetModuleValueOutter(JSTaggedValue key) JSThread *thread = vm_->GetJSThread(); JSTaggedValue currentModule = GetCurrentModule(); if (currentModule.IsUndefined()) { - LOG_ECMA(FATAL) << "GetModuleValueOutter currentModule failed"; + LOG_FULL(FATAL) << "GetModuleValueOutter currentModule failed"; } - JSTaggedValue moduleEnvironment = SourceTextModule::Cast(currentModule.GetHeapObject())->GetEnvironment(); + JSTaggedValue moduleEnvironment = SourceTextModule::Cast(currentModule.GetTaggedObject())->GetEnvironment(); ASSERT(!moduleEnvironment.IsUndefined()); JSTaggedValue resolvedBinding = LinkedHashMap::Cast(moduleEnvironment.GetTaggedObject())->Get(key); if (resolvedBinding.IsUndefined()) { @@ -65,13 +65,13 @@ JSTaggedValue ModuleManager::GetModuleValueOutter(JSTaggedValue key) ResolvedBinding *binding = ResolvedBinding::Cast(resolvedBinding.GetTaggedObject()); JSTaggedValue resolvedModule = binding->GetModule(); ASSERT(resolvedModule.IsSourceTextModule()); - SourceTextModule *module = SourceTextModule::Cast(resolvedModule.GetHeapObject()); + SourceTextModule *module = SourceTextModule::Cast(resolvedModule.GetTaggedObject()); if (module->GetTypes() == ModuleTypes::CJSMODULE) { JSHandle cjsModuleName(thread, module->GetEcmaModuleFilename()); - return JSCjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue(); + return CjsModule::SearchFromModuleCache(thread, cjsModuleName).GetTaggedValue(); } - return SourceTextModule::Cast(resolvedModule.GetHeapObject())->GetModuleValue(thread, binding->GetBindingName(), - false); + return SourceTextModule::Cast(resolvedModule.GetTaggedObject())->GetModuleValue(thread, + binding->GetBindingName(), false); } void ModuleManager::StoreModuleValue(JSTaggedValue key, JSTaggedValue value) @@ -79,7 +79,7 @@ void ModuleManager::StoreModuleValue(JSTaggedValue key, JSTaggedValue value) JSThread *thread = vm_->GetJSThread(); JSHandle currentModule(thread, GetCurrentModule()); if (currentModule.GetTaggedValue().IsUndefined()) { - LOG_ECMA(FATAL) << "StoreModuleValue currentModule failed"; + LOG_FULL(FATAL) << "StoreModuleValue currentModule failed"; } JSHandle keyHandle(thread, key); JSHandle valueHandle(thread, value); @@ -93,7 +93,7 @@ JSHandle ModuleManager::HostGetImportedModule(const CString &r JSHandle::Cast(factory->NewFromUtf8(referencingModule)); int entry = NameDictionary::Cast(resolvedModules_.GetTaggedObject())->FindEntry(referencingHandle.GetTaggedValue()); - LOG_IF(entry == -1, FATAL, ECMASCRIPT) << "cannot get module: " << referencingModule; + LOG_ECMA_IF(entry == -1, FATAL) << "cannot get module: " << referencingModule; return JSHandle(vm_->GetJSThread(), NameDictionary::Cast(resolvedModules_.GetTaggedObject())->GetValue(entry)); @@ -106,6 +106,18 @@ JSHandle ModuleManager::HostResolveImportedModule(const CStrin auto globalConstants = thread->GlobalConstants(); JSHandle referencingHandle = JSHandle::Cast(factory->NewFromUtf8(referencingModule)); + CString moduleFileName = referencingModule; + if (!vm_->GetResolvePathCallback()) { + std::string absPath; + std::string moduleName = CstringConvertToStdString(moduleFileName); + if (FileLoader::GetAbsolutePath(moduleName, absPath)) { + moduleFileName = ConvertToString(absPath); + referencingHandle = JSHandle::Cast(factory->NewFromUtf8(moduleFileName)); + } else { + LOG_ECMA(ERROR) << "absolute " << referencingModule << " path error"; + UNREACHABLE(); + } + } int entry = NameDictionary::Cast(resolvedModules_.GetTaggedObject())->FindEntry(referencingHandle.GetTaggedValue()); if (entry != -1) { @@ -114,18 +126,18 @@ JSHandle ModuleManager::HostResolveImportedModule(const CStrin } const JSPandaFile *jsPandaFile = - JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, referencingModule, JSPandaFile::ENTRY_MAIN_FUNCTION); + JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFileName, JSPandaFile::ENTRY_MAIN_FUNCTION); if (jsPandaFile == nullptr) { - LOG_ECMA(ERROR) << "open jsPandaFile " << referencingModule << " error"; + LOG_ECMA(ERROR) << "open jsPandaFile " << moduleFileName << " error"; UNREACHABLE(); } JSHandle moduleRecord = globalConstants->GetHandledUndefined(); if (jsPandaFile->IsCjs()) { - moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, referencingModule); + moduleRecord = ModuleDataExtractor::ParseCjsModule(thread, moduleFileName); } else if (jsPandaFile->IsModule()) { - moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, referencingModule); + moduleRecord = ModuleDataExtractor::ParseModule(thread, jsPandaFile, moduleFileName); } else { - LOG_ECMA(ERROR) << "jsPandaFile: " << referencingModule << " is not CjsModule or EcmaModule"; + LOG_ECMA(ERROR) << "jsPandaFile: " << moduleFileName << " is not CjsModule or EcmaModule"; UNREACHABLE(); } @@ -148,24 +160,13 @@ void ModuleManager::AddResolveImportedModule(const JSPandaFile *jsPandaFile, con .GetTaggedValue(); } -void ModuleManager::AddResolveImportedModule(const CString &referencingModule, JSHandle moduleRecord) -{ - JSThread *thread = vm_->GetJSThread(); - ObjectFactory *factory = vm_->GetFactory(); - JSHandle referencingHandle(factory->NewFromUtf8(referencingModule)); - JSHandle dict(thread, resolvedModules_); - resolvedModules_ = - NameDictionary::Put(thread, dict, referencingHandle, moduleRecord, PropertyAttributes::Default()) - .GetTaggedValue(); -} - JSTaggedValue ModuleManager::GetModuleNamespace(JSTaggedValue localName) { JSTaggedValue currentModule = GetCurrentModule(); if (currentModule.IsUndefined()) { - LOG_ECMA(FATAL) << "GetModuleNamespace currentModule failed"; + LOG_FULL(FATAL) << "GetModuleNamespace currentModule failed"; } - JSTaggedValue moduleEnvironment = SourceTextModule::Cast(currentModule.GetHeapObject())->GetEnvironment(); + JSTaggedValue moduleEnvironment = SourceTextModule::Cast(currentModule.GetTaggedObject())->GetEnvironment(); ASSERT(!moduleEnvironment.IsUndefined()); JSTaggedValue moduleNamespace = LinkedHashMap::Cast(moduleEnvironment.GetTaggedObject())->Get(localName); if (moduleNamespace.IsUndefined()) { diff --git a/ecmascript/module/js_module_manager.h b/ecmascript/module/js_module_manager.h index 59b0c6e8cc3f62cf50092f09445ea120425fe582..7cbd6e07efad4ee7714137d07316130f89c6b269 100644 --- a/ecmascript/module/js_module_manager.h +++ b/ecmascript/module/js_module_manager.h @@ -32,7 +32,6 @@ public: JSHandle HostResolveImportedModule(const CString &referencingModule); JSTaggedValue GetModuleNamespace(JSTaggedValue localName); void AddResolveImportedModule(const JSPandaFile *jsPandaFile, const CString &referencingModule); - void AddResolveImportedModule(const CString &referencingModule, JSHandle moduleRecord); void Iterate(const RootVisitor &v); private: diff --git a/ecmascript/module/js_module_namespace.cpp b/ecmascript/module/js_module_namespace.cpp index 58d29c73a7582b5191af337db32d5d999c43074f..a3eb1485b42195aa764c2763a484af9d390e8a7a 100644 --- a/ecmascript/module/js_module_namespace.cpp +++ b/ecmascript/module/js_module_namespace.cpp @@ -92,7 +92,7 @@ OperationResult ModuleNamespace::GetProperty(JSThread *thread, const JSHandleGetModule(); // 9. Assert: targetModule is not undefined. ASSERT(!targetModule.IsUndefined()); - JSTaggedValue result = SourceTextModule::Cast(targetModule.GetHeapObject())-> + JSTaggedValue result = SourceTextModule::Cast(targetModule.GetTaggedObject())-> GetModuleValue(thread, resolvedBind->GetBindingName(), true); return OperationResult(thread, result, PropertyMetaData(true)); } @@ -238,7 +238,7 @@ bool ModuleNamespace::ValidateKeysAvailable(JSThread *thread, const JSHandleIsResolvedBinding()); JSTaggedValue targetModule = JSHandle::Cast(binding)->GetModule(); ASSERT(!targetModule.IsUndefined()); - JSTaggedValue dictionary = SourceTextModule::Cast(targetModule.GetHeapObject())->GetNameDictionary(); + JSTaggedValue dictionary = SourceTextModule::Cast(targetModule.GetTaggedObject())->GetNameDictionary(); if (dictionary.IsUndefined()) { THROW_REFERENCE_ERROR_AND_RETURN(thread, "module environment is undefined", false); } diff --git a/ecmascript/module/js_module_record.cpp b/ecmascript/module/js_module_record.cpp index 38910f0524000df7172adc5222774e55658155f5..da9f0b7a49f71294775921b026cccdf286b1ce80 100644 --- a/ecmascript/module/js_module_record.cpp +++ b/ecmascript/module/js_module_record.cpp @@ -38,7 +38,7 @@ int32_t ModuleRecord::Evaluate(JSThread *thread, const JSHandle & JSTaggedValue ModuleRecord::GetNamespace(JSTaggedValue module) { if (module.IsSourceTextModule()) { - return SourceTextModule::Cast(module.GetHeapObject())->GetNamespace(); + return SourceTextModule::Cast(module.GetTaggedObject())->GetNamespace(); } UNREACHABLE(); } @@ -46,7 +46,7 @@ JSTaggedValue ModuleRecord::GetNamespace(JSTaggedValue module) void ModuleRecord::SetNamespace(JSThread *thread, JSTaggedValue module, JSTaggedValue value) { if (module.IsSourceTextModule()) { - SourceTextModule::Cast(module.GetHeapObject())->SetNamespace(thread, value); + SourceTextModule::Cast(module.GetTaggedObject())->SetNamespace(thread, value); } else { UNREACHABLE(); } diff --git a/ecmascript/module/js_module_source_text.cpp b/ecmascript/module/js_module_source_text.cpp index fa5fc238e4aec59143380576db8dfdf348bd5c9d..658e6341f4f3714839ef8cf836fee3cd8cdd5bcb 100644 --- a/ecmascript/module/js_module_source_text.cpp +++ b/ecmascript/module/js_module_source_text.cpp @@ -54,7 +54,7 @@ CVector SourceTextModule::GetExportedNames(JSThread *thread, const // a. Assert: module provides the direct binding for this export. // b. Append e.[[ExportName]] to exportedNames. std::string exportName = - base::StringHelper::ToStdString(EcmaString::Cast(ee->GetExportName().GetHeapObject())); + base::StringHelper::ToStdString(EcmaString::Cast(ee->GetExportName().GetTaggedObject())); exportedNames.emplace_back(exportName); } } @@ -70,7 +70,7 @@ CVector SourceTextModule::GetExportedNames(JSThread *thread, const // a. Assert: module imports a specific binding for this export. // b. Append e.[[ExportName]] to exportedNames. std::string exportName = - base::StringHelper::ToStdString(EcmaString::Cast(ee->GetExportName().GetHeapObject())); + base::StringHelper::ToStdString(EcmaString::Cast(ee->GetExportName().GetTaggedObject())); exportedNames.emplace_back(exportName); } } @@ -112,10 +112,10 @@ JSHandle SourceTextModule::HostResolveImportedModule(JSThread const JSHandle &module, const JSHandle &moduleRequest) { - CString moduleFilename = ConvertToString(EcmaString::Cast(moduleRequest->GetHeapObject())); + CString moduleFilename = ConvertToString(EcmaString::Cast(moduleRequest->GetTaggedObject())); ASSERT(module->GetEcmaModuleFilename().IsHeapObject()); CString baseFilename = - ConvertToString(EcmaString::Cast(module->GetEcmaModuleFilename().GetHeapObject())); + ConvertToString(EcmaString::Cast(module->GetEcmaModuleFilename().GetTaggedObject())); int suffixEnd = static_cast(moduleFilename.find_last_of('.')); if (suffixEnd == -1) { RETURN_HANDLE_IF_ABRUPT_COMPLETION(SourceTextModule, thread); @@ -664,7 +664,7 @@ void SourceTextModule::ModuleExecution(JSThread *thread, const JSHandleGetEcmaModuleFilename(); ASSERT(moduleFileName.IsString()); - CString moduleFilenameStr = ConvertToString(EcmaString::Cast(moduleFileName.GetHeapObject())); + CString moduleFilenameStr = ConvertToString(EcmaString::Cast(moduleFileName.GetTaggedObject())); const JSPandaFile *jsPandaFile = JSPandaFileManager::GetInstance()->LoadJSPandaFile(thread, moduleFilenameStr, JSPandaFile::ENTRY_MAIN_FUNCTION); if (jsPandaFile == nullptr) { diff --git a/ecmascript/napi/dfx_jsnapi.cpp b/ecmascript/napi/dfx_jsnapi.cpp index 31efbb038b22bb4c942577789ef370d26ae08c69..94ac8755b43e6ac4d674b5f533f31567dbb57bed 100644 --- a/ecmascript/napi/dfx_jsnapi.cpp +++ b/ecmascript/napi/dfx_jsnapi.cpp @@ -74,7 +74,7 @@ void DFXJSNApi::DumpHeapSnapshot([[maybe_unused]] const EcmaVM *vm, [[maybe_unus bool DFXJSNApi::BuildNativeAndJsStackTrace(const EcmaVM *vm, std::string &stackTraceStr) { - stackTraceStr = ecmascript::base::ErrorHelper::BuildJsStackTrace(vm->GetJSThreadNoCheck(), true); + stackTraceStr = ecmascript::base::ErrorHelper::BuildJsStackTrace(vm->GetAssociatedJSThread(), true); if (stackTraceStr.empty()) { return false; } @@ -83,17 +83,18 @@ bool DFXJSNApi::BuildNativeAndJsStackTrace(const EcmaVM *vm, std::string &stackT bool DFXJSNApi::BuildJsStackTrace(const EcmaVM *vm, std::string &stackTraceStr) { - stackTraceStr = ecmascript::base::ErrorHelper::BuildJsStackTrace(vm->GetJSThreadNoCheck(), false); + stackTraceStr = ecmascript::base::ErrorHelper::BuildJsStackTrace(vm->GetAssociatedJSThread(), false); if (stackTraceStr.empty()) { return false; } return true; } -bool DFXJSNApi::StartHeapTracking(const EcmaVM *vm, double timeInterval, bool isVmMode, Stream *stream) +bool DFXJSNApi::StartHeapTracking(const EcmaVM *vm, double timeInterval, bool isVmMode, + Stream *stream, bool traceAllocation) { ecmascript::HeapProfilerInterface *heapProfile = ecmascript::HeapProfilerInterface::GetInstance(vm); - return heapProfile->StartHeapTracking(timeInterval, isVmMode, stream); + return heapProfile->StartHeapTracking(timeInterval, isVmMode, stream, traceAllocation); } bool DFXJSNApi::StopHeapTracking(const EcmaVM *vm, const std::string &filePath) @@ -175,7 +176,7 @@ std::unique_ptr DFXJSNApi::StopCpuProfilerForInfo() CpuProfiler *singleton = CpuProfiler::GetInstance(); auto profile = singleton->StopCpuProfilerForInfo(); if (profile == nullptr) { - LOG(ERROR, DEBUGGER) << "Transfer CpuProfiler::StopCpuProfilerImpl is failure"; + LOG_DEBUGGER(ERROR) << "Transfer CpuProfiler::StopCpuProfilerImpl is failure"; } return profile; } @@ -189,19 +190,19 @@ void DFXJSNApi::SetCpuSamplingInterval(int interval) bool DFXJSNApi::SuspendVM(const EcmaVM *vm) { - ecmascript::VmThreadControl* vmThreadControl = vm->GetJSThreadNoCheck()->GetVmThreadControl(); + ecmascript::VmThreadControl* vmThreadControl = vm->GetAssociatedJSThread()->GetVmThreadControl(); return vmThreadControl->NotifyVMThreadSuspension(); } void DFXJSNApi::ResumeVM(const EcmaVM *vm) { - ecmascript::VmThreadControl* vmThreadControl = vm->GetJSThreadNoCheck()->GetVmThreadControl(); + ecmascript::VmThreadControl* vmThreadControl = vm->GetAssociatedJSThread()->GetVmThreadControl(); vmThreadControl->ResumeVM(); } bool DFXJSNApi::IsSuspended(const EcmaVM *vm) { - ecmascript::VmThreadControl* vmThreadControl = vm->GetJSThreadNoCheck()->GetVmThreadControl(); + ecmascript::VmThreadControl* vmThreadControl = vm->GetAssociatedJSThread()->GetVmThreadControl(); return vmThreadControl->IsSuspended(); } diff --git a/ecmascript/napi/include/dfx_jsnapi.h b/ecmascript/napi/include/dfx_jsnapi.h index e98825840344d228d5791865a2575cfb59831c94..d23ee1c8498b2b0101c47af1fbaa5c8960d668e6 100644 --- a/ecmascript/napi/include/dfx_jsnapi.h +++ b/ecmascript/napi/include/dfx_jsnapi.h @@ -52,7 +52,7 @@ public: static bool BuildNativeAndJsStackTrace(const EcmaVM *vm, std::string &stackTraceStr); static bool BuildJsStackTrace(const EcmaVM *vm, std::string &stackTraceStr); static bool StartHeapTracking(const EcmaVM *vm, double timeInterval, bool isVmMode = true, - Stream *stream = nullptr); + Stream *stream = nullptr, bool traceAllocation = false); static bool StopHeapTracking(const EcmaVM *vm, const std::string &filePath); static bool StopHeapTracking(const EcmaVM *vm, Stream *stream, Progress *progress = nullptr); static void PrintStatisticResult(const EcmaVM *vm); diff --git a/ecmascript/napi/include/jsnapi.h b/ecmascript/napi/include/jsnapi.h index 02b821bce5a0df0495cf887910136941750a25c7..8822eeb12b6f23b96930e1e95015ea260059acca 100644 --- a/ecmascript/napi/include/jsnapi.h +++ b/ecmascript/napi/include/jsnapi.h @@ -52,7 +52,7 @@ namespace ecmascript { class EcmaVM; class JSRuntimeOptions; class JSThread; -class EcmaRuntimeCallInfo; +struct EcmaRuntimeCallInfo; } // namespace ecmascript using Deleter = void (*)(void *nativePointer, void *data); @@ -673,6 +673,7 @@ public: } static Local New(const EcmaVM *vm); static Local New(const EcmaVM *vm, void *attach, void *detach); + bool Set(const EcmaVM *vm, void *attach, void *detach); bool Set(const EcmaVM *vm, Local key, Local value); bool Set(const EcmaVM *vm, uint32_t key, Local value); bool SetAccessorProperty(const EcmaVM *vm, Local key, Local getter, @@ -733,6 +734,7 @@ class PUBLIC_API PromiseRef : public ObjectRef { public: Local Catch(const EcmaVM *vm, Local handler); Local Then(const EcmaVM *vm, Local handler); + Local Finally(const EcmaVM *vm, Local handler); Local Then(const EcmaVM *vm, Local onFulfilled, Local onRejected); }; @@ -848,11 +850,26 @@ public: class PUBLIC_API MapRef : public ObjectRef { public: int32_t GetSize(); + Local GetKey(const EcmaVM *vm, int entry); + Local GetValue(const EcmaVM *vm, int entry); }; class PUBLIC_API SetRef : public ObjectRef { public: int32_t GetSize(); + Local GetValue(const EcmaVM *vm, int entry); +}; + +class PUBLIC_API MapIteratorRef : public ObjectRef { +public: + int32_t GetIndex(); + Local GetKind(const EcmaVM *vm); +}; + +class PUBLIC_API SetIteratorRef : public ObjectRef { +public: + int32_t GetIndex(); + Local GetKind(const EcmaVM *vm); }; class PUBLIC_API JSON { @@ -868,6 +885,7 @@ public: static Local ReferenceError(const EcmaVM *vm, Local message); static Local SyntaxError(const EcmaVM *vm, Local message); static Local TypeError(const EcmaVM *vm, Local message); + static Local AggregateError(const EcmaVM *vm, Local message); static Local EvalError(const EcmaVM *vm, Local message); }; @@ -943,6 +961,16 @@ public: asmOpcodeDisableRange_ = value; } + void SetIsWorker() + { + isWorker_ = true; + } + + bool GetIsWorker() const + { + return isWorker_; + } + private: std::string GetGcType() const { @@ -1051,6 +1079,7 @@ private: size_t gcThreadNum_ {DEFAULT_GC_THREAD_NUM}; size_t longPauseTime_ {DEFAULT_LONG_PAUSE_TIME}; bool enableAsmInterpreter_ {false}; + bool isWorker_ {false}; std::string asmOpcodeDisableRange_ {""}; friend JSNApi; }; @@ -1075,6 +1104,8 @@ private: class PUBLIC_API JSNApi { public: + using DebuggerPostTask = std::function&&)>; + // JSVM // fixme: Rename SEMI_GC to YOUNG_GC enum class PUBLIC_API TRIGGER_GC_TYPE : uint8_t { SEMI_GC, OLD_GC, FULL_GC }; @@ -1087,6 +1118,7 @@ public: const std::string &filename = ""); static bool ExecuteModuleFromBuffer(EcmaVM *vm, const void *data, int32_t size, const std::string &file); static Local GetExportObject(EcmaVM *vm, const std::string &file, const std::string &key); + static Local GetExportObjectFromBuffer(EcmaVM *vm, const std::string &file, const std::string &key); // ObjectRef Operation static Local GetGlobalObject(const EcmaVM *vm); @@ -1100,12 +1132,12 @@ public: static Local GetAndClearUncaughtException(const EcmaVM *vm); static Local GetUncaughtException(const EcmaVM *vm); static void EnableUserUncaughtErrorHandler(EcmaVM *vm); - - static bool StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode, int32_t instanceId = 0); + static bool StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode, int32_t instanceId = 0, + const DebuggerPostTask &debuggerPostTask = {}); static bool StopDebugger(EcmaVM *vm); // Serialize & Deserialize. static void* SerializeValue(const EcmaVM *vm, Local data, Local transfer); - static Local DeserializeValue(const EcmaVM *vm, void* recoder); + static Local DeserializeValue(const EcmaVM *vm, void *recoder, void *hint); static void DeleteSerializationData(void *data); static void SetHostPromiseRejectionTracker(EcmaVM *vm, void *cb, void* data); static void SetHostResolvePathTracker(EcmaVM *vm, @@ -1152,7 +1184,7 @@ public: EcmaVM *GetVM() const; - inline size_t GetArgsNumber() const + inline int32_t GetArgsNumber() const { return numArgs_; } @@ -1192,7 +1224,7 @@ private: uintptr_t GetArgAddress(uint32_t idx) const { - if (idx < static_cast(numArgs_ + FIRST_ARGS_INDEX)) { + if (idx < static_cast(numArgs_ + FIRST_ARGS_INDEX)) { return reinterpret_cast(&stackArgs_[idx]); } return 0U; @@ -1200,7 +1232,7 @@ private: private: JSThread *thread_ {nullptr}; - size_t numArgs_ = 0; + int32_t numArgs_ = 0; JSTaggedType *stackArgs_ {nullptr}; void *data_ {nullptr}; friend class FunctionRef; diff --git a/ecmascript/napi/jsnapi.cpp b/ecmascript/napi/jsnapi.cpp index 205a5417d8bbfc089becb52abacafd347c33dcbc..b2981debce196c22cb1fe1d56f89c8c0f37bd747 100644 --- a/ecmascript/napi/jsnapi.cpp +++ b/ecmascript/napi/jsnapi.cpp @@ -26,7 +26,7 @@ #if defined(ECMASCRIPT_SUPPORT_CPUPROFILER) #include "ecmascript/dfx/cpu_profiler/cpu_profiler.h" #endif -#include "ecmascript/ecma_global_storage-inl.h" +#include "ecmascript/ecma_global_storage.h" #include "ecmascript/ecma_runtime_call_info.h" #include "ecmascript/ecma_string.h" #include "ecmascript/ecma_vm.h" @@ -39,13 +39,16 @@ #include "ecmascript/js_bigint.h" #include "ecmascript/js_dataview.h" #include "ecmascript/js_function.h" +#include "ecmascript/js_iterator.h" #include "ecmascript/js_map.h" +#include "ecmascript/js_map_iterator.h" #include "ecmascript/js_primitive_ref.h" #include "ecmascript/js_promise.h" #include "ecmascript/js_regexp.h" #include "ecmascript/js_runtime_options.h" #include "ecmascript/js_serializer.h" #include "ecmascript/js_set.h" +#include "ecmascript/js_set_iterator.h" #include "ecmascript/js_tagged_number.h" #include "ecmascript/js_thread.h" #include "ecmascript/js_typed_array.h" @@ -110,6 +113,10 @@ using ecmascript::job::QueueType; using ecmascript::JSRuntimeOptions; using ecmascript::BigInt; using ecmascript::MemMapAllocator; +using ecmascript::JSMapIterator; +using ecmascript::JSSetIterator; +using ecmascript::IterationKind; +using ecmascript::JSIterator; template using JSHandle = ecmascript::JSHandle; @@ -129,6 +136,7 @@ EcmaVM *JSNApi::CreateJSVM(const RuntimeOption &option) runtimeOptions.SetArkProperties(option.GetArkProperties()); runtimeOptions.SetLongPauseTime(option.GetLongPauseTime()); runtimeOptions.SetGcThreadNum(option.GetGcThreadNum()); + runtimeOptions.SetIsWorker(option.GetIsWorker()); // Mem runtimeOptions.SetHeapSizeLimit(option.GetGcPoolSize()); // asmInterpreter @@ -145,7 +153,6 @@ EcmaVM *JSNApi::CreateJSVM(const RuntimeOption &option) if (option.GetLogBufPrint() != nullptr) { Logger::SetMobileLogPrintEntryPointByPtr(reinterpret_cast(option.GetLogBufPrint())); } - runtimeOptions.SetEnableArkTools(option.GetEnableArkTools()); return CreateEcmaVM(runtimeOptions); } @@ -160,7 +167,11 @@ EcmaVM *JSNApi::CreateEcmaVM(const JSRuntimeOptions &options) initialize_ = true; } } - return EcmaVM::Create(options); + auto config = ecmascript::EcmaParamConfiguration(options.IsWorker(), + MemMapAllocator::GetInstance()->GetCapacity()); + LOG_ECMA(INFO) << "CreateEcmaVM: isWorker = " << options.IsWorker() << ", vmCount = " << vmCount_; + MemMapAllocator::GetInstance()->IncreaseAndCheckReserved(config.GetMaxHeapSize()); + return EcmaVM::Create(options, config); } void JSNApi::DestroyJSVM(EcmaVM *ecmaVm) @@ -169,6 +180,8 @@ void JSNApi::DestroyJSVM(EcmaVM *ecmaVm) if (!initialize_) { return; } + auto &config = ecmaVm->GetEcmaParamConfiguration(); + MemMapAllocator::GetInstance()->DecreaseReserved(config.GetMaxHeapSize()); EcmaVM::Destroy(ecmaVm); vmCount_--; if (vmCount_ <= 0) { @@ -203,7 +216,8 @@ void JSNApi::ThrowException(const EcmaVM *vm, Local error) } #if defined(ECMASCRIPT_SUPPORT_DEBUGGER) -bool JSNApi::StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode, int32_t instanceId) +bool JSNApi::StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode, int32_t instanceId, + const DebuggerPostTask &debuggerPostTask) { const auto &handler = vm->GetJsDebuggerManager()->GetDebugLibraryHandle(); if (handler.IsValid()) { @@ -215,15 +229,16 @@ bool JSNApi::StartDebugger(const char *libraryPath, EcmaVM *vm, bool isDebugMode return false; } - using StartDebugger = bool (*)(const std::string &, EcmaVM *, bool, int32_t); + using StartDebugger = bool (*)(const std::string &, EcmaVM *, bool, int32_t, const DebuggerPostTask &); auto sym = panda::os::library_loader::ResolveSymbol(handle.Value(), "StartDebug"); if (!sym) { - LOG(ERROR, RUNTIME) << sym.Error().ToString(); + LOG_ECMA(ERROR) << sym.Error().ToString(); return false; } - bool ret = reinterpret_cast(sym.Value())("PandaDebugger", vm, isDebugMode, instanceId); + bool ret = reinterpret_cast(sym.Value())("PandaDebugger", vm, isDebugMode, instanceId, + debuggerPostTask); if (ret) { vm->GetJsDebuggerManager()->SetDebugMode(isDebugMode); vm->GetJsDebuggerManager()->SetDebugLibraryHandle(std::move(handle.Value())); @@ -242,7 +257,7 @@ bool JSNApi::StopDebugger(EcmaVM *vm) auto sym = panda::os::library_loader::ResolveSymbol(handle, "StopDebug"); if (!sym) { - LOG(ERROR, RUNTIME) << sym.Error().ToString(); + LOG_ECMA(ERROR) << sym.Error().ToString(); return false; } @@ -254,7 +269,7 @@ bool JSNApi::StopDebugger(EcmaVM *vm) bool JSNApi::Execute(EcmaVM *vm, const std::string &fileName, const std::string &entry) { - LOG_ECMA(DEBUG) << "start to execute ark file" << fileName; + LOG_ECMA(DEBUG) << "start to execute ark file: " << fileName; JSThread *thread = vm->GetAssociatedJSThread(); if (!ecmascript::JSPandaFileExecutor::ExecuteFromFile(thread, fileName.c_str(), entry)) { LOG_ECMA(ERROR) << "Cannot execute ark file '" << fileName @@ -267,6 +282,7 @@ bool JSNApi::Execute(EcmaVM *vm, const std::string &fileName, const std::string bool JSNApi::Execute(EcmaVM *vm, const uint8_t *data, int32_t size, const std::string &entry, const std::string &filename) { + LOG_ECMA(DEBUG) << "start to execute ark buffer: " << filename; JSThread *thread = vm->GetAssociatedJSThread(); if (!ecmascript::JSPandaFileExecutor::ExecuteFromBuffer(thread, data, size, entry, filename.c_str())) { LOG_ECMA(ERROR) << "Cannot execute ark buffer file '" << filename @@ -344,7 +360,7 @@ uintptr_t JSNApi::ClearWeak(const EcmaVM *vm, uintptr_t localAddress) } if (JSTaggedValue(reinterpret_cast(localAddress)->GetObject()) .IsUndefined()) { - LOG(ERROR, RUNTIME) << "The object of weak reference has been recycled!"; + LOG_ECMA(ERROR) << "The object of weak reference has been recycled!"; return 0; } return vm->GetJSThread()->GetEcmaGlobalStorage()->ClearWeak(localAddress); @@ -383,11 +399,11 @@ void *JSNApi::SerializeValue(const EcmaVM *vm, Local value, Local JSNApi::DeserializeValue(const EcmaVM *vm, void *recoder) +Local JSNApi::DeserializeValue(const EcmaVM *vm, void *recoder, void *hint) { ecmascript::JSThread *thread = vm->GetJSThread(); std::unique_ptr data(reinterpret_cast(recoder)); - ecmascript::Deserializer deserializer(thread, data.release()); + ecmascript::Deserializer deserializer(thread, data.release(), hint); JSHandle result = deserializer.ReadValue(); return JSNApiHelper::ToLocal(result); } @@ -481,6 +497,19 @@ Local JSNApi::GetExportObject(EcmaVM *vm, const std::string &file, co return JSNApiHelper::ToLocal(exportObj); } +Local JSNApi::GetExportObjectFromBuffer(EcmaVM *vm, const std::string &file, const std::string &key) +{ + ecmascript::ModuleManager *moduleManager = vm->GetModuleManager(); + JSThread *thread = vm->GetJSThread(); + JSHandle ecmaModule = moduleManager->HostGetImportedModule(file.c_str()); + + ObjectFactory *factory = vm->GetFactory(); + JSHandle keyHandle = factory->NewFromASCII(key.c_str()); + + JSHandle exportObj(thread, ecmaModule->GetModuleValue(thread, keyHandle.GetTaggedValue(), false)); + return JSNApiHelper::ToLocal(exportObj); +} + void JSNApi::InitializeMemMapAllocator() { MemMapAllocator::GetInstance()->Initialize(ecmascript::DEFAULT_REGION_SIZE); @@ -766,6 +795,22 @@ Local ObjectRef::New(const EcmaVM *vm, void *detach, void *attach) return JSNApiHelper::ToLocal(object); } +bool ObjectRef::Set(const EcmaVM *vm, void *detach, void *attach) +{ + [[maybe_unused]] LocalScope scope(vm); + JSHandle env = vm->GetGlobalEnv(); + JSHandle object = JSNApiHelper::ToJSHandle(this); + JSHandle detachKey = env->GetDetachSymbol(); + JSHandle attachKey = env->GetAttachSymbol(); + JSHandle detachValue = JSNApiHelper::ToJSHandle(NativePointerRef::New(vm, detach)); + JSHandle attachValue = JSNApiHelper::ToJSHandle(NativePointerRef::New(vm, attach)); + bool detachResult = JSTaggedValue::SetProperty(vm->GetJSThread(), object, detachKey, detachValue); + RETURN_VALUE_IF_ABRUPT(vm->GetJSThread(), false); + bool attachResult = JSTaggedValue::SetProperty(vm->GetJSThread(), object, attachKey, attachValue); + RETURN_VALUE_IF_ABRUPT(vm->GetJSThread(), false); + return detachResult && attachResult; +} + bool ObjectRef::Set(const EcmaVM *vm, Local key, Local value) { [[maybe_unused]] LocalScope scope(vm); @@ -1013,13 +1058,14 @@ Local FunctionRef::Call(const EcmaVM *vm, Local thisObj, JSHandle func = JSNApiHelper::ToJSHandle(this); JSHandle thisValue = JSNApiHelper::ToJSHandle(thisObj); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, func, thisValue, undefined, length); + RETURN_VALUE_IF_ABRUPT_NOT_CLEAR_EXCEPTION(thread, JSValueRef::Exception(vm)); for (int32_t i = 0; i < length; i++) { JSHandle arg = JSNApiHelper::ToJSHandle(argv[i]); - info.SetCallArg(i, arg.GetTaggedValue()); + info->SetCallArg(i, arg.GetTaggedValue()); } - JSTaggedValue result = JSFunction::Call(&info); + JSTaggedValue result = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_NOT_CLEAR_EXCEPTION(thread, JSValueRef::Exception(vm)); JSHandle resultValue(thread, result); @@ -1041,13 +1087,14 @@ Local FunctionRef::Constructor(const EcmaVM *vm, JSHandle func = JSNApiHelper::ToJSHandle(this); JSHandle newTarget = func; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, func, undefined, newTarget, length); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); for (int32_t i = 0; i < length; i++) { JSHandle arg = JSNApiHelper::ToJSHandle(argv[i]); - info.SetCallArg(i, arg.GetTaggedValue()); + info->SetCallArg(i, arg.GetTaggedValue()); } - JSTaggedValue result = JSFunction::Construct(&info); + JSTaggedValue result = JSFunction::Construct(info); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); JSHandle resultValue(thread, result); @@ -1164,10 +1211,11 @@ bool PromiseCapabilityRef::Resolve(const EcmaVM *vm, Local value) JSHandle capacity(JSNApiHelper::ToJSHandle(this)); JSHandle resolve(thread, capacity->GetResolve()); JSHandle undefined(constants->GetHandledUndefined()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); - info.SetCallArg(arg.GetTaggedValue()); - JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT(thread, false); + info->SetCallArg(arg.GetTaggedValue()); + JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT(thread, false); EcmaVM::ConstCast(vm)->ExecutePromisePendingJob(); @@ -1186,10 +1234,11 @@ bool PromiseCapabilityRef::Reject(const EcmaVM *vm, Local reason) JSHandle reject(thread, capacity->GetReject()); JSHandle undefined(constants->GetHandledUndefined()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); - info.SetCallArg(arg.GetTaggedValue()); - JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT(thread, false); + info->SetCallArg(arg.GetTaggedValue()); + JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT(thread, false); EcmaVM::ConstCast(vm)->ExecutePromisePendingJob(); @@ -1207,10 +1256,30 @@ Local PromiseRef::Catch(const EcmaVM *vm, Local handler JSHandle catchKey(thread, constants->GetPromiseCatchString()); JSHandle reject = JSNApiHelper::ToJSHandle(handler); JSHandle undefined = constants->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promise, undefined, 1); - info.SetCallArg(reject.GetTaggedValue()); - JSTaggedValue result = JSFunction::Invoke(&info, catchKey); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); + info->SetCallArg(reject.GetTaggedValue()); + JSTaggedValue result = JSFunction::Invoke(info, catchKey); + + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); + return JSNApiHelper::ToLocal(JSHandle(thread, result)); +} + +Local PromiseRef::Finally(const EcmaVM *vm, Local handler) +{ + JSThread *thread = vm->GetJSThread(); + const GlobalEnvConstants *constants = thread->GlobalConstants(); + + JSHandle promise = JSNApiHelper::ToJSHandle(this); + JSHandle finallyKey = constants->GetHandledPromiseFinallyString(); + JSHandle resolver = JSNApiHelper::ToJSHandle(handler); + JSHandle undefined(constants->GetHandledUndefined()); + EcmaRuntimeCallInfo *info = + ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promise, undefined, 2); // 2: two args + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); + info->SetCallArg(resolver.GetTaggedValue(), undefined.GetTaggedValue()); + JSTaggedValue result = JSFunction::Invoke(info, finallyKey); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(JSHandle(thread, result)); @@ -1225,10 +1294,11 @@ Local PromiseRef::Then(const EcmaVM *vm, Local handler) JSHandle thenKey(thread, constants->GetPromiseThenString()); JSHandle resolver = JSNApiHelper::ToJSHandle(handler); JSHandle undefined(constants->GetHandledUndefined()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promise, undefined, 2); // 2: two args - info.SetCallArg(resolver.GetTaggedValue(), undefined.GetTaggedValue()); - JSTaggedValue result = JSFunction::Invoke(&info, thenKey); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); + info->SetCallArg(resolver.GetTaggedValue(), undefined.GetTaggedValue()); + JSTaggedValue result = JSFunction::Invoke(info, thenKey); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(JSHandle(thread, result)); @@ -1244,10 +1314,11 @@ Local PromiseRef::Then(const EcmaVM *vm, Local onFulfil JSHandle resolver = JSNApiHelper::ToJSHandle(onFulfilled); JSHandle reject = JSNApiHelper::ToJSHandle(onRejected); JSHandle undefined(constants->GetHandledUndefined()); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, promise, undefined, 2); // 2: two args - info.SetCallArg(resolver.GetTaggedValue(), reject.GetTaggedValue()); - JSTaggedValue result = JSFunction::Invoke(&info, thenKey); + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); + info->SetCallArg(resolver.GetTaggedValue(), reject.GetTaggedValue()); + JSTaggedValue result = JSFunction::Invoke(info, thenKey); RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); return JSNApiHelper::ToLocal(JSHandle(thread, result)); @@ -1366,11 +1437,12 @@ Local TypedArrayRef::GetArrayBuffer(const EcmaVM *vm) JSHandle func = env->Get##Type##Function(); \ JSHandle arrayBuffer(JSNApiHelper::ToJSHandle(buffer)); \ JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); \ - const size_t argsLength = 3; \ - EcmaRuntimeCallInfo info = \ + const int32_t argsLength = 3; \ + EcmaRuntimeCallInfo *info = \ ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, func, undefined, func, argsLength); \ - info.SetCallArg(arrayBuffer.GetTaggedValue(), JSTaggedValue(byteOffset), JSTaggedValue(length)); \ - JSTaggedValue result = JSFunction::Construct(&info); \ + RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); \ + info->SetCallArg(arrayBuffer.GetTaggedValue(), JSTaggedValue(byteOffset), JSTaggedValue(length)); \ + JSTaggedValue result = JSFunction::Construct(info); \ RETURN_VALUE_IF_ABRUPT(thread, JSValueRef::Exception(vm)); \ JSHandle resultHandle(thread, result); \ return JSNApiHelper::ToLocal(resultHandle); \ @@ -1472,7 +1544,7 @@ double DateRef::GetTime() { JSHandle date(JSNApiHelper::ToJSHandle(this)); if (!date->IsDate()) { - LOG(ERROR, RUNTIME) << "Not a Date Object"; + LOG_ECMA(ERROR) << "Not a Date Object"; } return date->GetTime().GetDouble(); } @@ -1483,12 +1555,87 @@ int32_t MapRef::GetSize() return map->GetSize(); } +Local MapRef::GetKey(const EcmaVM *vm, int entry) +{ + JSHandle map(JSNApiHelper::ToJSHandle(this)); + JSThread *thread = vm->GetJSThread(); + return JSNApiHelper::ToLocal(JSHandle(thread, map->GetKey(entry))); +} + +Local MapRef::GetValue(const EcmaVM *vm, int entry) +{ + JSHandle map(JSNApiHelper::ToJSHandle(this)); + JSThread *thread = vm->GetJSThread(); + return JSNApiHelper::ToLocal(JSHandle(thread, map->GetValue(entry))); +} + int32_t SetRef::GetSize() { JSHandle set(JSNApiHelper::ToJSHandle(this)); return set->GetSize(); } +Local SetRef::GetValue(const EcmaVM *vm, int entry) +{ + JSHandle set(JSNApiHelper::ToJSHandle(this)); + JSThread *thread = vm->GetJSThread(); + return JSNApiHelper::ToLocal(JSHandle(thread, set->GetValue(entry))); +} + +int32_t MapIteratorRef::GetIndex() +{ + JSHandle jsMapIter(JSNApiHelper::ToJSHandle(this)); + return jsMapIter->GetNextIndex(); +} + +Local MapIteratorRef::GetKind(const EcmaVM *vm) +{ + JSHandle jsMapIter(JSNApiHelper::ToJSHandle(this)); + IterationKind iterKind = jsMapIter->GetIterationKind(); + Local result; + switch (iterKind) { + case IterationKind::KEY: + result = StringRef::NewFromUtf8(vm, "keys"); + break; + case IterationKind::VALUE: + result = StringRef::NewFromUtf8(vm, "values"); + break; + case IterationKind::KEY_AND_VALUE: + result = StringRef::NewFromUtf8(vm, "entries"); + break; + default: + break; + } + return result; +} + +int32_t SetIteratorRef::GetIndex() +{ + JSHandle jsSetIter(JSNApiHelper::ToJSHandle(this)); + return jsSetIter->GetNextIndex(); +} + +Local SetIteratorRef::GetKind(const EcmaVM *vm) +{ + JSHandle jsSetIter(JSNApiHelper::ToJSHandle(this)); + IterationKind iterKind = jsSetIter->GetIterationKind(); + Local result; + switch (iterKind) { + case IterationKind::KEY: + result = StringRef::NewFromUtf8(vm, "keys"); + break; + case IterationKind::VALUE: + result = StringRef::NewFromUtf8(vm, "values"); + break; + case IterationKind::KEY_AND_VALUE: + result = StringRef::NewFromUtf8(vm, "entries"); + break; + default: + break; + } + return result; +} + // ----------------------------------- FunctionCallback --------------------------------- JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *ecmaRuntimeCallInfo) { @@ -1498,6 +1645,7 @@ JSTaggedValue Callback::RegisterCallback(ecmascript::EcmaRuntimeCallInfo *ecmaRu if (!constructor->IsJSFunction()) { return JSTaggedValue::False(); } + [[maybe_unused]] LocalScope scope(thread->GetEcmaVM()); JSHandle function(constructor); JSHandle extraInfoValue(thread, function->GetFunctionExtraInfo()); if (!extraInfoValue->IsJSNativePointer()) { @@ -1889,31 +2037,31 @@ bool JSValueRef::IsJSPrimitiveRef() bool JSValueRef::IsJSPrimitiveNumber() { JSHandle obj = JSNApiHelper::ToJSHandle(this); - return JSPrimitiveRef::Cast(obj->GetHeapObject())->IsNumber(); + return JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsNumber(); } bool JSValueRef::IsJSPrimitiveInt() { JSHandle obj = JSNApiHelper::ToJSHandle(this); - return JSPrimitiveRef::Cast(obj->GetHeapObject())->IsInt(); + return JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsInt(); } bool JSValueRef::IsJSPrimitiveBoolean() { JSHandle obj = JSNApiHelper::ToJSHandle(this); - return JSPrimitiveRef::Cast(obj->GetHeapObject())->IsBoolean(); + return JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsBoolean(); } bool JSValueRef::IsJSPrimitiveString() { JSHandle obj = JSNApiHelper::ToJSHandle(this); - return JSPrimitiveRef::Cast(obj->GetHeapObject())->IsString(); + return JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsString(); } bool JSValueRef::IsJSPrimitiveSymbol() { JSHandle obj = JSNApiHelper::ToJSHandle(this); - return JSPrimitiveRef::Cast(obj->GetHeapObject())->IsSymbol(); + return JSPrimitiveRef::Cast(obj->GetTaggedObject())->IsSymbol(); } bool JSValueRef::IsGeneratorObject() diff --git a/ecmascript/napi/jsnapi_helper.h b/ecmascript/napi/jsnapi_helper.h index 8ab899fb9a9d67d9a614e29da4ab935587e760c3..792e9511b8c4c37eb9271c5ce46f03595a72513a 100644 --- a/ecmascript/napi/jsnapi_helper.h +++ b/ecmascript/napi/jsnapi_helper.h @@ -58,6 +58,7 @@ V(SyntaxError, SYNTAX_ERROR) \ V(ReferenceError, REFERENCE_ERROR) \ V(TypeError, TYPE_ERROR) \ + V(AggregateError, AGGREGATE_ERROR) \ V(EvalError, EVAL_ERROR) namespace panda { diff --git a/ecmascript/napi/test/jsnapi_tests.cpp b/ecmascript/napi/test/jsnapi_tests.cpp index 4ee6c15234d28591ed1d82ab4e6f42433d066dad..041286453228dcbbd3727e9ecad7c8b4b0adc568 100644 --- a/ecmascript/napi/test/jsnapi_tests.cpp +++ b/ecmascript/napi/test/jsnapi_tests.cpp @@ -329,7 +329,7 @@ HWTEST_F_L0(JSNApiTests, GetProtoType) void CheckReject(JsiRuntimeCallInfo* info) { - ASSERT_EQ(info->GetArgsNumber(), 1U); + ASSERT_EQ(info->GetArgsNumber(), 1); Local reason = info->GetCallArgRef(0); ASSERT_TRUE(reason->IsString()); ASSERT_EQ(Local(reason)->ToString(), "Reject"); @@ -361,7 +361,7 @@ HWTEST_F_L0(JSNApiTests, PromiseCatch) void CheckResolve(JsiRuntimeCallInfo* info) { - ASSERT_EQ(info->GetArgsNumber(), 1U); + ASSERT_EQ(info->GetArgsNumber(), 1); Local value = info->GetCallArgRef(0); ASSERT_TRUE(value->IsNumber()); ASSERT_EQ(Local(value)->Value(), 300.3); // 300.3 : test case of input diff --git a/ecmascript/object_factory.cpp b/ecmascript/object_factory.cpp index fa29a52017741abeaee599de1fe894b4fdde9280..3beab355e388eb1ee0e1d0140ac5a866d8327fe9 100644 --- a/ecmascript/object_factory.cpp +++ b/ecmascript/object_factory.cpp @@ -45,6 +45,10 @@ #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list.h" @@ -124,6 +128,7 @@ using Error = builtins::BuiltinsError; using RangeError = builtins::BuiltinsRangeError; using ReferenceError = builtins::BuiltinsReferenceError; using TypeError = builtins::BuiltinsTypeError; +using AggregateError = builtins::BuiltinsAggregateError; using URIError = builtins::BuiltinsURIError; using SyntaxError = builtins::BuiltinsSyntaxError; using EvalError = builtins::BuiltinsEvalError; @@ -209,7 +214,14 @@ void * ObjectFactory::InternalMethodTable[] = { reinterpret_cast(builtins::BuiltinsPromiseHandler::ResolveElementFunction), reinterpret_cast(builtins::BuiltinsPromiseHandler::Resolve), reinterpret_cast(builtins::BuiltinsPromiseHandler::Reject), - reinterpret_cast(builtins::BuiltinsPromiseHandler::Executor) + reinterpret_cast(builtins::BuiltinsPromiseHandler::Executor), + reinterpret_cast(builtins::BuiltinsPromiseHandler::AnyRejectElementFunction), + reinterpret_cast(builtins::BuiltinsPromiseHandler::AllSettledResolveElementFunction), + reinterpret_cast(builtins::BuiltinsPromiseHandler::AllSettledRejectElementFunction), + reinterpret_cast(builtins::BuiltinsPromiseHandler::ThenFinally), + reinterpret_cast(builtins::BuiltinsPromiseHandler::CatchFinally), + reinterpret_cast(builtins::BuiltinsPromiseHandler::valueThunkFunction), + reinterpret_cast(builtins::BuiltinsPromiseHandler::throwerFunction) }; void ObjectFactory::GenerateInternalNativeMethods() @@ -240,6 +252,17 @@ JSHandle ObjectFactory::NewEcmaDynClass(JSHClass *hclass, uint32_t siz return JSHandle(thread_, newClass); } +JSHandle ObjectFactory::NewEcmaReadOnlyDynClass(JSHClass *hclass, uint32_t size, JSType type, + uint32_t inlinedProps) +{ + NewObjectHook(); + uint32_t classSize = JSHClass::SIZE; + auto *newClass = static_cast(heap_->AllocateReadOnlyOrHugeObject(hclass, classSize)); + newClass->Initialize(thread_, size, type, inlinedProps); + + return JSHandle(thread_, newClass); +} + JSHandle ObjectFactory::NewEcmaDynClass(uint32_t size, JSType type, uint32_t inlinedProps) { return NewEcmaDynClass(JSHClass::Cast(thread_->GlobalConstants()->GetHClassClass().GetTaggedObject()), @@ -270,7 +293,7 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle &array, i auto *pointer = JSNativePointer::Cast(data.GetTaggedObject()); auto newData = vm_->GetNativeAreaAllocator()->AllocateBuffer(length * sizeof(uint8_t)); if (memset_s(newData, length, 0, length) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } pointer->ResetExternalPointer(newData); @@ -279,7 +302,7 @@ void ObjectFactory::NewJSArrayBufferData(const JSHandle &array, i auto newData = vm_->GetNativeAreaAllocator()->AllocateBuffer(length * sizeof(uint8_t)); if (memset_s(newData, length, 0, length) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } JSHandle pointer = NewJSNativePointer(newData, NativeAreaAllocator::FreeBufferFunc, @@ -295,7 +318,7 @@ void ObjectFactory::NewJSSharedArrayBufferData(const JSHandle &ar void *newData = nullptr; JSSharedMemoryManager::GetInstance()->CreateOrLoad(&newData, length); if (memset_s(newData, length, 0, length) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } JSHandle pointer = NewJSNativePointer(newData, JSSharedMemoryManager::RemoveSharedMemory, @@ -314,7 +337,7 @@ JSHandle ObjectFactory::NewJSArrayBuffer(int32_t length) if (length > 0) { auto newData = vm_->GetNativeAreaAllocator()->AllocateBuffer(length); if (memset_s(newData, length, 0, length) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } JSHandle pointer = NewJSNativePointer(newData, NativeAreaAllocator::FreeBufferFunc, @@ -403,7 +426,7 @@ void ObjectFactory::NewJSRegExpByteCodeData(const JSHandle ®exp, vo auto newBuffer = vm_->GetNativeAreaAllocator()->AllocateBuffer(size); if (memcpy_s(newBuffer, size, buffer, size) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } JSTaggedValue data = regexp->GetByteCodeBuffer(); @@ -582,6 +605,7 @@ JSHandle ObjectFactory::CloneJSFuction(JSHandle obj, Fun JSTaggedValue length = obj->GetPropertyInlinedProps(JSFunction::LENGTH_INLINE_PROPERTY_INDEX); cloneFunc->SetPropertyInlinedProps(thread_, JSFunction::LENGTH_INLINE_PROPERTY_INDEX, length); cloneFunc->SetModule(obj->GetModule()); + cloneFunc->SetCodeEntry(obj->GetCodeEntry()); return cloneFunc; } @@ -781,7 +805,6 @@ JSHandle ObjectFactory::NewJSArguments() JSHandle env = vm_->GetGlobalEnv(); JSHandle dynclass = JSHandle::Cast(env->GetArgumentsClass()); JSHandle obj = JSHandle::Cast(NewJSObject(dynclass)); - obj->SetParameterMap(thread_, JSTaggedValue::Undefined()); return obj; } @@ -847,14 +870,22 @@ JSHandle ObjectFactory::NewJSError(const ErrorType &errorType, const J JSHandle nativePrototype(thread_, nativeFunc->GetFunctionPrototype()); JSHandle ctorKey = globalConst->GetHandledConstructorString(); JSHandle undefined = thread_->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread_, undefined, nativePrototype, undefined, 1); - info.SetCallArg(message.GetTaggedValue()); - JSTaggedValue obj = JSFunction::Invoke(&info, ctorKey); + info->SetCallArg(message.GetTaggedValue()); + JSTaggedValue obj = JSFunction::Invoke(info, ctorKey); JSHandle handleNativeInstanceObj(thread_, obj); return handleNativeInstanceObj; } +JSHandle ObjectFactory::NewJSAggregateError() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle constructor(env->GetAggregateErrorFunction()); + JSHandle newTarget(constructor); + return NewJSObjectByConstructor(constructor, newTarget); +} + JSHandle ObjectFactory::NewJSObjectByConstructor(const JSHandle &constructor, const JSHandle &newTarget) { @@ -888,6 +919,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa case JSType::JS_RANGE_ERROR: case JSType::JS_REFERENCE_ERROR: case JSType::JS_TYPE_ERROR: + case JSType::JS_AGGREGATE_ERROR: case JSType::JS_URI_ERROR: case JSType::JS_SYNTAX_ERROR: case JSType::JS_ITERATOR: { @@ -1024,6 +1056,7 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSRegExp::Cast(*obj)->SetByteCodeBuffer(thread_, JSTaggedValue::Undefined()); JSRegExp::Cast(*obj)->SetOriginalSource(thread_, JSTaggedValue::Undefined()); JSRegExp::Cast(*obj)->SetOriginalFlags(thread_, JSTaggedValue(0)); + JSRegExp::Cast(*obj)->SetGroupName(thread_, JSTaggedValue::Undefined()); JSRegExp::Cast(*obj)->SetLength(0); break; case JSType::JS_PRIMITIVE_REF: @@ -1112,6 +1145,17 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSAPIDeque::Cast(*obj)->SetFirst(0); JSAPIDeque::Cast(*obj)->SetLast(0); break; + case JSType::JS_API_LIGHT_WEIGHT_MAP: + JSAPILightWeightMap::Cast(*obj)->SetLength(0); + JSAPILightWeightMap::Cast(*obj)->SetHashes(thread_, JSTaggedValue::Undefined()); + JSAPILightWeightMap::Cast(*obj)->SetKeys(thread_, JSTaggedValue::Undefined()); + JSAPILightWeightMap::Cast(*obj)->SetValues(thread_, JSTaggedValue::Undefined()); + break; + case JSType::JS_API_LIGHT_WEIGHT_SET: + JSAPILightWeightSet::Cast(*obj)->SetLength(0); + JSAPILightWeightSet::Cast(*obj)->SetHashes(thread_, JSTaggedValue::Undefined()); + JSAPILightWeightSet::Cast(*obj)->SetValues(thread_, JSTaggedValue::Undefined()); + break; case JSType::JS_API_VECTOR: JSAPIVector::Cast(*obj)->SetLength(0); break; @@ -1151,6 +1195,31 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSPromiseAllResolveElementFunction::Cast(*obj)->SetRemainingElements(JSTaggedValue::Undefined()); JSPromiseAllResolveElementFunction::Cast(*obj)->SetAlreadyCalled(JSTaggedValue::Undefined()); break; + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseAnyRejectElementFunction::Cast(*obj)->SetIndex(0); + JSPromiseAnyRejectElementFunction::Cast(*obj)->SetErrors(JSTaggedValue::Undefined()); + JSPromiseAnyRejectElementFunction::Cast(*obj)->SetCapability(JSTaggedValue::Undefined()); + JSPromiseAnyRejectElementFunction::Cast(*obj)->SetRemainingElements(JSTaggedValue::Undefined()); + JSPromiseAnyRejectElementFunction::Cast(*obj)->SetAlreadyCalled(JSTaggedValue::Undefined()); + break; + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseAllSettledElementFunction::Cast(*obj)->SetIndex(0); + JSPromiseAllSettledElementFunction::Cast(*obj)->SetValues(JSTaggedValue::Undefined()); + JSPromiseAllSettledElementFunction::Cast(*obj)->SetCapability(JSTaggedValue::Undefined()); + JSPromiseAllSettledElementFunction::Cast(*obj)->SetRemainingElements(JSTaggedValue::Undefined()); + JSPromiseAllSettledElementFunction::Cast(*obj)->SetAlreadyCalled(JSTaggedValue::Undefined()); + break; + case JSType::JS_PROMISE_FINALLY_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseFinallyFunction::Cast(*obj)->SetOnFinally(JSTaggedValue::Undefined()); + JSPromiseFinallyFunction::Cast(*obj)->SetConstructor(JSTaggedValue::Undefined()); + break; + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: + JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); + JSPromiseValueThunkOrThrowerFunction::Cast(*obj)->SetResult(JSTaggedValue::Undefined()); + break; case JSType::JS_INTL_BOUND_FUNCTION: JSFunction::InitializeJSFunction(thread_, JSHandle(obj), FunctionKind::NORMAL_FUNCTION); JSIntlBoundFunction::Cast(*obj)->SetNumberFormat(JSTaggedValue::Undefined()); @@ -1163,7 +1232,6 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa JSBoundFunction::Cast(*obj)->SetBoundArguments(JSTaggedValue::Undefined()); break; case JSType::JS_ARGUMENTS: - JSArguments::Cast(*obj)->SetParameterMap(JSTaggedValue::Undefined()); break; case JSType::JS_FORIN_ITERATOR: case JSType::JS_MAP_ITERATOR: @@ -1174,23 +1242,26 @@ void ObjectFactory::InitializeJSObject(const JSHandle &obj, const JSHa case JSType::JS_API_TREESET_ITERATOR: case JSType::JS_API_QUEUE_ITERATOR: case JSType::JS_API_DEQUE_ITERATOR: + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: case JSType::JS_API_STACK_ITERATOR: + case JSType::JS_API_VECTOR_ITERATOR: case JSType::JS_ARRAY_ITERATOR: case JSType::JS_API_PLAIN_ARRAY_ITERATOR: break; case JSType::JS_CJS_MODULE: - JSCjsModule::Cast(*obj)->SetId(thread_, JSTaggedValue::Undefined()); - JSCjsModule::Cast(*obj)->SetExports(thread_, JSTaggedValue::Undefined()); - JSCjsModule::Cast(*obj)->SetPath(thread_, JSTaggedValue::Undefined()); - JSCjsModule::Cast(*obj)->SetFilename(thread_, JSTaggedValue::Undefined()); - JSCjsModule::Cast(*obj)->SetStatus(CjsModuleStatus::UNLOAD); + CjsModule::Cast(*obj)->SetId(thread_, JSTaggedValue::Undefined()); + CjsModule::Cast(*obj)->SetExports(thread_, JSTaggedValue::Undefined()); + CjsModule::Cast(*obj)->SetPath(thread_, JSTaggedValue::Undefined()); + CjsModule::Cast(*obj)->SetFilename(thread_, JSTaggedValue::Undefined()); + CjsModule::Cast(*obj)->SetStatus(CjsModuleStatus::UNLOAD); break; case JSType::JS_CJS_EXPORTS: - JSCjsExports::Cast(*obj)->SetExports(thread_, JSTaggedValue::Undefined()); + CjsExports::Cast(*obj)->SetExports(thread_, JSTaggedValue::Undefined()); break; case JSType::JS_CJS_REQUIRE: - JSCjsRequire::Cast(*obj)->SetCache(thread_, JSTaggedValue::Undefined()); - JSCjsRequire::Cast(*obj)->SetParent(thread_, JSTaggedValue::Undefined()); + CjsRequire::Cast(*obj)->SetCache(thread_, JSTaggedValue::Undefined()); + CjsRequire::Cast(*obj)->SetParent(thread_, JSTaggedValue::Undefined()); break; default: UNREACHABLE(); @@ -1257,7 +1328,8 @@ void ObjectFactory::InitializeExtraProperties(const JSHandle &dynclass { ASSERT(inobjPropCount * JSTaggedValue::TaggedTypeSize() < dynclass->GetObjectSize()); auto paddr = reinterpret_cast(obj) + dynclass->GetObjectSize(); - JSTaggedType initVal = JSTaggedValue::Undefined().GetRawData(); + JSTaggedType initVal = dynclass->IsTSType() ? JSTaggedValue::VALUE_HOLE + : JSTaggedValue::VALUE_UNDEFINED; for (int i = 0; i < inobjPropCount; ++i) { paddr -= JSTaggedValue::TaggedTypeSize(); *reinterpret_cast(paddr) = initVal; @@ -1817,6 +1889,12 @@ JSHandle ObjectFactory::NewPendingJob(const JSHandle obj(thread_, header); obj->SetJob(thread_, func.GetTaggedValue()); obj->SetArguments(thread_, argv.GetTaggedValue()); +#if defined(ENABLE_HITRACE) + obj->SetChainId(0); + obj->SetSpanId(0); + obj->SetParentSpanId(0); + obj->SetFlags(0); +#endif return obj; } @@ -1878,7 +1956,7 @@ JSHandle ObjectFactory::NewJSRealm() JSHandle ObjectFactory::NewEmptyArray() { NewObjectHook(); - auto header = heap_->AllocateNonMovableOrHugeObject( + auto header = heap_->AllocateReadOnlyOrHugeObject( JSHClass::Cast(thread_->GlobalConstants()->GetArrayClass().GetTaggedObject()), TaggedArray::SIZE); JSHandle array(thread_, header); array->SetLength(0); @@ -2103,37 +2181,37 @@ JSHandle ObjectFactory::NewModuleNamespace() return moduleNamespace; } -JSHandle ObjectFactory::NewCjsModule() +JSHandle ObjectFactory::NewCjsModule() { NewObjectHook(); JSHandle env = vm_->GetGlobalEnv(); JSHandle moduleObj(env->GetCjsModuleFunction()); - JSHandle cjsModule = - JSHandle(NewJSObjectByConstructor(JSHandle(moduleObj), moduleObj)); + JSHandle cjsModule = + JSHandle(NewJSObjectByConstructor(JSHandle(moduleObj), moduleObj)); return cjsModule; } -JSHandle ObjectFactory::NewCjsExports() +JSHandle ObjectFactory::NewCjsExports() { NewObjectHook(); JSHandle env = vm_->GetGlobalEnv(); JSHandle exportsObj(env->GetCjsExportsFunction()); - JSHandle cjsExports = - JSHandle(NewJSObjectByConstructor(JSHandle(exportsObj), exportsObj)); + JSHandle cjsExports = + JSHandle(NewJSObjectByConstructor(JSHandle(exportsObj), exportsObj)); return cjsExports; } -JSHandle ObjectFactory::NewCjsRequire() +JSHandle ObjectFactory::NewCjsRequire() { NewObjectHook(); JSHandle env = vm_->GetGlobalEnv(); JSHandle requireObj(env->GetCjsRequireFunction()); - JSHandle cjsRequire = - JSHandle(NewJSObjectByConstructor(JSHandle(requireObj), requireObj)); - + JSHandle cjsRequire = + JSHandle(NewJSObjectByConstructor(JSHandle(requireObj), requireObj)); + return cjsRequire; } @@ -2252,15 +2330,18 @@ JSHandle ObjectFactory::NewProfileTypeInfo(uint32_t length) return array; } -JSHandle ObjectFactory::NewBigInt() +JSHandle ObjectFactory::NewBigInt(uint32_t length) { NewObjectHook(); - TaggedObject *header = heap_->AllocateYoungOrHugeObject( - JSHClass::Cast(thread_->GlobalConstants()->GetBigIntClass().GetTaggedObject())); - JSHandle obj(thread_, BigInt::Cast(header)); - obj->SetData(thread_, JSTaggedValue::Undefined()); - obj->SetSign(false); - return obj; + ASSERT(length > 0); + size_t size = BigInt::ComputeSize(length); + auto header = heap_->AllocateYoungOrHugeObject( + JSHClass::Cast(thread_->GlobalConstants()->GetBigIntClass().GetTaggedObject()), size); + JSHandle bigint(thread_, header); + bigint->SetLength(length); + bigint->SetSign(false); + bigint->InitializationZero(); + return bigint; } // static @@ -2408,6 +2489,111 @@ JSHandle ObjectFactory::NewJSPromiseAllResol return function; } +JSHandle ObjectFactory::NewJSPromiseAnyRejectElementFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseAnyRejectElementFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_ANY_REJECT_ELEMENT_FUNCTION)); + function->SetIndex(0); + function->SetErrors(JSTaggedValue::Undefined()); + function->SetCapability(JSTaggedValue::Undefined()); + function->SetRemainingElements(JSTaggedValue::Undefined()); + function->SetAlreadyCalled(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); + return function; +} + +JSHandle ObjectFactory::NewJSPromiseAllSettledResolveElementFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseAllSettledElementFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_ALL_SETTLED_RESOLVE_ELEMENT_FUNCTION)); + function->SetIndex(0); + function->SetValues(JSTaggedValue::Undefined()); + function->SetCapability(JSTaggedValue::Undefined()); + function->SetRemainingElements(JSTaggedValue::Undefined()); + function->SetAlreadyCalled(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); + return function; +} + +JSHandle ObjectFactory::NewJSPromiseAllSettledRejectElementFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseAllSettledElementFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_ALL_SETTLED_REJECT_ELEMENT_FUNCTION)); + function->SetIndex(0); + function->SetValues(JSTaggedValue::Undefined()); + function->SetCapability(JSTaggedValue::Undefined()); + function->SetRemainingElements(JSTaggedValue::Undefined()); + function->SetAlreadyCalled(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); + return function; +} + +JSHandle ObjectFactory::NewJSPromiseThenFinallyFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseFinallyFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_THEN_FINALLY_FUNCTION)); + function->SetConstructor(JSTaggedValue::Undefined()); + function->SetOnFinally(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); + return function; +} + +JSHandle ObjectFactory::NewJSPromiseCatchFinallyFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseFinallyFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_CATCH_FINALLY_FUNCTION)); + function->SetConstructor(JSTaggedValue::Undefined()); + function->SetOnFinally(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(1)); + return function; +} + +JSHandle ObjectFactory::NewJSPromiseValueThunkFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseValueThunkOrThrowerFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_VALUE_THUNK_FUNCTION)); + function->SetResult(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(0)); + return function; +} + +JSHandle ObjectFactory::NewJSPromiseThrowerFunction() +{ + JSHandle env = vm_->GetGlobalEnv(); + JSHandle dynclass = JSHandle::Cast(env->GetPromiseValueThunkOrThrowerFunctionClass()); + JSHandle function = + JSHandle::Cast(NewJSObject(dynclass)); + JSFunction::InitializeJSFunction(thread_, JSHandle::Cast(function)); + function->SetMethod(GetMethodByIndex(MethodIndex::BUILTINS_PROMISE_HANDLER_THROWER_FUNCTION)); + function->SetResult(JSTaggedValue::Undefined()); + JSFunction::SetFunctionLength(thread_, JSHandle::Cast(function), JSTaggedValue(0)); + return function; +} + EcmaString *ObjectFactory::InternString(const JSHandle &key) { EcmaString *str = EcmaString::Cast(key->GetTaggedObject()); @@ -2586,7 +2772,7 @@ JSHandle ObjectFactory::NewMachineCodeObject(size_t length, const u thread_->GlobalConstants()->GetMachineCodeClass().GetTaggedObject()), length + MachineCode::SIZE); MachineCode *code = MachineCode::Cast(obj); if (code == nullptr) { - LOG_ECMA(FATAL) << "machine code cast failed"; + LOG_FULL(FATAL) << "machine code cast failed"; UNREACHABLE(); } code->SetInstructionSizeInBytes(static_cast(length)); @@ -2654,7 +2840,8 @@ JSHandle ObjectFactory::NewTSClassType() classType->SetInstanceType(thread_, JSTaggedValue::Undefined()); classType->SetConstructorType(thread_, JSTaggedValue::Undefined()); classType->SetPrototypeType(thread_, JSTaggedValue::Undefined()); - classType->SetExtensionType(thread_, JSTaggedValue::Undefined()); + classType->SetExtensionGTRawData(0); + classType->SetHasLinked(false); return classType; } @@ -2914,7 +3101,41 @@ JSHandle ObjectFactory::NewJSAPIArrayListIterator(const return iter; } -JSHandle ObjectFactory::NewJSAPIPlainArray(array_size_t capacity) +JSHandle ObjectFactory::NewJSAPILightWeightMapIterator(const + JSHandle &obj, + IterationKind kind) +{ + NewObjectHook(); + JSHandle protoValue(thread_, thread_->GlobalConstants()->GetLightWeightMapIteratorPrototype()); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle dynHandle(globalConst->GetHandledJSAPILightWeightMapIteratorClass()); + dynHandle->SetPrototype(thread_, protoValue); + JSHandle iter(NewJSObject(dynHandle)); + iter->GetJSHClass()->SetExtensible(true); + iter->SetIteratedLightWeightMap(thread_, obj); + iter->SetNextIndex(0); + iter->SetIterationKind(kind); + return iter; +} + +JSHandle ObjectFactory::NewJSAPILightWeightSetIterator(const + JSHandle &obj, + IterationKind kind) +{ + NewObjectHook(); + JSHandle protoValue(thread_, thread_->GlobalConstants()->GetLightWeightSetIteratorPrototype()); + const GlobalEnvConstants *globalConst = thread_->GlobalConstants(); + JSHandle dynHandle(globalConst->GetHandledJSAPILightWeightSetIteratorClass()); + dynHandle->SetPrototype(thread_, protoValue); + JSHandle iter(NewJSObject(dynHandle)); + iter->GetJSHClass()->SetExtensible(true); + iter->SetIteratedLightWeightSet(thread_, obj); + iter->SetNextIndex(0); + iter->SetIterationKind(kind); + return iter; +} + +JSHandle ObjectFactory::NewJSAPIPlainArray(uint32_t capacity) { NewObjectHook(); JSHandle builtinObj(thread_, thread_->GlobalConstants()->GetPlainArrayFunction()); diff --git a/ecmascript/object_factory.h b/ecmascript/object_factory.h index 9cc5f185c29c71b88d0ca33f9f234fe784960b9c..9b1f2358abb8eef221245ea1f0bde1c8a9fafce3 100644 --- a/ecmascript/object_factory.h +++ b/ecmascript/object_factory.h @@ -71,6 +71,10 @@ class JSPromise; class JSPromiseReactionsFunction; class JSPromiseExecutorFunction; class JSPromiseAllResolveElementFunction; +class JSPromiseAnyRejectElementFunction; +class JSPromiseAllSettledElementFunction; +class JSPromiseFinallyFunction; +class JSPromiseValueThunkOrThrowerFunction; class PromiseReaction; class PromiseCapability; class PromiseIteratorRecord; @@ -104,6 +108,10 @@ class JSAPIArrayList; class JSAPIArrayListIterator; class JSAPIDeque; class JSAPIDequeIterator; +class JSAPILightWeightMap; +class JSAPILightWeightMapIterator; +class JSAPILightWeightSet; +class JSAPILightWeightSetIterator; class JSAPIQueue; class JSAPIQueueIterator; class JSAPIStack; @@ -122,9 +130,9 @@ class ModuleNamespace; class ImportEntry; class ExportEntry; class SourceTextModule; -class JSCjsModule; -class JSCjsRequire; -class JSCjsExports; +class CjsModule; +class CjsRequire; +class CjsExports; class ResolvedBinding; class BigInt; class CellRecord; @@ -164,6 +172,13 @@ enum class MethodIndex : uint8_t { BUILTINS_PROMISE_HANDLER_RESOLVE, BUILTINS_PROMISE_HANDLER_REJECT, BUILTINS_PROMISE_HANDLER_EXECUTOR, + BUILTINS_PROMISE_HANDLER_ANY_REJECT_ELEMENT_FUNCTION, + BUILTINS_PROMISE_HANDLER_ALL_SETTLED_RESOLVE_ELEMENT_FUNCTION, + BUILTINS_PROMISE_HANDLER_ALL_SETTLED_REJECT_ELEMENT_FUNCTION, + BUILTINS_PROMISE_HANDLER_THEN_FINALLY_FUNCTION, + BUILTINS_PROMISE_HANDLER_CATCH_FINALLY_FUNCTION, + BUILTINS_PROMISE_HANDLER_VALUE_THUNK_FUNCTION, + BUILTINS_PROMISE_HANDLER_THROWER_FUNCTION, METHOD_END }; @@ -184,6 +199,8 @@ public: JSHandle NewJSError(const ErrorType &errorType, const JSHandle &message); + JSHandle NewJSAggregateError(); + JSHandle NewTransitionHandler(); JSHandle NewPrototypeHandler(); @@ -295,7 +312,7 @@ public: JSHandle NewProtoChangeMarker(); JSHandle NewProtoChangeDetails(); - JSHandle NewBigInt(); + JSHandle NewBigInt(uint32_t length); // use for copy properties keys's array to another array JSHandle ExtendArray(const JSHandle &old, uint32_t length, JSTaggedValue initVal = JSTaggedValue::Hole()); @@ -351,6 +368,20 @@ public: JSHandle NewJSPromiseAllResolveElementFunction(); + JSHandle NewJSPromiseAnyRejectElementFunction(); + + JSHandle NewJSPromiseAllSettledResolveElementFunction(); + + JSHandle NewJSPromiseAllSettledRejectElementFunction(); + + JSHandle NewJSPromiseThenFinallyFunction(); + + JSHandle NewJSPromiseCatchFinallyFunction(); + + JSHandle NewJSPromiseValueThunkFunction(); + + JSHandle NewJSPromiseThrowerFunction(); + JSHandle CloneObjectLiteral(JSHandle object, const JSHandle &env, const JSHandle &constpool, bool canShareHClass = true); JSHandle CloneObjectLiteral(JSHandle object); @@ -447,10 +478,15 @@ public: JSHandle NewEcmaDynClass(uint32_t size, JSType type, const JSHandle &prototype); // It is used to provide iterators for non ECMA standard jsapi containers. - JSHandle NewJSAPIPlainArray(array_size_t capacity); + JSHandle NewJSAPIPlainArray(uint32_t capacity); JSHandle NewJSAPIPlainArrayIterator(const JSHandle &plainarray, IterationKind kind); JSHandle NewJSAPIArrayList(uint32_t capacity); + + JSHandle NewJSAPILightWeightMapIterator(const JSHandle &obj, + IterationKind kind); + JSHandle NewJSAPILightWeightSetIterator(const JSHandle &obj, + IterationKind kind); JSHandle CopyQueue(const JSHandle &old, uint32_t newLength, uint32_t front, uint32_t tail); JSHandle NewJSAPIQueueIterator(const JSHandle &queue); @@ -485,9 +521,9 @@ public: JSHandle NewCellRecord(); // --------------------------------------require-------------------------------------------- - JSHandle NewCjsModule(); - JSHandle NewCjsExports(); - JSHandle NewCjsRequire(); + JSHandle NewCjsModule(); + JSHandle NewCjsExports(); + JSHandle NewCjsRequire(); private: friend class GlobalEnv; @@ -520,6 +556,8 @@ private: JSHandle NewEcmaDynClassClass(JSHClass *hclass, uint32_t size, JSType type); JSHandle NewEcmaDynClass(JSHClass *hclass, uint32_t size, JSType type, uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); + JSHandle NewEcmaReadOnlyDynClass(JSHClass *hclass, uint32_t size, JSType type, + uint32_t inlinedProps = JSHClass::DEFAULT_CAPACITY_OF_IN_OBJECTS); JSHandle InitClassClass(); // used to create nonmovable js_object @@ -530,6 +568,7 @@ private: // used for creating Function JSHandle NewJSFunction(const JSHandle &env, const JSHandle &dynKlass); + JSHandle CreateObjectClass(const JSHandle &keys, const JSHandle &values); JSHandle CreateObjectClass(const JSHandle &properties, size_t length); JSHandle CreateFunctionClass(FunctionKind kind, uint32_t size, JSType type, const JSHandle &prototype); diff --git a/ecmascript/object_operator.cpp b/ecmascript/object_operator.cpp index a4e3d6ae2954a359841b964a876677b1d2e18f4b..921488642701bbd6adc3a91116343586deb431cf 100644 --- a/ecmascript/object_operator.cpp +++ b/ecmascript/object_operator.cpp @@ -215,7 +215,7 @@ void ObjectOperator::ToPropertyDescriptor(PropertyDescriptor &desc) const result = PropertyBox::Cast(result.GetTaggedObject())->GetValue(); } AccessorData *accessor = AccessorData::Cast(result.GetTaggedObject()); - + if (UNLIKELY(accessor->IsInternal())) { desc.SetWritable(IsWritable()); auto val = accessor->CallInternalGet(thread_, JSHandle::Cast(GetHolder())); @@ -332,6 +332,9 @@ void ObjectOperator::LookupPropertyInlinedProps(const JSHandle &obj) JSTaggedValue value; if (attr.IsInlinedProps()) { value = obj->GetPropertyInlinedProps(entry); + if (value.IsHole()) { // properties from ts type are all inlined + return; + } } else { entry -= static_cast(jshclass->GetInlinedProperties()); value = array->Get(entry); @@ -392,7 +395,7 @@ void ObjectOperator::TransitionForAttributeChanged(const JSHandle &rec bool ObjectOperator::UpdateValueAndDetails(const JSHandle &receiver, const JSHandle &value, PropertyAttributes attr, bool attrChanged) { - bool isInternalAccessor = IsAccessorDescriptor() && AccessorData::Cast(GetValue().GetHeapObject())->IsInternal(); + bool isInternalAccessor = IsAccessorDescriptor() && AccessorData::Cast(GetValue().GetTaggedObject())->IsInternal(); if (attrChanged) { TransitionForAttributeChanged(receiver, attr); } @@ -423,7 +426,7 @@ bool ObjectOperator::UpdateDataValue(const JSHandle &receiver, const J } if (isInternalAccessor) { - auto accessor = AccessorData::Cast(GetValue().GetHeapObject()); + auto accessor = AccessorData::Cast(GetValue().GetTaggedObject()); if (accessor->HasSetter()) { return accessor->CallInternalSet(thread_, JSHandle(receiver), value, mayThrow); } @@ -471,7 +474,7 @@ bool ObjectOperator::WriteDataProperty(const JSHandle &receiver, const } if (IsAccessorDescriptor()) { - auto accessor = AccessorData::Cast(GetValue().GetHeapObject()); + auto accessor = AccessorData::Cast(GetValue().GetTaggedObject()); if (!accessor->IsInternal() || !accessor->HasSetter()) { attr.SetIsAccessor(false); attrChanged = true; diff --git a/ecmascript/regexp/regexp_executor.cpp b/ecmascript/regexp/regexp_executor.cpp index aec901aa4fe73281086cdaa873f9a0ebecab5d76..a681a6fd53545222aec22a3252eec1f285a77ee6 100644 --- a/ecmascript/regexp/regexp_executor.cpp +++ b/ecmascript/regexp/regexp_executor.cpp @@ -43,14 +43,14 @@ bool RegExpExecutor::Execute(const uint8_t *input, uint32_t lastIndex, uint32_t if (captureResultSize != 0) { captureResultList_ = chunk_->NewArray(nCapture_); if (memset_s(captureResultList_, captureResultSize, 0, captureResultSize) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } } if (stackSize != 0) { stack_ = chunk_->NewArray(nStack_); if (memset_s(stack_, stackSize, 0, stackSize) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } } @@ -264,7 +264,7 @@ MatchResult RegExpExecutor::GetResult(const JSThread *thread, bool isSuccess) co uint8_t *dest = buffer.data(); if (memcpy_s(dest, len + 1, reinterpret_cast(captureState->captureStart), len) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } dest[len] = '\0'; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) @@ -298,7 +298,7 @@ void RegExpExecutor::PushRegExpState(StateType type, uint32_t pc) state->currentPtr_ = GetCurrentPtr(); size_t listSize = sizeof(CaptureState) * nCapture_; if (memcpy_s(state->captureResultList_, listSize, GetCaptureResultList(), listSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } uint8_t *stackStart = @@ -307,7 +307,7 @@ void RegExpExecutor::PushRegExpState(StateType type, uint32_t pc) if (stack_ != nullptr) { size_t stackSize = sizeof(uintptr_t) * nStack_; if (memcpy_s(stackStart, stackSize, stack_, stackSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -321,7 +321,7 @@ RegExpState *RegExpExecutor::PopRegExpState(bool copyCaptrue) size_t listSize = sizeof(CaptureState) * nCapture_; if (copyCaptrue) { if (memcpy_s(GetCaptureResultList(), listSize, state->captureResultList_, listSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -333,7 +333,7 @@ RegExpState *RegExpExecutor::PopRegExpState(bool copyCaptrue) if (stack_ != nullptr) { size_t stackSize = sizeof(uintptr_t) * nStack_; if (memcpy_s(stack_, stackSize, stackStart, stackSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -350,7 +350,7 @@ void RegExpExecutor::ReAllocStack(uint32_t stackLen) uint32_t stackByteSize = newStackSize * stateSize_; auto newStack = chunk_->NewArray(stackByteSize); if (memset_s(newStack, stackByteSize, 0, stackByteSize) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; + LOG_FULL(FATAL) << "memset_s failed"; UNREACHABLE(); } if (stateStack_ != nullptr) { diff --git a/ecmascript/regexp/regexp_opcode.h b/ecmascript/regexp/regexp_opcode.h index 9fdc5aa102748ecc9fc9efb486e4200e181e10d0..a9c8500daa5acb96b06ade773eeec073edbe6eaf 100644 --- a/ecmascript/regexp/regexp_opcode.h +++ b/ecmascript/regexp/regexp_opcode.h @@ -344,7 +344,6 @@ public: } return false; } - inline uint32_t HighestValue() const { if (!rangeSet_.empty()) { @@ -352,7 +351,6 @@ public: } return 0; } - RangeSet(RangeSet const &) = default; RangeSet &operator=(RangeSet const &) = default; RangeSet(RangeSet &&) = default; diff --git a/ecmascript/regexp/regexp_parser.cpp b/ecmascript/regexp/regexp_parser.cpp index c5bfdd596d840c220a57017d9abf0ff74c3f9d86..26073c2d199c9155d140a86790f3bda8d289159f 100644 --- a/ecmascript/regexp/regexp_parser.cpp +++ b/ecmascript/regexp/regexp_parser.cpp @@ -21,10 +21,15 @@ #include "libpandabase/utils/utils.h" #include "securec.h" #include "unicode/uniset.h" - +#include "third_party/icu/icu4c/source/common/unicode/uchar.h" #define _NO_DEBUG_ namespace panda::ecmascript { +static constexpr uint32_t CACHE_SIZE = 128; +static constexpr uint32_t ID_START_TABLE_ASCII[4] = { + /* $ A-Z _ a-z */ + 0x00000000, 0x00000010, 0x87FFFFFE, 0x07FFFFFE +}; static RangeSet g_rangeD(0x30, 0x39); // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) // NOLINTNEXTLINE(fuchsia-statically-constructed-objects) static RangeSet g_rangeS({ @@ -151,7 +156,7 @@ bool RegExpParser::ParseUnlimitedLengthHexNumber(uint32_t maxValue, uint32_t *va } while (d >= 0) { if (UNLIKELY(x > (std::numeric_limits::max() - static_cast(d)) / HEX_VALUE)) { - LOG_ECMA(FATAL) << "value overflow"; + LOG_FULL(FATAL) << "value overflow"; return false; } x = x * HEX_VALUE + static_cast(d); @@ -436,12 +441,12 @@ void RegExpParser::ParseAlternative(bool isBackward) moveSize, buffer_.buf_ + start, // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) moveSize) != EOK) { - LOG_ECMA(FATAL) << "memmove_s failed"; + LOG_FULL(FATAL) << "memmove_s failed"; UNREACHABLE(); } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) if (memcpy_s(buffer_.buf_ + start, termSize, buffer_.buf_ + end, termSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -539,6 +544,7 @@ bool RegExpParser::ParseAssertionCapture(int *captureIndex, bool isBackward) return false; } groupNames_.EmitStr(name.c_str()); + newGroupNames_.push_back(name); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) PrintF("group name %s", name.c_str()); Advance(); @@ -758,24 +764,42 @@ void RegExpParser::ParseQuantifier(size_t atomBcStart, int captureStart, int cap bool RegExpParser::ParseGroupSpecifier(const uint8_t **pp, CString &name) { const uint8_t *p = *pp; - int c = *p; - while (c != '>') { - if (c < (INT8_MAX + 1)) { - if (name.empty()) { - if (!g_regexpIdentifyStart.IsContain(c)) { - return false; - } - } else { - if (!g_regexpIdentifyContinue.IsContain(c)) { - return false; - } + uint32_t c; + char buffer[CACHE_SIZE] = {0}; + char *q = buffer; + while (true) { + c = *p; + if (c == '\\') { + p++; + if (*p != 'u') { + return false; } - name += static_cast(c); + if (!ParseUnicodeEscape(&c)) { + return false; + } + } else if (c == '>') { + break; + } else if (c > CACHE_SIZE) { + c = static_cast(base::StringHelper::UnicodeFromUtf8(p, UTF8_CHAR_LEN_MAX, &p)); + } else { + p++; } - c = *++p; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - } - p++; // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + if (q == buffer) { + if (!IsIdentFirst(c)) { + return false; + } + } else { + if (!u_isIDPart(c)) { + return false; + } + } + if (q != nullptr) { + *q++ = c; + } + } // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + p++; *pp = p; + name = buffer; return true; } @@ -784,6 +808,7 @@ int RegExpParser::ParseCaptureCount(const char *groupName) const uint8_t *p; int captureIndex = 1; CString name; + hasNamedCaptures_ = 0; for (p = base_; p < end_; p++) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) switch (*p) { case '(': { @@ -793,6 +818,7 @@ int RegExpParser::ParseCaptureCount(const char *groupName) // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) p[CAPTURE_CONUT_ADVANCE] != '=') { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + hasNamedCaptures_ = 1; p += CAPTURE_CONUT_ADVANCE; if (groupName != nullptr) { if (ParseGroupSpecifier(&p, name)) { @@ -836,6 +862,7 @@ int RegExpParser::ParseAtomEscape(bool isBackward) int result = -1; // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) PrintF("Parse AtomEscape------\n"); + PrevOpCode prevOp; switch (c0_) { case KEY_EOF: // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) @@ -870,50 +897,108 @@ int RegExpParser::ParseAtomEscape(bool isBackward) case 'd': { // [0-9] RangeOpCode rangeOp; + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } rangeOp.InsertOpCode(&buffer_, g_rangeD); - Advance(); + goto parseLookBehind; } break; case 'D': { // [^0-9] RangeSet atomRange(g_rangeD); atomRange.Invert(IsUtf16()); Range32OpCode rangeOp; + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } rangeOp.InsertOpCode(&buffer_, atomRange); - Advance(); + goto parseLookBehind; } break; case 's': { // [\f\n\r\t\v] RangeOpCode rangeOp; + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } rangeOp.InsertOpCode(&buffer_, g_rangeS); - Advance(); + goto parseLookBehind; } break; case 'S': { RangeSet atomRange(g_rangeS); - atomRange.Invert(IsUtf16()); Range32OpCode rangeOp; + atomRange.Invert(IsUtf16()); + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } rangeOp.InsertOpCode(&buffer_, atomRange); - Advance(); + goto parseLookBehind; } break; case 'w': { // [A-Za-z0-9] RangeOpCode rangeOp; + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } rangeOp.InsertOpCode(&buffer_, g_rangeW); - Advance(); + goto parseLookBehind; } break; case 'W': { // [^A-Za-z0-9] RangeSet atomRange(g_rangeW); atomRange.Invert(IsUtf16()); Range32OpCode rangeOp; + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } rangeOp.InsertOpCode(&buffer_, atomRange); - Advance(); + goto parseLookBehind; } break; // P{UnicodePropertyValueExpression} // p{UnicodePropertyValueExpression} case 'P': case 'p': // [+N]kGroupName[?U] - case 'k': + case 'k': { + Advance(); + if (c0_ != '<') { + if (!IsUtf16() || HasNamedCaptures()) { + ParseError("expecting group name."); + break; + } + } + Advance(); + Prev(); + CString name; + auto **pp = const_cast(&pc_); + if (!ParseGroupSpecifier(pp, name)) { + ParseError("GroupName Syntax error."); + break; + } + int postion = FindGroupName(name); + if (postion < 0) { + postion = ParseCaptureCount(name.c_str()); + if (postion < 0 && (!IsUtf16() || HasNamedCaptures())) { + ParseError("group name not defined"); + break; + } + } + if (isBackward) { + BackwardBackReferenceOpCode backReferenceOp; + backReferenceOp.EmitOpCode(&buffer_, postion); + } else { + BackReferenceOpCode backReferenceOp; + backReferenceOp.EmitOpCode(&buffer_, postion); + } + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg) + Advance(); + } break; + parseLookBehind: { + if (isBackward) { + prevOp.EmitOpCode(&buffer_, 0); + } + Advance(); + break; + } default: result = ParseCharacterEscape(); break; @@ -921,6 +1006,22 @@ int RegExpParser::ParseAtomEscape(bool isBackward) return result; } +int RegExpParser::RecountCaptures() +{ + if (totalCaptureCount_ < 0) { + const char *name = reinterpret_cast(groupNames_.buf_); + totalCaptureCount_ = ParseCaptureCount(name); + } + return totalCaptureCount_; +} +bool RegExpParser::HasNamedCaptures() +{ + if (hasNamedCaptures_ < 0) { + RecountCaptures(); + } + return false; +} + int RegExpParser::ParseCharacterEscape() { // CharacterEscape[U]:: @@ -1105,10 +1206,11 @@ bool RegExpParser::ParseClassRanges(RangeSet *result) result->Insert(s2); continue; } - - if (c1 > c2) { - ParseError("invalid class range"); - return false; + if (c1 < INT8_MAX) { + if (c1 > c2) { + ParseError("invalid class range"); + return false; + } } if (IsIgnoreCase()) { c1 = static_cast(Canonicalize(c1, IsUtf16())); @@ -1296,8 +1398,17 @@ void RegExpParser::ParseError(const char *errorMessage) SetIsError(); size_t length = strlen(errorMessage) + 1; if (memcpy_s(errorMsg_, length, errorMessage, length) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } -} // namespace panda::ecmascript + +int RegExpParser::IsIdentFirst(uint32_t c) +{ + if (c < CACHE_SIZE) { + return (ID_START_TABLE_ASCII[c >> 5] >> (c & 31)) & 1; // 5: Shift five bits 31: and operation binary of 31 + } else { + return static_cast(u_isIDStart(c)); + } +} +} // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/regexp/regexp_parser.h b/ecmascript/regexp/regexp_parser.h index 278c923dae7a296103f10bbda94042dc3ef7441b..31ebb70e4a9fc72d3f65b0757f6e5821611bd6a8 100644 --- a/ecmascript/regexp/regexp_parser.h +++ b/ecmascript/regexp/regexp_parser.h @@ -20,6 +20,7 @@ #include #include #include "ecmascript/mem/chunk.h" +#include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/c_string.h" #include "ecmascript/mem/dyn_chunk.h" #include "ecmascript/regexp/regexp_opcode.h" @@ -28,6 +29,7 @@ #include "unicode/utf16.h" #include "unicode/utf8.h" #include "unicode/utypes.h" +#include "unicode/udata.h" namespace panda::ecmascript { class RegExpParser { @@ -51,6 +53,7 @@ public: static constexpr uint32_t UNICODE_HEX_VALUE = 4; static constexpr uint32_t UNICODE_HEX_ADVANCE = 2; static constexpr uint32_t CAPTURE_CONUT_ADVANCE = 3; + static constexpr uint32_t UTF8_CHAR_LEN_MAX = 6; explicit RegExpParser(Chunk *chunk) : base_(nullptr), @@ -105,7 +108,21 @@ public: bool ParseUnlimitedLengthHexNumber(uint32_t maxValue, uint32_t *value); bool ParseUnicodeEscape(uint32_t *value); bool ParserIntervalQuantifier(int *pmin, int *pmax); + bool HasNamedCaptures(); + int ParseEscape(const uint8_t **pp, int isUtf16); + int RecountCaptures(); + int IsIdentFirst(uint32_t c); + inline CVector GetGroupNames() const + { + return newGroupNames_; + } + + inline size_t GetGroupNamesSize() const + { + return groupNames_.size_ ; + } + inline bool IsError() const { return isError_; @@ -227,8 +244,11 @@ private: int stackCount_; bool isError_; char errorMsg_[TMP_BUF_SIZE] = {0}; // NOLINTNEXTLINE(modernize-avoid-c-arrays) + int hasNamedCaptures_ = -1; + int totalCaptureCount_ = -1; DynChunk buffer_; DynChunk groupNames_; + CVector newGroupNames_; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_REGEXP_PARSER_H diff --git a/ecmascript/regexp/regexp_parser_cache.cpp b/ecmascript/regexp/regexp_parser_cache.cpp index db54a7d590e541f08ff9df310c016c7b28ea056b..0b68035d03324c48053b45cd652f75ad78155822 100644 --- a/ecmascript/regexp/regexp_parser_cache.cpp +++ b/ecmascript/regexp/regexp_parser_cache.cpp @@ -41,18 +41,21 @@ size_t RegExpParserCache::GetHash(EcmaString *pattern, const uint32_t flags) return (pattern->GetHashcode() ^ flags) % CACHE_SIZE; } -std::pair RegExpParserCache::GetCache(EcmaString *pattern, const uint32_t flags) +std::pair RegExpParserCache::GetCache(EcmaString *pattern, const uint32_t flags, + CVector &groupName) { size_t hash = GetHash(pattern, flags); ParserKey &info = info_[hash]; if (info.flags_ != flags || !EcmaString::StringsAreEqual(info.pattern_, pattern)) { return std::pair(JSTaggedValue::Hole(), 0); } + groupName = info.newGroupNames_; return std::pair(info.codeBuffer_, info.bufferSize_); } void RegExpParserCache::SetCache(EcmaString *pattern, const uint32_t flags, - const JSTaggedValue codeBuffer, const size_t bufferSize) + const JSTaggedValue codeBuffer, const size_t bufferSize, + CVector groupName) { size_t hash = GetHash(pattern, flags); ParserKey &info = info_[hash]; @@ -60,5 +63,6 @@ void RegExpParserCache::SetCache(EcmaString *pattern, const uint32_t flags, info.flags_ = flags; info.codeBuffer_ = codeBuffer; info.bufferSize_ = bufferSize; + info.newGroupNames_ = groupName; } } // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/regexp/regexp_parser_cache.h b/ecmascript/regexp/regexp_parser_cache.h index 24490c55fedd70660ea52f8e1d26babb49ce99aa..bdb6d6820c5adac34f1f12d3cb6bf2dad4f6aaf3 100644 --- a/ecmascript/regexp/regexp_parser_cache.h +++ b/ecmascript/regexp/regexp_parser_cache.h @@ -19,6 +19,7 @@ #include #include "ecmascript/ecma_string.h" +#include "ecmascript/mem/c_containers.h" #include "ecmascript/js_tagged_value.h" namespace panda::ecmascript { @@ -29,8 +30,10 @@ public: static constexpr size_t CACHE_SIZE = 128; bool IsInCache(EcmaString *pattern, const uint32_t flags); - std::pair GetCache(EcmaString *pattern, const uint32_t flags); - void SetCache(EcmaString *pattern, const uint32_t flags, const JSTaggedValue codeBuffer, const size_t bufferSize); + std::pair GetCache(EcmaString *pattern, const uint32_t flags, + CVector &groupName); + void SetCache(EcmaString *pattern, const uint32_t flags, const JSTaggedValue codeBuffer, + const size_t bufferSize, CVector groupName); void Clear(); private: @@ -41,6 +44,7 @@ private: uint32_t flags_{UINT32_MAX}; JSTaggedValue codeBuffer_{JSTaggedValue::Hole()}; size_t bufferSize_{0}; + CVector newGroupNames_; }; std::array info_{}; diff --git a/ecmascript/require/js_cjs_exports.h b/ecmascript/require/js_cjs_exports.h index 524080ac22d6c3153a16fec2d8092128071dfed9..b7b5714633918dd2399f425aa747a9fde6a1929a 100644 --- a/ecmascript/require/js_cjs_exports.h +++ b/ecmascript/require/js_cjs_exports.h @@ -20,14 +20,9 @@ #include "ecmascript/js_tagged_value.h" namespace panda::ecmascript { -class JSCjsExports final : public JSObject { +class CjsExports final : public JSObject { public: - CAST_CHECK(JSCjsExports, IsJSCjsExports); - - inline static JSCjsExports *Cast(const TaggedObject *object) - { - return static_cast(const_cast(object)); - } + CAST_CHECK(CjsExports, IsCjsExports); static constexpr size_t JS_CJS_EXPORTS_OFFSET = JSObject::SIZE; ACCESSORS(Exports, JS_CJS_EXPORTS_OFFSET, SIZE) diff --git a/ecmascript/require/js_cjs_module.cpp b/ecmascript/require/js_cjs_module.cpp index 7f5921758a3851d593b2a52e54778ac66826c425..49d6ac8e769761b45751b91f231439700be9dce1 100644 --- a/ecmascript/require/js_cjs_module.cpp +++ b/ecmascript/require/js_cjs_module.cpp @@ -22,8 +22,8 @@ #include "ecmascript/jspandafile/js_pandafile_manager.h" namespace panda::ecmascript { -void JSCjsModule::InitializeModule(JSThread *thread, JSHandle &module, - JSHandle &filename, JSHandle &dirname) +void CjsModule::InitializeModule(JSThread *thread, JSHandle &module, + JSHandle &filename, JSHandle &dirname) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -38,7 +38,7 @@ void JSCjsModule::InitializeModule(JSThread *thread, JSHandle &modu return; } -JSHandle JSCjsModule::SearchFromModuleCache(JSThread *thread, JSHandle &filename) +JSHandle CjsModule::SearchFromModuleCache(JSThread *thread, JSHandle &filename) { [[maybe_unused]] EcmaHandleScope handleScope(thread); JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); @@ -52,7 +52,7 @@ JSHandle JSCjsModule::SearchFromModuleCache(JSThread *thread, JSH JSTaggedValue::Undefined()); JSHandle moduleCache = JSHandle(thread, modCache); if (moduleCache->ContainsModule(filename.GetTaggedValue())) { - JSHandle cachedModule = JSHandle(thread, + JSHandle cachedModule = JSHandle(thread, moduleCache->GetModule(filename.GetTaggedValue())); JSHandle exportsName = globalConst->GetHandledCjsExportsString(); JSTaggedValue cachedExports = SlowRuntimeStub::LdObjByName(thread, cachedModule.GetTaggedValue(), @@ -65,7 +65,7 @@ JSHandle JSCjsModule::SearchFromModuleCache(JSThread *thread, JSH return JSHandle(thread, JSTaggedValue::Hole()); } -void JSCjsModule::PutIntoCache(JSThread *thread, JSHandle &module, JSHandle &filename) +void CjsModule::PutIntoCache(JSThread *thread, JSHandle &module, JSHandle &filename) { JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); @@ -84,7 +84,7 @@ void JSCjsModule::PutIntoCache(JSThread *thread, JSHandle &module, newCache.GetTaggedValue()); } -JSHandle JSCjsModule::Load(JSThread *thread, JSHandle &request) +JSHandle CjsModule::Load(JSThread *thread, JSHandle &request) { [[maybe_unused]] EcmaHandleScope handleScope(thread); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -93,7 +93,7 @@ JSHandle JSCjsModule::Load(JSThread *thread, JSHandle JSMutableHandle parent(thread, JSTaggedValue::Undefined()); JSMutableHandle dirname(thread, JSTaggedValue::Undefined()); const JSPandaFile *jsPandaFile = EcmaInterpreter::GetNativeCallPandafile(thread); - JSRequireManager::ResolveCurrentPath(thread, parent, dirname, jsPandaFile); + RequireManager::ResolveCurrentPath(thread, parent, dirname, jsPandaFile); // Get filename from Callback JSHandle filenameStr = ResolveFilename(thread, dirname.GetTaggedValue(), request.GetTaggedValue()); @@ -108,7 +108,7 @@ JSHandle JSCjsModule::Load(JSThread *thread, JSHandle // Don't get required exports from cache, execute required JSPandaFile. // module = new Module(), which belongs to required JSPandaFile. - JSHandle module = factory->NewCjsModule(); + JSHandle module = factory->NewCjsModule(); InitializeModule(thread, module, filename, dirname); PutIntoCache(thread, module, filename); @@ -124,7 +124,7 @@ JSHandle JSCjsModule::Load(JSThread *thread, JSHandle return cachedExports; } -void JSCjsModule::RequireExecution(JSThread *thread, const JSHandle &moduleFileName) +void CjsModule::RequireExecution(JSThread *thread, const JSHandle &moduleFileName) { CString moduleFilenameStr = ConvertToString(moduleFileName.GetTaggedValue()); const JSPandaFile *jsPandaFile = @@ -136,7 +136,7 @@ void JSCjsModule::RequireExecution(JSThread *thread, const JSHandle JSPandaFileExecutor::Execute(thread, jsPandaFile); } -JSHandle JSCjsModule::ResolveFilename(JSThread *thread, JSTaggedValue dirname, JSTaggedValue request) +JSHandle CjsModule::ResolveFilename(JSThread *thread, JSTaggedValue dirname, JSTaggedValue request) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); @@ -145,20 +145,20 @@ JSHandle JSCjsModule::ResolveFilename(JSThread *thread, JSTaggedValu JSHandle nativeRequireName = ResolveFilenameFromNative(thread, dirname, request); return nativeRequireName; } - std::string modDirname = std::string(ConvertToString(EcmaString::Cast(dirname.GetHeapObject()))); - std::string modFile = std::string(ConvertToString(EcmaString::Cast(request.GetHeapObject()))); + std::string modDirname = std::string(ConvertToString(EcmaString::Cast(dirname.GetTaggedObject()))); + std::string modFile = std::string(ConvertToString(EcmaString::Cast(request.GetTaggedObject()))); std::string callbackRequireName = resolvePathCallback(modDirname, modFile); CString fullname = callbackRequireName.c_str(); return factory->NewFromUtf8(fullname); } -JSHandle JSCjsModule::ResolveFilenameFromNative(JSThread *thread, JSTaggedValue dirname, - JSTaggedValue request) +JSHandle CjsModule::ResolveFilenameFromNative(JSThread *thread, JSTaggedValue dirname, + JSTaggedValue request) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - CString dirnameStr = ConvertToString(EcmaString::Cast(dirname.GetHeapObject())); - CString requestStr = ConvertToString(EcmaString::Cast(request.GetHeapObject())); + CString dirnameStr = ConvertToString(EcmaString::Cast(dirname.GetTaggedObject())); + CString requestStr = ConvertToString(EcmaString::Cast(request.GetTaggedObject())); if (requestStr.find("./") == 0) { requestStr = requestStr.substr(2); // 2 : delete './' } @@ -179,9 +179,9 @@ JSHandle JSCjsModule::ResolveFilenameFromNative(JSThread *thread, JS return factory->NewFromUtf8(fullname); } -JSTaggedValue JSCjsModule::Require(JSThread *thread, JSHandle &request, - [[maybe_unused]]JSHandle &parent, - [[maybe_unused]]bool isMain) +JSTaggedValue CjsModule::Require(JSThread *thread, JSHandle &request, + [[maybe_unused]]JSHandle &parent, + [[maybe_unused]]bool isMain) { Load(thread, request); return JSTaggedValue::Undefined(); diff --git a/ecmascript/require/js_cjs_module.h b/ecmascript/require/js_cjs_module.h index 739993eeded1d5af3d3d0d87bee06b81c3b8f8b6..b928c1059ec67495873068c4dd63acd640a6ea00 100644 --- a/ecmascript/require/js_cjs_module.h +++ b/ecmascript/require/js_cjs_module.h @@ -23,14 +23,9 @@ namespace panda::ecmascript { enum class CjsModuleStatus : uint8_t { UNLOAD = 0x01, LOADED}; -class JSCjsModule final : public JSObject { +class CjsModule final : public JSObject { public: - CAST_CHECK(JSCjsModule, IsJSCjsModule); - - inline static JSCjsModule *Cast(const TaggedObject *object) - { - return static_cast(const_cast(object)); - } + CAST_CHECK(CjsModule, IsCjsModule); // Instantiate member static constexpr size_t JS_CJS_MODULE_OFFSET = JSObject::SIZE; @@ -49,16 +44,16 @@ public: DECL_DUMP() DECL_VISIT_OBJECT_FOR_JS_OBJECT(JSObject, JS_CJS_MODULE_OFFSET, BIT_FIELD_OFFSET) - static void InitializeModule(JSThread *thread, JSHandle &module, + static void InitializeModule(JSThread *thread, JSHandle &module, JSHandle &filename, JSHandle &dirname); static JSHandle SearchFromModuleCache(JSThread *thread, JSHandle &filename); - static void PutIntoCache(JSThread *thread, JSHandle &module, JSHandle &filename); + static void PutIntoCache(JSThread *thread, JSHandle &module, JSHandle &filename); static JSHandle Load(JSThread *thread, JSHandle &request); - static JSTaggedValue Require(JSThread *thread, JSHandle &request, JSHandle &parent, + static JSTaggedValue Require(JSThread *thread, JSHandle &request, JSHandle &parent, bool isMain); static JSHandle ResolveFilename(JSThread *thread, JSTaggedValue dirname, JSTaggedValue filename); diff --git a/ecmascript/require/js_cjs_module_cache.cpp b/ecmascript/require/js_cjs_module_cache.cpp index 5ba84a88bc3510086c2f902a9ea3c93b2d06e676..78454d27b83197d4bff1c8380dd48a19e2305206 100644 --- a/ecmascript/require/js_cjs_module_cache.cpp +++ b/ecmascript/require/js_cjs_module_cache.cpp @@ -24,7 +24,7 @@ JSHandle CjsModuleCache::PutIfAbsent(const JSThread *thread, const JSHandle &key, const JSHandle &value) { - int hash = Hash(key.GetTaggedValue()); + int hash = static_cast(Hash(key.GetTaggedValue())); int entry = dictionary->FindEntry(key.GetTaggedValue()); if (entry != -1) { diff --git a/ecmascript/require/js_cjs_module_cache.h b/ecmascript/require/js_cjs_module_cache.h index 882106212c7908479581894a5199a98914168d20..ea84f2f66bd63cdaeb9e9786515f770b67c719be 100644 --- a/ecmascript/require/js_cjs_module_cache.h +++ b/ecmascript/require/js_cjs_module_cache.h @@ -28,8 +28,9 @@ class CjsModuleCache : public TaggedHashTable { public: using HashTable = TaggedHashTable; - static CjsModuleCache *Cast(ObjectHeader *object) + static CjsModuleCache *Cast(TaggedObject *object) { + ASSERT(JSTaggedValue(object).IsTaggedArray()); return reinterpret_cast(object); } @@ -83,7 +84,7 @@ public: int size = Size(); int count = 1; JSTaggedValue keyValue; - int32_t hash = Hash(key); + uint32_t hash = Hash(key); for (uint32_t entry = GetFirstPosition(hash, size);; entry = GetNextPosition(entry, count++, size)) { keyValue = GetKey(entry); diff --git a/ecmascript/require/js_cjs_require.h b/ecmascript/require/js_cjs_require.h index b03569cb2fe4c0c570d35bfaa497f65c85c70b76..07558b20917fb8489c804a18d73fe9e24fe2bd6b 100644 --- a/ecmascript/require/js_cjs_require.h +++ b/ecmascript/require/js_cjs_require.h @@ -21,14 +21,9 @@ #include "ecmascript/ecma_runtime_call_info.h" namespace panda::ecmascript { -class JSCjsRequire final : public JSObject { +class CjsRequire final : public JSObject { public: - CAST_CHECK(JSCjsRequire, IsJSCjsRequire); - - inline static JSCjsRequire *Cast(const TaggedObject *object) - { - return static_cast(const_cast(object)); - } + CAST_CHECK(CjsRequire, IsCjsRequire); // Instantiate member static constexpr size_t JS_CJS_REQUIRE_OFFSET = JSObject::SIZE; diff --git a/ecmascript/require/js_require_manager.cpp b/ecmascript/require/js_require_manager.cpp index 62c737e9c241dad10ddd4cc53411b115404a42fc..b46a538bfc0522d30bea9c539b61cbfff4e9a465 100644 --- a/ecmascript/require/js_require_manager.cpp +++ b/ecmascript/require/js_require_manager.cpp @@ -20,10 +20,10 @@ #include "ecmascript/ecma_string.h" namespace panda::ecmascript { -void JSRequireManager::ResolveCurrentPath(JSThread *thread, - JSMutableHandle &dirPath, - JSMutableHandle &fileName, - const JSPandaFile *jsPandaFile) +void RequireManager::ResolveCurrentPath(JSThread *thread, + JSMutableHandle &dirPath, + JSMutableHandle &fileName, + const JSPandaFile *jsPandaFile) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); CString fullName = CString(jsPandaFile->GetPandaFile()->GetFilename()); @@ -41,14 +41,14 @@ void JSRequireManager::ResolveCurrentPath(JSThread *thread, fileName.Update(cbFileName.GetTaggedValue()); } -void JSRequireManager::InitializeCommonJS(JSThread *thread, CJSInfo cjsInfo) +void RequireManager::InitializeCommonJS(JSThread *thread, CJSInfo cjsInfo) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle module = cjsInfo.moduleHdl; + JSHandle module = cjsInfo.moduleHdl; JSHandle require = cjsInfo.requireHdl; - JSHandle exports = cjsInfo.exportsHdl; + JSHandle exports = cjsInfo.exportsHdl; JSHandle filename = cjsInfo.filenameHdl; JSHandle dirname = cjsInfo.dirnameHdl; @@ -57,7 +57,7 @@ void JSRequireManager::InitializeCommonJS(JSThread *thread, CJSInfo cjsInfo) SlowRuntimeStub::StObjByName(thread, module.GetTaggedValue(), exportsKey.GetTaggedValue(), exports.GetTaggedValue()); // initialize module - JSCjsModule::InitializeModule(thread, module, filename, dirname); + CjsModule::InitializeModule(thread, module, filename, dirname); // Set this.module ---> this.require.parent JSHandle parentKey(factory->NewFromASCII("parent")); @@ -77,11 +77,11 @@ void JSRequireManager::InitializeCommonJS(JSThread *thread, CJSInfo cjsInfo) newCache.GetTaggedValue()); } -void JSRequireManager::CollectExecutedExp(JSThread *thread, CJSInfo cjsInfo) +void RequireManager::CollectExecutedExp(JSThread *thread, CJSInfo cjsInfo) { const GlobalEnvConstants *globalConst = thread->GlobalConstants(); - JSHandle module = cjsInfo.moduleHdl; + JSHandle module = cjsInfo.moduleHdl; JSHandle filename = cjsInfo.filenameHdl; // get Module from global env diff --git a/ecmascript/require/js_require_manager.h b/ecmascript/require/js_require_manager.h index b5e7d68fce618ed55ad07c900c7e9e87ea5af265..5bf868cb35c06544eeb21c838f2c13e825fc307d 100644 --- a/ecmascript/require/js_require_manager.h +++ b/ecmascript/require/js_require_manager.h @@ -25,19 +25,19 @@ namespace panda::ecmascript { struct CJSInfo { - JSHandle moduleHdl; + JSHandle moduleHdl; JSHandle requireHdl; - JSHandle exportsHdl; + JSHandle exportsHdl; JSHandle filenameHdl; JSHandle dirnameHdl; - CJSInfo(JSHandle &module, + CJSInfo(JSHandle &module, JSHandle &require, - JSHandle &exports, + JSHandle &exports, JSHandle &filename, JSHandle &dirname) : moduleHdl(module), requireHdl(require), exportsHdl(exports), filenameHdl(filename), dirnameHdl(dirname) {} }; -class JSRequireManager { +class RequireManager { public: static void ResolveCurrentPath(JSThread *thread, JSMutableHandle &dirPath, diff --git a/ecmascript/runtime_call_id.h b/ecmascript/runtime_call_id.h index bff01d68627068f651dae0fa4d79a5f79043154d..74a770b2dd6d617217b736252cc1b46ca348386a 100644 --- a/ecmascript/runtime_call_id.h +++ b/ecmascript/runtime_call_id.h @@ -162,14 +162,6 @@ namespace panda::ecmascript { V(FastGetPropertyByValue) \ V(FastGetPropertyByIndex) \ V(NewLexicalEnvDyn) \ - V(SetElement) \ - V(SetGlobalOwnProperty) \ - V(SetOwnPropertyByName) \ - V(SetOwnElement) \ - V(FastSetProperty) \ - V(FastGetProperty) \ - V(FindOwnProperty) \ - V(HasOwnProperty) \ V(ExecuteNative) \ V(Execute) \ V(ToJSTaggedValueWithInt32) \ @@ -377,7 +369,7 @@ namespace panda::ecmascript { V(Atomics, Xor) \ V(Atomics, Sub) \ V(Atomics, Exchange) \ - V(Atomics, CompareEchange) \ + V(Atomics, CompareExchange) \ V(Atomics, Store) \ V(Atomics, Load) \ V(Atomics, IsLockFree) \ @@ -419,6 +411,7 @@ namespace panda::ecmascript { V(Object, GetPrototypeOf) \ V(Object, Is) \ V(Object, Keys) \ + V(Object, Values) \ V(Object, PreventExtensions) \ V(Object, Seal) \ V(Object, SetPrototypeOf) \ @@ -434,6 +427,9 @@ namespace panda::ecmascript { V(PromiseHandler, Reject) \ V(PromiseHandler, Executor) \ V(PromiseHandler, ResolveElementFunction) \ + V(PromiseHandler, AllSettledResolveElementFunction) \ + V(PromiseHandler, AllSettledRejectElementFunction) \ + V(PromiseHandler, AnyRejectElementFunction) \ V(PromiseJob, Reaction) \ V(PromiseJob, ResolveThenableJob) \ V(Promise, Constructor) \ @@ -445,6 +441,11 @@ namespace panda::ecmascript { V(Promise, Catch) \ V(Promise, Then) \ V(Promise, PerformPromiseThen) \ + V(Promise, Finally) \ + V(Promise, Any) \ + V(Promise, PerformPromiseAny) \ + V(Promise, AllSettled) \ + V(Promise, PerformPromiseAllSettled) \ V(Proxy, Constructor) \ V(Proxy, Revocable) \ V(Proxy, InvalidateProxyFunction) \ @@ -504,6 +505,7 @@ namespace panda::ecmascript { V(String, PadEnd) \ V(String, Repeat) \ V(String, Replace) \ + V(String, ReplaceAll) \ V(String, Search) \ V(String, Slice) \ V(String, Split) \ @@ -590,6 +592,49 @@ namespace panda::ecmascript { V(ArrayList, Get) \ V(ArrayList, Set) \ V(ArrayList, GetSize) \ + V(LightWeightMap, Constructor) \ + V(LightWeightMap, HasAll) \ + V(LightWeightMap, HasKey) \ + V(LightWeightMap, HasValue) \ + V(LightWeightMap, IncreaseCapacityTo) \ + V(LightWeightMap, Entries) \ + V(LightWeightMap, Get) \ + V(LightWeightMap, GetIndexOfKey) \ + V(LightWeightMap, GetIndexOfValue) \ + V(LightWeightMap, IsEmpty) \ + V(LightWeightMap, GetKeyAt) \ + V(LightWeightMap, Keys) \ + V(LightWeightMap, SetAll) \ + V(LightWeightMap, Set) \ + V(LightWeightMap, Remove) \ + V(LightWeightMap, RemoveAt) \ + V(LightWeightMap, Clear) \ + V(LightWeightMap, SetValueAt) \ + V(LightWeightMap, ForEach) \ + V(LightWeightMap, ToString) \ + V(LightWeightMap, GetValueAt) \ + V(LightWeightMap, Length) \ + V(LightWeightSet, Constructor) \ + V(LightWeightSet, Add) \ + V(LightWeightSet, AddAll) \ + V(LightWeightSet, IsEmpty) \ + V(LightWeightSet, GetValueAt) \ + V(LightWeightSet, HasAll) \ + V(LightWeightSet, Has) \ + V(LightWeightSet, HasHash) \ + V(LightWeightSet, Equal) \ + V(LightWeightSet, IncreaseCapacityTo) \ + V(LightWeightSet, GetIteratorObj) \ + V(LightWeightSet, Values) \ + V(LightWeightSet, Entries) \ + V(LightWeightSet, ForEach) \ + V(LightWeightSet, GetIndexOf) \ + V(LightWeightSet, Remove) \ + V(LightWeightSet, RemoveAt) \ + V(LightWeightSet, Clear) \ + V(LightWeightSet, ToString) \ + V(LightWeightSet, ToArray) \ + V(LightWeightSet, GetSize) \ V(PlainArray, Constructor) \ V(PlainArray, Add) \ V(PlainArray, Clear) \ @@ -686,7 +731,7 @@ namespace panda::ecmascript { V(Vector, SubVector) \ V(Vector, ToString) \ V(Vector, GetSize) \ - V(Vector, forEach) \ + V(Vector, ForEach) \ V(Vector, ReplaceAllElements) \ V(Vector, Has) \ V(Vector, Sort) \ diff --git a/ecmascript/shared_mm/shared_mm.h b/ecmascript/shared_mm/shared_mm.h index 0479e9c934c1ba95039c40dcb245333c49fca77c..1cb62148ae2d5324fb18e75e9df5587067e89ec3 100644 --- a/ecmascript/shared_mm/shared_mm.h +++ b/ecmascript/shared_mm/shared_mm.h @@ -17,7 +17,6 @@ #define ECMASCRIPT_SHARED_MEMORY_MANAGER_MANAGER_H #include "ecmascript/mem/c_containers.h" -#include "libpandabase/utils/logger.h" #include "os/mutex.h" namespace panda { diff --git a/ecmascript/snapshot/mem/constants.h b/ecmascript/snapshot/mem/constants.h index b29ce2b65ad089b4b7ae3f1063631ac2ef83bd93..4413fa08d17f51358c3b80e0b429ccbeb6844b07 100644 --- a/ecmascript/snapshot/mem/constants.h +++ b/ecmascript/snapshot/mem/constants.h @@ -37,7 +37,8 @@ public: static constexpr size_t PAGE_SIZE_ALIGN_UP = 4_KB; static constexpr size_t MAX_UINT_16 = 0xFFFF; static constexpr size_t MAX_UINT_32 = 0xFFFFFFFF; - static constexpr size_t MAX_STRING_SIZE = 0x0FFFFFFF; + static constexpr size_t MAX_OBJECT_INDEX = 0x0FFFFFFF; + static constexpr size_t REGION_INDEX_MASK = 0x3FF; // 10 bits static constexpr int UINT_64_BITS_COUNT = 64; // builtins native method encode diff --git a/ecmascript/snapshot/mem/encode_bit.h b/ecmascript/snapshot/mem/encode_bit.h index 49299247fdc12e2e6741455b5987907a4f5c4cbc..68b891fbbce386a62b0194f57a892fe17b73022a 100644 --- a/ecmascript/snapshot/mem/encode_bit.h +++ b/ecmascript/snapshot/mem/encode_bit.h @@ -25,9 +25,9 @@ /* * EncodeBit: use uint64_t value to encode TaggedObject when serialize * - * |0000...000| |0000...000| |0| |0| |0000000| |0| |0000...000| |00...0| - * 16bit:is reference 10bit:native or builtins special obj type string 18bit:obj offset 10bit:region index - * global index + * |0000...000| |0000...00| |0| |0| |00000000| |0| |0000...000| |00...0| + * 16bit:is reference 9bit:unused builtins special obj type string 18bit:obj offset 10bit:region index + * */ namespace panda::ecmascript { @@ -45,10 +45,10 @@ public: static constexpr int REGION_INDEX_BIT_NUMBER = 10; // region index static constexpr int OBJECT_OFFSET_IN_REGION_NUMBER = 18; // object offset in current region static constexpr int OBJECT_TO_STRING_FLAG_NUMBER = 1; // 1 : reference to string - static constexpr int OBJECT_TYPE_BIT_NUMBER = 7; // js_type + static constexpr int OBJECT_TYPE_BIT_NUMBER = 8; // js_type static constexpr int OBJECT_SPECIAL = 1; // special - static constexpr int GLOBAL_ENV_CONST = 1; // global object which has initialized before snapshot - static constexpr int NATIVE_OR_GLOBAL_INDEX_NUMBER = 10; // native pointer or global object index + static constexpr int GLOBAL_CONST_OR_BUILTINS = 1; // is global const or builtins object + static constexpr int UNUSED_BIT_NUMBER = 9; // unused bit number static constexpr int IS_REFERENCE_BIT_NUMBER = 16; // [0x0000] is reference using RegionIndexBits = BitField; @@ -56,9 +56,9 @@ public: using ObjectToStringBits = ObjectOffsetInRegionBits::NextField; using ObjectTypeBits = ObjectToStringBits::NextField; using ObjectSpecialBits = ObjectTypeBits::NextField; - using GlobalEnvConstBits = ObjectSpecialBits::NextField; - using NativeOrGlobalIndexBits = GlobalEnvConstBits::NextField; - using IsReferenceBits = NativeOrGlobalIndexBits::NextField; + using GlobalConstOrBuiltinsBits = ObjectSpecialBits::NextField; + using UnusedBits = GlobalConstOrBuiltinsBits::NextField; + using IsReferenceBits = UnusedBits::NextField; void SetRegionIndex(size_t region_index) { @@ -85,11 +85,6 @@ public: ObjectTypeBits::Set(object_type, &value_); } - void SetNativeOrGlobalIndex(size_t native_or_global_index) - { - NativeOrGlobalIndexBits::Set(native_or_global_index, &value_); - } - uint64_t GetValue() const { return value_; @@ -105,7 +100,7 @@ public: return ObjectOffsetInRegionBits::Decode(value_); } - size_t GetStringIndex() const + size_t GetNativePointerOrObjectIndex() const { return (ObjectOffsetInRegionBits::Decode(value_) << REGION_INDEX_BIT_NUMBER) + RegionIndexBits::Decode(value_); } @@ -115,11 +110,6 @@ public: return ObjectTypeBits::Decode(value_); } - size_t GetNativeOrGlobalIndex() const - { - return NativeOrGlobalIndexBits::Decode(value_); - } - bool IsReference() const { return IsReferenceBits::Decode(value_) == 0; @@ -135,14 +125,23 @@ public: ObjectSpecialBits::Set(true, &value_); } - bool IsGlobalEnvConst() const + bool IsGlobalConstOrBuiltins() const + { + return GlobalConstOrBuiltinsBits::Decode(value_); + } + + void SetGlobalConstOrBuiltins() { - return GlobalEnvConstBits::Decode(value_); + GlobalConstOrBuiltinsBits::Set(true, &value_); } - void SetGlobalEnvConst() + // low 28 bits are used to record object location(region index and object offset), besides, it's + // used to record string index, global const and builtins object index, native pointer index + void SetNativePointerOrObjectIndex(size_t index) { - GlobalEnvConstBits::Set(true, &value_); + ASSERT(index < Constants::MAX_OBJECT_INDEX); + ObjectOffsetInRegionBits::Set(index >> REGION_INDEX_BIT_NUMBER, &value_); + RegionIndexBits::Set(index & Constants::REGION_INDEX_MASK, &value_); } void ClearObjectSpecialFlag() @@ -155,7 +154,7 @@ private: }; static_assert(EncodeBit::REGION_INDEX_BIT_NUMBER + EncodeBit::OBJECT_OFFSET_IN_REGION_NUMBER + EncodeBit::OBJECT_TO_STRING_FLAG_NUMBER + EncodeBit::OBJECT_TYPE_BIT_NUMBER + EncodeBit::OBJECT_SPECIAL + - EncodeBit::GLOBAL_ENV_CONST + EncodeBit::NATIVE_OR_GLOBAL_INDEX_NUMBER + + EncodeBit::GLOBAL_CONST_OR_BUILTINS + EncodeBit::UNUSED_BIT_NUMBER + EncodeBit::IS_REFERENCE_BIT_NUMBER == Constants::UINT_64_BITS_COUNT); } // namespace panda::ecmascript diff --git a/ecmascript/snapshot/mem/snapshot.cpp b/ecmascript/snapshot/mem/snapshot.cpp index 1f3186e5463d6b180cc83da0c24b5dd848703d10..056a74b3a85633fb436f9365b97a93484fcc6d2a 100644 --- a/ecmascript/snapshot/mem/snapshot.cpp +++ b/ecmascript/snapshot/mem/snapshot.cpp @@ -30,6 +30,7 @@ #include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/heap.h" #include "ecmascript/object_factory.h" +#include "ecmascript/snapshot/mem/snapshot_env.h" #include "ecmascript/ts_types/ts_loader.h" #include "libpandabase/mem/mem.h" @@ -38,17 +39,16 @@ void Snapshot::Serialize(TaggedObject *objectHeader, const panda_file::File *pf, { std::pair filePath = VerifyFilePath(fileName, true); if (!filePath.first) { - LOG_ECMA(FATAL) << "snapshot file path error"; + LOG_FULL(FATAL) << "snapshot file path error"; } std::fstream writer(fileName.c_str(), std::ios::out | std::ios::binary | std::ios::trunc); if (!writer.good()) { writer.close(); - LOG_ECMA(FATAL) << "snapshot open file failed"; + LOG_FULL(FATAL) << "snapshot open file failed"; } SnapshotProcessor processor(vm_); processor.Initialize(); - vm_->GetSnapshotEnv()->Initialize(); std::unordered_map> data; CQueue objectQueue; @@ -61,24 +61,22 @@ void Snapshot::Serialize(TaggedObject *objectHeader, const panda_file::File *pf, size_t rootObjSize = objectQueue.size(); processor.ProcessObjectQueue(&objectQueue, &data); WriteToFile(writer, pf, rootObjSize, processor); - vm_->GetSnapshotEnv()->ClearEnvMap(); } void Snapshot::Serialize(uintptr_t startAddr, size_t size, const CString &fileName) { std::pair filePath = VerifyFilePath(fileName, true); if (!filePath.first) { - LOG_ECMA(FATAL) << "snapshot file path error"; + LOG_FULL(FATAL) << "snapshot file path error"; } std::fstream writer(fileName.c_str(), std::ios::out | std::ios::binary | std::ios::trunc); if (!writer.good()) { writer.close(); - LOG_ECMA(FATAL) << "snapshot open file failed"; + LOG_FULL(FATAL) << "snapshot open file failed"; } SnapshotProcessor processor(vm_); processor.Initialize(); - vm_->GetSnapshotEnv()->Initialize(); std::unordered_map> data; CQueue objectQueue; @@ -87,16 +85,16 @@ void Snapshot::Serialize(uintptr_t startAddr, size_t size, const CString &fileNa ObjectSlot end(startAddr + size * sizeof(JSTaggedType)); processor.EncodeTaggedObjectRange(start, end, &objectQueue, &data); + size_t rootObjSize = objectQueue.size(); processor.ProcessObjectQueue(&objectQueue, &data); - WriteToFile(writer, nullptr, size, processor); - vm_->GetSnapshotEnv()->ClearEnvMap(); + WriteToFile(writer, nullptr, rootObjSize, processor); } void Snapshot::SerializeBuiltins(const CString &fileName) { std::pair filePath = VerifyFilePath(fileName, true); if (!filePath.first) { - LOG_ECMA(FATAL) << "snapshot file path error"; + LOG_FULL(FATAL) << "snapshot file path error"; } // if builtins.snapshot file has exist, return directly if (!filePath.second.empty()) { @@ -105,7 +103,7 @@ void Snapshot::SerializeBuiltins(const CString &fileName) std::fstream write(fileName.c_str(), std::ios::out | std::ios::binary | std::ios::trunc); if (!write.good()) { write.close(); - LOG_ECMA(FATAL) << "snapshot open file failed"; + LOG_FULL(FATAL) << "snapshot open file failed"; } SnapshotProcessor processor(vm_); @@ -131,17 +129,17 @@ const JSPandaFile *Snapshot::Deserialize(SnapshotType type, const CString &snaps { std::pair filePath = VerifyFilePath(snapshotFile, false); if (!filePath.first) { - LOG_ECMA(FATAL) << "snapshot file path error"; + LOG_FULL(FATAL) << "snapshot file path error"; UNREACHABLE(); } int fd = open(filePath.second.c_str(), O_CLOEXEC); // NOLINT(cppcoreguidelines-pro-type-vararg) if (UNLIKELY(fd == -1)) { - LOG_ECMA(FATAL) << "open file failed"; + LOG_FULL(FATAL) << "open file failed"; UNREACHABLE(); } int32_t file_size = lseek(fd, 0, SEEK_END); if (file_size == -1) { - LOG_ECMA(FATAL) << "lseek failed"; + LOG_FULL(FATAL) << "lseek failed"; UNREACHABLE(); } @@ -162,7 +160,7 @@ const JSPandaFile *Snapshot::Deserialize(SnapshotType type, const CString &snaps if (type == SnapshotType::TS_LOADER) { auto stringVector = processor.GetStringVector(); - for (uint32_t i = 0; i < hdr.rootObjectSize; ++i) { + for (uint32_t i = 0; i < stringVector.size(); ++i) { JSTaggedValue result(reinterpret_cast(stringVector[i])); vm_->GetTSLoader()->AddConstString(result); } diff --git a/ecmascript/snapshot/mem/snapshot.h b/ecmascript/snapshot/mem/snapshot.h index 48493154cc9511896f154589b7e8d30b72d448bf..7f81cecbf381e192f3a86d965c067c3d6a9ba0b1 100644 --- a/ecmascript/snapshot/mem/snapshot.h +++ b/ecmascript/snapshot/mem/snapshot.h @@ -21,7 +21,6 @@ #include "ecmascript/common.h" #include "ecmascript/snapshot/mem/encode_bit.h" -#include "ecmascript/snapshot/mem/snapshot_env.h" #include "ecmascript/snapshot/mem/snapshot_processor.h" #include "ecmascript/mem/c_string.h" diff --git a/ecmascript/snapshot/mem/snapshot_env.cpp b/ecmascript/snapshot/mem/snapshot_env.cpp index 362c47b5fe9002dd8601532870fa0e0ac1b06bed..a4c44760a349ac78292b5c8d6fe1fc5aef68f8b6 100644 --- a/ecmascript/snapshot/mem/snapshot_env.cpp +++ b/ecmascript/snapshot/mem/snapshot_env.cpp @@ -20,29 +20,71 @@ namespace panda::ecmascript { void SnapshotEnv::Initialize() +{ +#if ECMASCRIPT_ENABLE_SNAPSHOT + InitGlobalConst(); + InitGlobalEnv(); +#endif +} + +void SnapshotEnv::InitGlobalConst() { auto globalConst = const_cast(vm_->GetJSThread()->GlobalConstants()); - size_t endIndex = globalConst->GetHClassEndIndex(); - for (size_t index = 0; index <= endIndex; index++) { + size_t constantCount = globalConst->GetConstantCount(); + for (size_t index = 0; index < constantCount; index++) { JSTaggedValue objectValue = globalConst->GetGlobalConstantObject(index); - envMap_.emplace(ToUintPtr(objectValue.GetTaggedObject()), index); + if (objectValue.IsHeapObject() && !objectValue.IsString()) { + TaggedObject *object = objectValue.GetTaggedObject(); + object->GetClass()->SetGlobalConstOrBuiltinsObject(true); + objectVector_.emplace_back(ToUintPtr(object)); + } } +} +void SnapshotEnv::InitGlobalEnv() +{ auto globalEnv = vm_->GetGlobalEnv(); - size_t globalEnvFieldSize = globalEnv->GetGlobalEnvFieldSize(); - for (size_t i = 0; i < globalEnvFieldSize; i++) { - uintptr_t address = globalEnv->ComputeObjectAddress(i); - JSHandle result(address); - if (result->IsHeapObject()) { - envMap_.emplace(ToUintPtr(result->GetTaggedObject()), i); + CQueue objectQueue; + std::set objectSet; + objectQueue.emplace(*globalEnv); + objectSet.emplace(*globalEnv); + while (!objectQueue.empty()) { + auto taggedObject = objectQueue.front(); + if (taggedObject == nullptr) { + break; } + taggedObject->GetClass()->SetGlobalConstOrBuiltinsObject(true); + objectVector_.emplace_back(ToUintPtr(taggedObject)); + objectQueue.pop(); + HandleObjectField(taggedObject, &objectQueue, &objectSet); } } +void SnapshotEnv::HandleObjectField(TaggedObject *objectHeader, CQueue *objectQueue, + std::set *objectSet) +{ + auto visitor = [objectQueue, objectSet]([[maybe_unused]]TaggedObject *root, ObjectSlot start, ObjectSlot end, + [[maybe_unused]]bool isNative) { + for (ObjectSlot slot = start; slot < end; slot++) { + auto fieldAddr = reinterpret_cast(slot.SlotAddress()); + JSTaggedValue fieldValue(*fieldAddr); + if (fieldValue.IsHeapObject() && !fieldValue.IsWeak() && !fieldValue.IsString() + && objectSet->find(fieldValue.GetTaggedObject()) == objectSet->end()) { + auto object = fieldValue.GetTaggedObject(); + objectQueue->emplace(object); + objectSet->emplace(object); + } + } + }; + objXRay_.VisitObjectBody(objectHeader, objectHeader->GetClass(), visitor); +} + void SnapshotEnv::Iterate(const RootVisitor &v) { - for (const auto &it : envMap_) { - v(Root::ROOT_VM, ObjectSlot(reinterpret_cast(&(it.first)))); + uint64_t length = objectVector_.size(); + for (uint64_t i = 0; i < length; i++) { + v(Root::ROOT_VM, ObjectSlot(reinterpret_cast(&(objectVector_.data()[i])))); } } } // namespace panda::ecmascript + diff --git a/ecmascript/snapshot/mem/snapshot_env.h b/ecmascript/snapshot/mem/snapshot_env.h index d2e7d8466459f691760cdb6bab0e9e61985ad788..b52e775f1e70d18dbbd9e753832ac1890bea6729 100644 --- a/ecmascript/snapshot/mem/snapshot_env.h +++ b/ecmascript/snapshot/mem/snapshot_env.h @@ -16,6 +16,9 @@ #ifndef ECMASCRIPT_SNAPSHOT_MEM_SNAPSHOT_ENV_H #define ECMASCRIPT_SNAPSHOT_MEM_SNAPSHOT_ENV_H +#include + +#include "ecmascript/mem/object_xray.h" #include "ecmascript/mem/visitor.h" #include "libpandabase/macros.h" @@ -24,23 +27,32 @@ class EcmaVM; class SnapshotEnv final { public: - explicit SnapshotEnv(EcmaVM *vm) : vm_(vm) {} + explicit SnapshotEnv(EcmaVM *vm) : vm_(vm), objXRay_(vm) {} ~SnapshotEnv() = default; void Initialize(); + void Iterate(const RootVisitor &v); void ClearEnvMap() { - envMap_.clear(); + objectVector_.clear(); } size_t GetEnvObjectIndex(uintptr_t objectAddr) const { - if (envMap_.find(objectAddr) == envMap_.end()) { + auto it = std::find(objectVector_.begin(), objectVector_.end(), objectAddr); + if (it == objectVector_.end()) { return MAX_UINT_32; + } else { + return std::distance(objectVector_.begin(), it); } - return envMap_.find(objectAddr)->second; + } + + uintptr_t FindEnvObjectByIndex(size_t index) + { + ASSERT(index < objectVector_.size()); + return objectVector_.at(index); } static constexpr size_t MAX_UINT_32 = 0xFFFFFFFF; @@ -49,8 +61,14 @@ private: NO_MOVE_SEMANTIC(SnapshotEnv); NO_COPY_SEMANTIC(SnapshotEnv); + void HandleObjectField(TaggedObject *objectHeader, CQueue *objectQueue, + std::set *objectSet); + void InitGlobalConst(); + void InitGlobalEnv(); + EcmaVM *vm_; - std::unordered_map envMap_; // Cache global object which can reuse when serialize + ObjectXRay objXRay_; + CVector objectVector_; }; } // namespace panda::ecmascript #endif // ECMASCRIPT_SNAPSHOT_MEM_SNAPSHOT_ENV_H \ No newline at end of file diff --git a/ecmascript/snapshot/mem/snapshot_processor.cpp b/ecmascript/snapshot/mem/snapshot_processor.cpp index b317a5f4280f43c6d2a1426ece62db5c748bd8cf..06d8f871bb227cecc677e05fc820070fee78c823 100644 --- a/ecmascript/snapshot/mem/snapshot_processor.cpp +++ b/ecmascript/snapshot/mem/snapshot_processor.cpp @@ -23,9 +23,9 @@ #include "ecmascript/builtins/builtins_atomics.h" #include "ecmascript/builtins/builtins_bigint.h" #include "ecmascript/builtins/builtins_boolean.h" -#include "ecmascript/builtins/builtin_cjs_exports.h" -#include "ecmascript/builtins/builtin_cjs_module.h" -#include "ecmascript/builtins/builtin_cjs_require.h" +#include "ecmascript/builtins/builtins_cjs_exports.h" +#include "ecmascript/builtins/builtins_cjs_module.h" +#include "ecmascript/builtins/builtins_cjs_require.h" #include "ecmascript/builtins/builtins_collator.h" #include "ecmascript/builtins/builtins_dataview.h" #include "ecmascript/builtins/builtins_date.h" @@ -65,6 +65,8 @@ #include "ecmascript/builtins/builtins_weak_set.h" #include "ecmascript/containers/containers_arraylist.h" #include "ecmascript/containers/containers_deque.h" +#include "ecmascript/containers/containers_lightweightmap.h" +#include "ecmascript/containers/containers_lightweightset.h" #include "ecmascript/containers/containers_linked_list.h" #include "ecmascript/containers/containers_list.h" #include "ecmascript/containers/containers_plainarray.h" @@ -80,6 +82,8 @@ #include "ecmascript/global_env.h" #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list_iterator.h" #include "ecmascript/js_api_plain_array_iterator.h" @@ -124,6 +128,7 @@ using Error = builtins::BuiltinsError; using RangeError = builtins::BuiltinsRangeError; using ReferenceError = builtins::BuiltinsReferenceError; using TypeError = builtins::BuiltinsTypeError; +using AggregateError = builtins::BuiltinsAggregateError; using URIError = builtins::BuiltinsURIError; using SyntaxError = builtins::BuiltinsSyntaxError; using EvalError = builtins::BuiltinsEvalError; @@ -146,9 +151,9 @@ using Promise = builtins::BuiltinsPromise; using BuiltinsPromiseHandler = builtins::BuiltinsPromiseHandler; using BuiltinsPromiseJob = builtins::BuiltinsPromiseJob; using ListFormat = builtins::BuiltinsListFormat; -using CjsExports = builtins::BuiltinsCjsExports; -using CjsModule = builtins::BuiltinsCjsModule; -using CjsRequire = builtins::BuiltinsCjsRequire; +using BuiltinsCjsExports = builtins::BuiltinsCjsExports; +using BuiltinsCjsModule = builtins::BuiltinsCjsModule; +using BuiltinsCjsRequire = builtins::BuiltinsCjsRequire; using ArkTools = builtins::BuiltinsArkTools; using ErrorType = base::ErrorType; @@ -161,6 +166,8 @@ using RelativeTimeFormat = builtins::BuiltinsRelativeTimeFormat; using Collator = builtins::BuiltinsCollator; using PluralRules = builtins::BuiltinsPluralRules; using ArrayList = containers::ContainersArrayList; +using LightWeightMap = containers::ContainersLightWeightMap; +using LightWeightSet = containers::ContainersLightWeightSet; using TreeMap = containers::ContainersTreeMap; using TreeSet = containers::ContainersTreeSet; using Vector = containers::ContainersVector; @@ -197,6 +204,8 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(TypeError::TypeErrorConstructor), reinterpret_cast(TypeError::ToString), reinterpret_cast(TypeError::ThrowTypeError), + reinterpret_cast(AggregateError::AggregateErrorConstructor), + reinterpret_cast(AggregateError::ToString), reinterpret_cast(URIError::URIErrorConstructor), reinterpret_cast(URIError::ToString), reinterpret_cast(SyntaxError::SyntaxErrorConstructor), @@ -296,6 +305,7 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(Object::IsFrozen), reinterpret_cast(Object::IsSealed), reinterpret_cast(Object::Keys), + reinterpret_cast(Object::Values), reinterpret_cast(Object::PreventExtensions), reinterpret_cast(Object::Seal), reinterpret_cast(Object::SetPrototypeOf), @@ -462,6 +472,7 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(BuiltinsString::PadStart), reinterpret_cast(BuiltinsString::Repeat), reinterpret_cast(BuiltinsString::Replace), + reinterpret_cast(BuiltinsString::ReplaceAll), reinterpret_cast(BuiltinsString::Search), reinterpret_cast(BuiltinsString::Slice), reinterpret_cast(BuiltinsString::Split), @@ -611,6 +622,9 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(Promise::Reject), reinterpret_cast(Promise::Catch), reinterpret_cast(Promise::Then), + reinterpret_cast(Promise::Finally), + reinterpret_cast(Promise::Any), + reinterpret_cast(Promise::AllSettled), reinterpret_cast(Promise::GetSpecies), reinterpret_cast(BuiltinsPromiseJob::PromiseReactionJob), reinterpret_cast(BuiltinsPromiseJob::PromiseResolveThenableJob), @@ -641,7 +655,6 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(NumberFormat::Format), reinterpret_cast(NumberFormat::FormatToParts), reinterpret_cast(NumberFormat::ResolvedOptions), - reinterpret_cast(NumberFormat::NumberFormatInternalFormatNumber), reinterpret_cast(RelativeTimeFormat::RelativeTimeFormatConstructor), reinterpret_cast(RelativeTimeFormat::SupportedLocalesOf), reinterpret_cast(RelativeTimeFormat::Format), @@ -660,17 +673,17 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(ListFormat::Format), reinterpret_cast(ListFormat::FormatToParts), reinterpret_cast(ListFormat::ResolvedOptions), - reinterpret_cast(CjsExports::CjsExportsConstructor), - reinterpret_cast(CjsModule::CjsModuleConstructor), - reinterpret_cast(CjsModule::Compiler), - reinterpret_cast(CjsModule::Load), - reinterpret_cast(CjsModule::Require), - reinterpret_cast(CjsModule::GetExportsForCircularRequire), - reinterpret_cast(CjsModule::UpdateChildren), - reinterpret_cast(CjsModule::ResolveFilename), - reinterpret_cast(CjsRequire::CjsRequireConstructor), - reinterpret_cast(CjsRequire::Main), - reinterpret_cast(CjsRequire::Resolve), + reinterpret_cast(BuiltinsCjsExports::CjsExportsConstructor), + reinterpret_cast(BuiltinsCjsModule::CjsModuleConstructor), + reinterpret_cast(BuiltinsCjsModule::Compiler), + reinterpret_cast(BuiltinsCjsModule::Load), + reinterpret_cast(BuiltinsCjsModule::Require), + reinterpret_cast(BuiltinsCjsModule::GetExportsForCircularRequire), + reinterpret_cast(BuiltinsCjsModule::UpdateChildren), + reinterpret_cast(BuiltinsCjsModule::ResolveFilename), + reinterpret_cast(BuiltinsCjsRequire::CjsRequireConstructor), + reinterpret_cast(BuiltinsCjsRequire::Main), + reinterpret_cast(BuiltinsCjsRequire::Resolve), reinterpret_cast(ArkTools::ObjectDump), reinterpret_cast(ArkTools::CompareHClass), reinterpret_cast(ArkTools::DumpHClass), @@ -701,6 +714,50 @@ static uintptr_t g_nativeTable[] = { reinterpret_cast(ArrayList::Set), reinterpret_cast(ArrayList::GetSize), reinterpret_cast(JSAPIArrayListIterator::Next), + reinterpret_cast(LightWeightMap::HasAll), + reinterpret_cast(LightWeightMap::HasKey), + reinterpret_cast(LightWeightMap::HasValue), + reinterpret_cast(LightWeightMap::IncreaseCapacityTo), + reinterpret_cast(LightWeightMap::Entries), + reinterpret_cast(LightWeightMap::Get), + reinterpret_cast(LightWeightMap::GetIndexOfKey), + reinterpret_cast(LightWeightMap::GetIndexOfValue), + reinterpret_cast(LightWeightMap::IsEmpty), + reinterpret_cast(LightWeightMap::GetKeyAt), + reinterpret_cast(LightWeightMap::Keys), + reinterpret_cast(LightWeightMap::SetAll), + reinterpret_cast(LightWeightMap::Set), + reinterpret_cast(LightWeightMap::Remove), + reinterpret_cast(LightWeightMap::RemoveAt), + reinterpret_cast(LightWeightMap::Clear), + reinterpret_cast(LightWeightMap::SetValueAt), + reinterpret_cast(LightWeightMap::ForEach), + reinterpret_cast(LightWeightMap::ToString), + reinterpret_cast(LightWeightMap::GetValueAt), + reinterpret_cast(LightWeightMap::Values), + reinterpret_cast(JSAPILightWeightMapIterator::Next), + reinterpret_cast(LightWeightSet::LightWeightSetConstructor), + reinterpret_cast(LightWeightSet::Add), + reinterpret_cast(LightWeightSet::AddAll), + reinterpret_cast(LightWeightSet::IsEmpty), + reinterpret_cast(LightWeightSet::GetValueAt), + reinterpret_cast(LightWeightSet::HasAll), + reinterpret_cast(LightWeightSet::Has), + reinterpret_cast(LightWeightSet::HasHash), + reinterpret_cast(LightWeightSet::Equal), + reinterpret_cast(LightWeightSet::IncreaseCapacityTo), + reinterpret_cast(LightWeightSet::GetIteratorObj), + reinterpret_cast(LightWeightSet::Values), + reinterpret_cast(LightWeightSet::Entries), + reinterpret_cast(LightWeightSet::ForEach), + reinterpret_cast(LightWeightSet::GetIndexOf), + reinterpret_cast(LightWeightSet::Remove), + reinterpret_cast(LightWeightSet::RemoveAt), + reinterpret_cast(LightWeightSet::Clear), + reinterpret_cast(LightWeightSet::ToString), + reinterpret_cast(LightWeightSet::ToArray), + reinterpret_cast(LightWeightSet::GetSize), + reinterpret_cast(JSAPILightWeightSetIterator::Next), reinterpret_cast(TreeMap::TreeMapConstructor), reinterpret_cast(TreeMap::Set), reinterpret_cast(TreeMap::Get), @@ -1050,7 +1107,7 @@ void SnapshotProcessor::DeserializeSpaceObject(uintptr_t beginAddr, Space* space copyBytes, ToVoidPtr(copyFrom), copyBytes) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } @@ -1089,16 +1146,15 @@ void SnapshotProcessor::DeserializeString(uintptr_t stringBegin, uintptr_t strin size_t strSize = str->ObjectSize(); strSize = AlignUp(strSize, static_cast(MemAlignment::MEM_ALIGN_OBJECT)); auto strFromTable = stringTable->GetString(str); - if (strFromTable) { stringVector_.emplace_back(ToUintPtr(strFromTable)); } else { - uintptr_t newObj = oldSpace->Allocate(strSize); + uintptr_t newObj = oldSpace->Allocate(strSize, false); if (newObj == 0) { LOG_ECMA_MEM(FATAL) << "Snapshot Allocate OldLocalSpace OOM"; } if (memcpy_s(ToVoidPtr(newObj), strSize, str, strSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } str = reinterpret_cast(newObj); @@ -1118,7 +1174,7 @@ void SnapshotProcessor::DeserializePandaMethod(uintptr_t begin, uintptr_t end, J pandaMethod_.emplace_back(begin); auto method = reinterpret_cast(begin); if (memcpy_s(methods + (--methodNums), METHOD_SIZE, method, METHOD_SIZE) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } begin += METHOD_SIZE; @@ -1132,13 +1188,14 @@ void SnapshotProcessor::HandleRootObject(SnapshotType type, uintptr_t rootObject size_t objType, size_t &constSpecialIndex) { switch (type) { - case SnapshotType::VM_ROOT: + case SnapshotType::VM_ROOT: { if (JSType(objType) == JSType::GLOBAL_ENV) { vm_->SetGlobalEnv(reinterpret_cast(rootObjectAddr)); } else if (JSType(objType) == JSType::MICRO_JOB_QUEUE) { vm_->SetMicroJobQueue(reinterpret_cast(rootObjectAddr)); } break; + } case SnapshotType::BUILTINS: { JSTaggedValue result(rootObjectAddr); auto constants = const_cast(vm_->GetJSThread()->GlobalConstants()); @@ -1154,6 +1211,13 @@ void SnapshotProcessor::HandleRootObject(SnapshotType type, uintptr_t rootObject constSpecialIndex++; break; } + case SnapshotType::TS_LOADER: { + if (JSType(objType) == JSType::HCLASS) { + TSLoader *tsLoader = vm_->GetTSLoader(); + tsLoader->AddStaticHClassInRuntimePhase(JSTaggedValue(rootObjectAddr)); + } + break; + } default: break; } @@ -1166,7 +1230,7 @@ void SnapshotProcessor::SerializeObject(TaggedObject *objectHeader, CQueueGetObjectType(); uintptr_t snapshotObj = 0; if (UNLIKELY(data->find(ToUintPtr(objectHeader)) == data->end())) { - LOG_ECMA(FATAL) << "Data map can not find object"; + LOG_FULL(FATAL) << "Data map can not find object"; UNREACHABLE(); } else { snapshotObj = data->find(ToUintPtr(objectHeader))->second.first; @@ -1240,7 +1304,7 @@ void SnapshotProcessor::RelocateSpaceObject(Space* space, SnapshotType type, JSM auto objType = encodeBit.GetObjectType(); if (objType == Constants::MASK_METHOD_SPACE_BEGIN) { begin += sizeof(uint64_t); - others = encodeBit.GetNativeOrGlobalIndex(); + others = encodeBit.GetNativePointerOrObjectIndex(); DeserializePandaMethod(begin, end, methods, methodNums, others); break; } @@ -1316,11 +1380,9 @@ uint64_t SnapshotProcessor::SerializeTaggedField(JSTaggedType *tagged, CQueueGetGlobalEnv(); - auto globalEnvObjectValue = globalEnv->GetGlobalEnvObjectByIndex(index); - *value = ToUintPtr(globalEnvObjectValue->GetTaggedObject()); + if (!builtinsDeserialize_ && encodeBit.IsReference() && encodeBit.IsGlobalConstOrBuiltins()) { + size_t index = encodeBit.GetNativePointerOrObjectIndex(); + *value = vm_->GetSnapshotEnv()->FindEnvObjectByIndex(index); return; } if (encodeBit.IsReference() && !encodeBit.IsSpecial()) { @@ -1338,8 +1400,8 @@ void SnapshotProcessor::DeserializeTaggedField(uint64_t *value) void SnapshotProcessor::DeserializeClassWord(TaggedObject *object) { EncodeBit encodeBit(*reinterpret_cast(object)); - if (!builtinsDeserialize_ && encodeBit.IsGlobalEnvConst()) { - size_t hclassIndex = encodeBit.GetNativeOrGlobalIndex(); + if (!builtinsDeserialize_ && encodeBit.IsGlobalConstOrBuiltins()) { + size_t hclassIndex = encodeBit.GetNativePointerOrObjectIndex(); auto globalConst = const_cast(vm_->GetJSThread()->GlobalConstants()); JSTaggedValue hclassValue = globalConst->GetGlobalConstantObject(hclassIndex); ASSERT(hclassValue.IsJSHClass()); @@ -1381,18 +1443,17 @@ EncodeBit SnapshotProcessor::NativePointerToEncodeBit(void *nativePointer) index = SearchNativeMethodIndex(nativePointer); } - LOG_IF(index > Constants::MAX_C_POINTER_INDEX, FATAL, RUNTIME) << "MAX_C_POINTER_INDEX: " + ToCString(index); - native.SetNativeOrGlobalIndex(index); + LOG_ECMA_IF(index > Constants::MAX_C_POINTER_INDEX, FATAL) << "MAX_C_POINTER_INDEX: " << index; + native.SetNativePointerOrObjectIndex(index); } return native; } void *SnapshotProcessor::NativePointerEncodeBitToAddr(EncodeBit nativeBit) { - size_t index = nativeBit.GetNativeOrGlobalIndex(); + size_t index = nativeBit.GetNativePointerOrObjectIndex(); void *addr = nullptr; size_t nativeTableSize = GetNativeTableSize(); - if (index < nativeTableSize - Constants::PROGRAM_NATIVE_METHOD_BEGIN) { addr = reinterpret_cast(vm_->GetFactory()->nativeMethods_.at(index)); } else if (index < nativeTableSize) { @@ -1420,7 +1481,7 @@ size_t SnapshotProcessor::SearchNativeMethodIndex(void *nativePointer) } } - LOG_ECMA(FATAL) << "native method did not register in g_table, please register it first"; + LOG_FULL(FATAL) << "native method did not register in g_table, please register it first"; UNREACHABLE(); } @@ -1428,12 +1489,12 @@ uintptr_t SnapshotProcessor::TaggedObjectEncodeBitToAddr(EncodeBit taggedBit) { ASSERT(taggedBit.IsReference()); if (!builtinsDeserialize_ && taggedBit.IsReferenceToString()) { - size_t stringIndex = taggedBit.GetStringIndex(); + size_t stringIndex = taggedBit.GetNativePointerOrObjectIndex(); return stringVector_[stringIndex]; } size_t regionIndex = taggedBit.GetRegionIndex(); if (UNLIKELY(regionIndexMap_.find(regionIndex) == regionIndexMap_.end())) { - LOG_ECMA(FATAL) << "Snapshot deserialize can not find region by index"; + LOG_FULL(FATAL) << "Snapshot deserialize can not find region by index"; } Region *region = regionIndexMap_.find(regionIndex)->second; size_t objectOffset = taggedBit.GetObjectOffsetInRegion(); @@ -1443,10 +1504,9 @@ uintptr_t SnapshotProcessor::TaggedObjectEncodeBitToAddr(EncodeBit taggedBit) void SnapshotProcessor::DeserializeNativePointer(uint64_t *value) { EncodeBit native(*value); - size_t index = native.GetNativeOrGlobalIndex(); + size_t index = native.GetNativePointerOrObjectIndex(); uintptr_t addr = 0U; size_t nativeTableSize = GetNativeTableSize(); - if (index < nativeTableSize - Constants::PROGRAM_NATIVE_METHOD_BEGIN) { addr = reinterpret_cast(vm_->GetFactory()->nativeMethods_.at(index)); } else if (index < nativeTableSize) { @@ -1459,15 +1519,14 @@ void SnapshotProcessor::DeserializeNativePointer(uint64_t *value) void SnapshotProcessor::SerializePandaFileMethod() { - EncodeBit encodeBit(0); + EncodeBit encodeBit(pandaMethod_.size()); encodeBit.SetObjectType(Constants::MASK_METHOD_SPACE_BEGIN); - encodeBit.SetNativeOrGlobalIndex(pandaMethod_.size()); ObjectFactory *factory = vm_->GetFactory(); // panda method space begin uintptr_t snapshotObj = factory->NewSpaceBySnapshotAllocator(sizeof(uint64_t)); if (snapshotObj == 0) { - LOG(ERROR, RUNTIME) << "SnapshotAllocator OOM"; + LOG_ECMA(ERROR) << "SnapshotAllocator OOM"; return; } SetObjectEncodeField(snapshotObj, 0, encodeBit.GetValue()); // methods @@ -1478,11 +1537,11 @@ void SnapshotProcessor::SerializePandaFileMethod() size_t methodObjSize = METHOD_SIZE; uintptr_t methodObj = factory->NewSpaceBySnapshotAllocator(methodObjSize); if (methodObj == 0) { - LOG(ERROR, RUNTIME) << "SnapshotAllocator OOM"; + LOG_ECMA(ERROR) << "SnapshotAllocator OOM"; return; } if (memcpy_s(ToVoidPtr(methodObj), methodObjSize, ToVoidPtr(it), METHOD_SIZE) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } } @@ -1494,7 +1553,7 @@ EncodeBit SnapshotProcessor::EncodeTaggedObject(TaggedObject *objectHeader, CQue if (!builtinsSerialize_) { // String duplicate if (objectHeader->GetClass()->GetObjectType() == JSType::STRING) { - ASSERT(stringVector_.size() < Constants::MAX_STRING_SIZE); + ASSERT(stringVector_.size() < Constants::MAX_OBJECT_INDEX); EncodeBit encodeBit(stringVector_.size()); stringVector_.emplace_back(ToUintPtr(objectHeader)); data->emplace(ToUintPtr(objectHeader), std::make_pair(0U, encodeBit)); @@ -1502,13 +1561,14 @@ EncodeBit SnapshotProcessor::EncodeTaggedObject(TaggedObject *objectHeader, CQue } // builtins object reuse - size_t globalEnvIndex = vm_->GetSnapshotEnv()->GetEnvObjectIndex(ToUintPtr(objectHeader)); - if (globalEnvIndex != SnapshotEnv::MAX_UINT_32) { - EncodeBit encodeBit(0); - encodeBit.SetGlobalEnvConst(); - encodeBit.SetNativeOrGlobalIndex(globalEnvIndex); - data->emplace(ToUintPtr(objectHeader), std::make_pair(0U, encodeBit)); - return encodeBit; + if (objectHeader->GetClass()->IsGlobalConstOrBuiltinsObject()) { + size_t index = vm_->GetSnapshotEnv()->GetEnvObjectIndex(ToUintPtr(objectHeader)); + if (index != SnapshotEnv::MAX_UINT_32) { + EncodeBit encodeBit(index); + encodeBit.SetGlobalConstOrBuiltins(); + data->emplace(ToUintPtr(objectHeader), std::make_pair(0U, encodeBit)); + return encodeBit; + } } } queue->emplace(objectHeader); @@ -1540,7 +1600,7 @@ EncodeBit SnapshotProcessor::EncodeTaggedObject(TaggedObject *objectHeader, CQue LOG_ECMA_MEM(FATAL) << "Snapshot Allocate OOM"; } if (memcpy_s(ToVoidPtr(newObj), objectSize, objectHeader, objectSize) != EOK) { - LOG_ECMA(FATAL) << "memcpy_s failed"; + LOG_FULL(FATAL) << "memcpy_s failed"; UNREACHABLE(); } auto currentRegion = Region::ObjectAddressToRange(newObj); diff --git a/ecmascript/snapshot/tests/snapshot_test.cpp b/ecmascript/snapshot/tests/snapshot_test.cpp index 3c06db8e4675b599e1985f81a692a77f62b5ee59..8941a5298e884a676f2ae5334aee91bae6a9b82b 100644 --- a/ecmascript/snapshot/tests/snapshot_test.cpp +++ b/ecmascript/snapshot/tests/snapshot_test.cpp @@ -133,7 +133,6 @@ HWTEST_F_L0(SnapshotTest, SerializeConstPool) EXPECT_TRUE(constpool1->Get(0).IsJSFunction()); EXPECT_TRUE(constpool1->Get(1).IsJSFunction()); EXPECT_TRUE(constpool1->Get(3).IsJSFunction()); - EXPECT_EQ(constpool1->Get(0).GetRawData(), constpool1->Get(0).GetRawData()); EcmaString *str11 = reinterpret_cast(constpool1->Get(2).GetTaggedObject()); EcmaString *str22 = reinterpret_cast(constpool1->Get(4).GetTaggedObject()); EcmaString *str33 = reinterpret_cast(constpool1->Get(5).GetTaggedObject()); @@ -254,23 +253,24 @@ HWTEST_F_L0(SnapshotTest, SerializeBuiltins) // generate builtins.snapshot file JSRuntimeOptions options1; options1.SetArkProperties(ArkProperties::ENABLE_SNAPSHOT_SERIALIZE); - EcmaVM *ecmaVm1 = EcmaVM::Create(options1); + auto config = ecmascript::EcmaParamConfiguration(false, MemMapAllocator::GetInstance()->GetCapacity()); + EcmaVM *ecmaVm1 = EcmaVM::Create(options1, config); EcmaVM::Destroy(ecmaVm1); // create EcmaVM use builtins deserialzie JSRuntimeOptions options2; options2.SetArkProperties(ArkProperties::ENABLE_SNAPSHOT_DESERIALIZE); - EcmaVM *ecmaVm2 = EcmaVM::Create(options2); + EcmaVM *ecmaVm2 = EcmaVM::Create(options2, config); EXPECT_TRUE(ecmaVm2->GetGlobalEnv()->GetClass()->GetObjectType() == JSType::GLOBAL_ENV); auto globalConst = const_cast(ecmaVm2->GetJSThread()->GlobalConstants()); - size_t hclassEndIndex = globalConst->GetHClassEndIndex(); + size_t hclassEndIndex = static_cast(ConstantIndex::UNDEFINED_INDEX); size_t hclassIndex = 0; globalConst->VisitRangeSlot([&hclassIndex, &hclassEndIndex]([[maybe_unused]]Root type, ObjectSlot start, ObjectSlot end) { while (start < end) { JSTaggedValue object(start.GetTaggedType()); start++; - if (hclassIndex <= hclassEndIndex) { + if (hclassIndex < hclassEndIndex) { EXPECT_TRUE(object.IsJSHClass()); } hclassIndex++; diff --git a/ecmascript/stubs/runtime_stubs-inl.h b/ecmascript/stubs/runtime_stubs-inl.h index 2cf45b158e6b9b5c6219e6f6afeb3f50c3ebc43d..f5d7f4cc5e5b07461fe920a8e67ba81a523c6800 100644 --- a/ecmascript/stubs/runtime_stubs-inl.h +++ b/ecmascript/stubs/runtime_stubs-inl.h @@ -18,8 +18,9 @@ #include "runtime_stubs.h" #include "ecmascript/builtins/builtins_regexp.h" -#include "ecmascript/compiler/llvm/llvm_stackmap_parser.h" +#include "ecmascript/llvm_stackmap_parser.h" #include "ecmascript/ecma_string_table.h" +#include "ecmascript/file_loader.h" #include "ecmascript/global_dictionary-inl.h" #include "ecmascript/global_env.h" #include "ecmascript/ic/profile_type_info.h" @@ -31,8 +32,11 @@ #include "ecmascript/js_generator_object.h" #include "ecmascript/js_iterator.h" #include "ecmascript/js_promise.h" +#include "ecmascript/jspandafile/scope_info_extractor.h" #include "ecmascript/module/js_module_manager.h" #include "ecmascript/template_string.h" +#include "ecmascript/ts_types/ts_loader.h" +#include "ecmascript/jspandafile/literal_data_extractor.h" #include "ecmascript/jspandafile/scope_info_extractor.h" namespace panda::ecmascript { @@ -184,12 +188,13 @@ JSTaggedValue RuntimeStubs::RuntimeSuperCallSpread(JSThread *thread, const JSHan ASSERT(superFunc->IsJSFunction()); JSHandle argv(thread, RuntimeGetCallSpreadArgs(thread, array.GetTaggedValue())); - const size_t argsLength = argv->GetLength(); + const int32_t argsLength = static_cast(argv->GetLength()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, superFunc, undefined, newTarget, argsLength); - info.SetCallArg(argsLength, argv); - JSTaggedValue result = JSFunction::Construct(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(argsLength, argv); + JSTaggedValue result = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result; @@ -224,9 +229,10 @@ JSTaggedValue RuntimeStubs::RuntimeNewObjSpreadDyn(JSThread *thread, const JSHan RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, undefined, newTarget, length); - info.SetCallArg(length, argsArray); - return SlowRuntimeHelper::NewObject(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, undefined, newTarget, length); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(length, argsArray); + return SlowRuntimeHelper::NewObject(info); } JSTaggedValue RuntimeStubs::RuntimeCreateIterResultObj(JSThread *thread, const JSHandle &value, @@ -268,9 +274,10 @@ JSTaggedValue RuntimeStubs::RuntimeAsyncFunctionResolveOrReject(JSThread *thread activeFunc = JSHandle(thread, reactions->GetRejectFunction()); } JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, activeFunc, thisArg, undefined, 1); - info.SetCallArg(value.GetTaggedValue()); - [[maybe_unused]] JSTaggedValue res = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, activeFunc, thisArg, undefined, 1); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(value.GetTaggedValue()); + [[maybe_unused]] JSTaggedValue res = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return promise.GetTaggedValue(); @@ -360,8 +367,9 @@ JSTaggedValue RuntimeStubs::RuntimeGetIteratorNext(JSThread *thread, const JSHan { ASSERT(method->IsCallable()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, obj, undefined, 0); - JSTaggedValue ret = JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, method, obj, undefined, 0); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + JSTaggedValue ret = JSFunction::Call(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); if (!ret.IsECMAObject()) { return RuntimeThrowTypeError(thread, "the Iterator is not an ecmaobject."); @@ -640,7 +648,7 @@ JSTaggedValue RuntimeStubs::RuntimeCloneClassFromTemplate(JSThread *thread, cons cloneClass->SetHomeObject(thread, cloneClassPrototype); if (!canShareHClass) { - RuntimeSetClassInheritanceRelationship(thread, JSHandle(ctor), base); + RuntimeSetClassInheritanceRelationship(thread, JSHandle(cloneClass), base); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); } @@ -729,6 +737,7 @@ JSTaggedValue RuntimeStubs::RuntimeNotifyInlineCache(JSThread *thread, const JSH JSHandle profileTypeInfo = factory->NewProfileTypeInfo(icSlotSize); if (overflow) { + // set as mega profileTypeInfo->Set(thread, ProfileTypeInfo::INVALID_SLOT_INDEX - 1, JSTaggedValue::Hole()); profileTypeInfo->Set(thread, ProfileTypeInfo::INVALID_SLOT_INDEX, JSTaggedValue::Hole()); } @@ -865,8 +874,8 @@ JSTaggedValue RuntimeStubs::RuntimeGetIterator(JSThread *thread, const JSHandle< return valuesFunc.GetTaggedValue(); } JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, valuesFunc, obj, undefined, 0); - return EcmaInterpreter::Execute(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, valuesFunc, obj, undefined, 0); + return EcmaInterpreter::Execute(info); } void RuntimeStubs::RuntimeThrowDyn(JSThread *thread, JSTaggedValue value) @@ -1205,47 +1214,12 @@ JSTaggedValue RuntimeStubs::RuntimeGetUnmapedArgs(JSThread *thread, JSTaggedType uint32_t startIdx) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle argumentsList = factory->NewTaggedArray(actualNumArgs); for (uint32_t i = 0; i < actualNumArgs; ++i) { argumentsList->Set(thread, i, JSTaggedValue(sp[startIdx + i])); // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) } - // 1. Let len be the number of elements in argumentsList - uint32_t len = argumentsList->GetLength(); - // 2. Let obj be ObjectCreate(%ObjectPrototype%, «[[ParameterMap]]»). - // 3. Set obj’s [[ParameterMap]] internal slot to undefined. - JSHandle obj = factory->NewJSArguments(); - // 4. Perform DefinePropertyOrThrow(obj, "length", PropertyDescriptor{[[Value]]: len, [[Writable]]: true, - // [[Enumerable]]: false, [[Configurable]]: true}). - obj->SetPropertyInlinedProps(thread, JSArguments::LENGTH_INLINE_PROPERTY_INDEX, JSTaggedValue(len)); - // 5. Let index be 0. - // 6. Repeat while index < len, - // a. Let val be argumentsList[index]. - // b. Perform CreateDataProperty(obj, ToString(index), val). - // c. Let index be index + 1 - obj->SetElements(thread, argumentsList.GetTaggedValue()); - // 7. Perform DefinePropertyOrThrow(obj, @@iterator, PropertyDescriptor - // {[[Value]]:%ArrayProto_values%, - // [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}). - obj->SetPropertyInlinedProps(thread, JSArguments::ITERATOR_INLINE_PROPERTY_INDEX, - globalEnv->GetArrayProtoValuesFunction().GetTaggedValue()); - // 8. Perform DefinePropertyOrThrow(obj, "caller", PropertyDescriptor {[[Get]]: %ThrowTypeError%, - // [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false}). - JSHandle throwFunction = globalEnv->GetThrowTypeError(); - JSHandle accessor = factory->NewAccessorData(); - accessor->SetGetter(thread, throwFunction); - accessor->SetSetter(thread, throwFunction); - obj->SetPropertyInlinedProps(thread, JSArguments::CALLER_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); - // 9. Perform DefinePropertyOrThrow(obj, "callee", PropertyDescriptor {[[Get]]: %ThrowTypeError%, - // [[Set]]: %ThrowTypeError%, [[Enumerable]]: false, [[Configurable]]: false}). - accessor = factory->NewAccessorData(); - accessor->SetGetter(thread, throwFunction); - accessor->SetSetter(thread, throwFunction); - obj->SetPropertyInlinedProps(thread, JSArguments::CALLEE_INLINE_PROPERTY_INDEX, accessor.GetTaggedValue()); - RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - // 11. Return obj - return obj.GetTaggedValue(); + return RuntimeGetUnmapedJSArgumentObj(thread, argumentsList); } JSTaggedValue RuntimeStubs::RuntimeCopyRestArgs(JSThread *thread, JSTaggedType *sp, uint32_t restNumArgs, @@ -1471,9 +1445,10 @@ JSTaggedValue RuntimeStubs::RuntimeCallSpreadDyn(JSThread *thread, const JSHandl JSHandle coretypesArray(thread, RuntimeGetCallSpreadArgs(thread, array.GetTaggedValue())); uint32_t length = coretypesArray->GetLength(); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, obj, undefined, length); - info.SetCallArg(length, coretypesArray); - return EcmaInterpreter::Execute(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, func, obj, undefined, length); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(length, coretypesArray); + return EcmaInterpreter::Execute(info); } JSTaggedValue RuntimeStubs::RuntimeDefineGetterSetterByValue(JSThread *thread, const JSHandle &obj, @@ -1543,9 +1518,10 @@ JSTaggedValue RuntimeStubs::RuntimeSuperCall(JSThread *thread, const JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, superFunc, undefined, newTarget, length); - info.SetCallArg(length, argv); - JSTaggedValue result = JSFunction::Construct(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, superFunc, undefined, newTarget, length); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(length, argv); + JSTaggedValue result = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return result; @@ -1608,20 +1584,46 @@ JSTaggedValue RuntimeStubs::RuntimeNewLexicalEnvWithNameDyn(JSThread *thread, ui return newEnv.GetTaggedValue(); } -JSTaggedValue RuntimeStubs::RuntimeGetAotUnmapedArgs(JSThread *thread, uint32_t actualNumArgs, uintptr_t argv) +JSTaggedValue RuntimeStubs::RuntimeGetAotUnmapedArgs(JSThread *thread, uint32_t actualNumArgs) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle argumentsList = factory->NewTaggedArray(actualNumArgs - FIXED_NUM_ARGS); + + auto argv = GetActualArgv(thread); + int idx = 0; + for (uint32_t i = FIXED_NUM_ARGS; i < actualNumArgs; ++i) { + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) + JSTaggedType arg = reinterpret_cast(argv)[i]; + JSTaggedValue args = JSTaggedValue(arg); + argumentsList->Set(thread, idx++, args); + } + return RuntimeGetUnmapedJSArgumentObj(thread, argumentsList); +} + +JSTaggedValue RuntimeStubs::RuntimeGetAotUnmapedArgsWithRestArgs(JSThread *thread, uint32_t actualNumArgs) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); JSHandle argumentsList = factory->NewTaggedArray(actualNumArgs - FIXED_NUM_ARGS); + auto leaveFrame = const_cast(thread->GetLastLeaveFrame()); + auto frame = OptimizedLeaveFrame::GetFrameFromSp(leaveFrame); + JSTaggedType *argv = frame->GetJsFuncFrameArgv(thread); for (uint32_t i = 0; i < actualNumArgs - FIXED_NUM_ARGS; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - JSTaggedType arg = reinterpret_cast(argv)[i + 1]; // skip actualNumArgs + JSTaggedType arg = reinterpret_cast(argv)[i + FIXED_NUM_ARGS]; // skip actualNumArgs argumentsList->Set(thread, i, JSTaggedValue(arg)); } + return RuntimeGetUnmapedJSArgumentObj(thread, argumentsList); +} + +JSTaggedValue RuntimeStubs::RuntimeGetUnmapedJSArgumentObj(JSThread *thread, const JSHandle &argumentsList) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); // 1. Let len be the number of elements in argumentsList uint32_t len = argumentsList->GetLength(); // 2. Let obj be ObjectCreate(%ObjectPrototype%, «[[ParameterMap]]»). // 3. Set obj’s [[ParameterMap]] internal slot to undefined. + // [[ParameterMap]] setted as undifined. JSHandle obj = factory->NewJSArguments(); // 4. Perform DefinePropertyOrThrow(obj, "length", PropertyDescriptor{[[Value]]: len, [[Writable]]: true, // [[Enumerable]]: false, [[Configurable]]: true}). @@ -1663,33 +1665,41 @@ JSTaggedValue RuntimeStubs::RuntimeNewAotLexicalEnvDyn(JSThread *thread, uint16_ newEnv->SetParentEnv(thread, currentLexEnv.GetTaggedValue()); newEnv->SetScopeInfo(thread, JSTaggedValue::Hole()); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return newEnv.GetTaggedValue(); + JSTaggedValue taggedEnv = newEnv.GetTaggedValue(); + RuntimeSetAotLexEnv(thread, taggedEnv); + return taggedEnv; } JSTaggedValue RuntimeStubs::RuntimeNewAotLexicalEnvWithNameDyn(JSThread *thread, uint16_t numVars, uint16_t scopeId, - JSHandle ¤tLexEnv) + JSHandle ¤tLexEnv, + JSHandle &func) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle newEnv = factory->NewLexicalEnv(numVars); newEnv->SetParentEnv(thread, currentLexEnv.GetTaggedValue()); - JSTaggedValue scopeInfo = ScopeInfoExtractor::GenerateScopeInfo(thread, scopeId); + JSTaggedValue scopeInfo = RuntimeGenerateAotScopeInfo(thread, scopeId, func.GetTaggedValue()); newEnv->SetScopeInfo(thread, scopeInfo); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); - return newEnv.GetTaggedValue(); + JSTaggedValue taggedEnv = newEnv.GetTaggedValue(); + RuntimeSetAotLexEnv(thread, taggedEnv); + return taggedEnv; } -JSTaggedValue RuntimeStubs::RuntimeCopyAotRestArgs(JSThread *thread, uint32_t restNumArgs, uintptr_t argv) +JSTaggedValue RuntimeStubs::RuntimeCopyAotRestArgs(JSThread *thread, uint32_t actualArgc, uint32_t restIndex) { - uint32_t actualRestNum = restNumArgs - FIXED_NUM_ARGS; + uint32_t actualRestNum = actualArgc - FIXED_NUM_ARGS - restIndex; JSHandle restArray = JSArray::ArrayCreate(thread, JSTaggedNumber(actualRestNum)); + auto argv = GetActualArgv(thread); + int idx = 0; JSMutableHandle element(thread, JSTaggedValue::Undefined()); - for (uint32_t i = 0; i < actualRestNum; ++i) { + + for (uint32_t i = FIXED_NUM_ARGS + restIndex; i < actualArgc; ++i) { // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) - JSTaggedType arg = reinterpret_cast(argv)[i + 1]; // skip restNumArgs + JSTaggedType arg = reinterpret_cast(argv)[i]; element.Update(JSTaggedValue(arg)); - JSObject::SetProperty(thread, restArray, i, element, true); + JSObject::SetProperty(thread, restArray, idx++, element, true); } RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); return restArray.GetTaggedValue(); @@ -1719,15 +1729,113 @@ JSTaggedValue RuntimeStubs::RuntimeNewAotObjDynRange(JSThread *thread, uintptr_t JSHandle thisObj = thread->GlobalConstants()->GetHandledUndefined(); const size_t numCtorAndNewTgt = 2; STACK_ASSERT_SCOPE(thread); - EcmaRuntimeCallInfo info = - ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, ctor, thisObj, newTgt, argc - numCtorAndNewTgt); + EcmaRuntimeCallInfo *info = + EcmaInterpreter::NewRuntimeCallInfo(thread, ctor, thisObj, newTgt, argc - numCtorAndNewTgt); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); for (size_t i = 0; i < argc - numCtorAndNewTgt; ++i) { - info.SetCallArg(i, JSTaggedValue(args[i + numCtorAndNewTgt])); + info->SetCallArg(i, JSTaggedValue(args[i + numCtorAndNewTgt])); + } + + JSTaggedValue object = JSFunction::Construct(info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + return object; +} + +JSTaggedValue RuntimeStubs::RuntimeAotNewObjWithIHClass(JSThread *thread, uintptr_t argv, uint32_t argc) +{ + CVector hclassTable = thread->GetEcmaVM()->GetTSLoader()->GetStaticHClassTable(); + + int32_t ihcIndex = GetArg(argv, argc, argc - 1).GetInt(); // last element + JSHandle ihc(thread, JSTaggedValue(hclassTable[ihcIndex])); + + JSTaggedType *args = reinterpret_cast(argv); + JSHandle ctor = GetHArg(argv, argc, 0); + JSHandle newTgt = GetHArg(argv, argc, 1); + JSHandle thisObj = thread->GlobalConstants()->GetHandledUndefined(); + + JSHandle ctorPrototype = JSTaggedValue::GetProperty(thread, JSHandle(ctor), + thread->GlobalConstants()->GetHandledPrototypeString()).GetValue(); + ihc->SetProto(thread, ctorPrototype); + + ctor->SetProtoOrDynClass(thread, ihc); + + const size_t numCtorAndNewTgt = 2; + const size_t numCtorNewTgtAndIHCIndex = 3; + EcmaRuntimeCallInfo *info = ecmascript::EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(ctor), + thisObj, newTgt, argc - numCtorNewTgtAndIHCIndex); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + for (size_t i = 0; i < argc - numCtorNewTgtAndIHCIndex; ++i) { + info->SetCallArg(i, JSTaggedValue(args[i + numCtorAndNewTgt])); } - JSTaggedValue object = JSFunction::Construct(&info); + JSTaggedValue object = JSFunction::Construct(info); RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + return object; } + +JSTaggedValue RuntimeStubs::RuntimeGetAotLexEnv(JSThread *thread) +{ + [[maybe_unused]] DisallowGarbageCollection noGc; + auto optimizedJSFunctionFrame = GetOptimizedJSFunctionFrame(thread); + return optimizedJSFunctionFrame->GetEnv(); +} + +void RuntimeStubs::RuntimeSetAotLexEnv(JSThread *thread, JSTaggedValue lexEnv) +{ + auto optimizedJSFunctionFrame = GetOptimizedJSFunctionFrame(thread); + optimizedJSFunctionFrame->SetEnv(lexEnv); +} + +JSTaggedValue RuntimeStubs::RuntimeGenerateAotScopeInfo(JSThread *thread, uint16_t scopeId, JSTaggedValue func) +{ + EcmaVM *ecmaVm = thread->GetEcmaVM(); + ObjectFactory *factory = ecmaVm->GetFactory(); + JSMethod *method = ECMAObject::Cast(func.GetTaggedObject())->GetCallTarget(); + const JSPandaFile *jsPandaFile = method->GetJSPandaFile(); + JSHandle elementsLiteral = LiteralDataExtractor::GetDatasIgnoreType(thread, jsPandaFile, scopeId); + ASSERT(elementsLiteral->GetLength() > 0); + size_t length = elementsLiteral->GetLength(); + + auto buffer = ecmaVm->GetNativeAreaAllocator()->New(); + auto scopeDebugInfo = static_cast(buffer); + + for (size_t i = 1; i < length; i += 2) { // 2: Each literal buffer contains a pair of key-value. + JSTaggedValue val = elementsLiteral->Get(i); + ASSERT(val.IsString()); + CString name = ConvertToString(EcmaString::Cast(val.GetTaggedObject())); + int32_t slot = elementsLiteral->Get(i + 1).GetInt(); + if (scopeDebugInfo == nullptr) { + return JSTaggedValue::Hole(); + } + scopeDebugInfo->scopeInfo.insert(std::make_pair(name, slot)); + } + + auto freeObjFunc = NativeAreaAllocator::FreeObjectFunc; + auto allocator = ecmaVm->GetNativeAreaAllocator(); + JSHandle pointer = factory->NewJSNativePointer(buffer, freeObjFunc, allocator); + return pointer.GetTaggedValue(); +} + +JSTaggedType *RuntimeStubs::GetActualArgv(JSThread *thread) +{ + JSTaggedType *current = const_cast(thread->GetLastLeaveFrame()); + ASSERT(FrameHandler::GetFrameType(current) == FrameType::LEAVE_FRAME); + FrameIterator it(current, thread); + it.Advance(); + ASSERT(it.GetFrameType() == FrameType::OPTIMIZED_JS_FUNCTION_FRAME); + auto optimizedJSFunctionFrame = it.GetFrame(); + return optimizedJSFunctionFrame->GetArgv(it); +} + +OptimizedJSFunctionFrame *RuntimeStubs::GetOptimizedJSFunctionFrame(JSThread *thread) +{ + JSTaggedType *current = const_cast(thread->GetLastLeaveFrame()); + ASSERT(FrameHandler::GetFrameType(current) == FrameType::LEAVE_FRAME); + FrameIterator it(current, thread); + it.Advance(); + ASSERT(it.GetFrameType() == FrameType::OPTIMIZED_JS_FUNCTION_FRAME); + return it.GetFrame(); +} } // namespace panda::ecmascript #endif // ECMASCRIPT_STUBS_RUNTIME_STUBS_INL_H diff --git a/ecmascript/stubs/runtime_stubs.cpp b/ecmascript/stubs/runtime_stubs.cpp index 418c095c9dc4dc7f58957f02eb9089a622ab27b0..23767d3177a78737712ae1cb31613056ac39d6d9 100644 --- a/ecmascript/stubs/runtime_stubs.cpp +++ b/ecmascript/stubs/runtime_stubs.cpp @@ -32,6 +32,7 @@ #include "ecmascript/js_object.h" #include "ecmascript/js_proxy.h" #include "ecmascript/js_thread.h" +#include "ecmascript/js_typed_array.h" #include "ecmascript/jspandafile/program_object.h" #include "ecmascript/layout_info.h" #include "ecmascript/mem/space-inl.h" @@ -889,6 +890,7 @@ DEF_RUNTIME_STUBS(UpFrame) uint32_t pcOffset = panda_file::INVALID_OFFSET; for (; frameHandler.HasFrame(); frameHandler.PrevInterpretedFrame()) { if (frameHandler.IsEntryFrame() || frameHandler.IsBuiltinFrame()) { + thread->SetCurrentFrame(frameHandler.GetSp()); thread->SetLastFp(frameHandler.GetFp()); return JSTaggedValue(static_cast(0)).GetRawData(); } @@ -1219,7 +1221,7 @@ DEF_RUNTIME_STUBS(JumpToCInterpreter) uint8_t opcode = currentPc[0]; asmDispatchTable[opcode](thread, currentPc, sp, constpool, profileTypeInfo, acc, hotnessCounter.GetInt()); sp = const_cast(thread->GetCurrentInterpretedFrame()); - return JSTaggedValue(reinterpret_cast(sp)).GetRawData(); + return JSTaggedValue(reinterpret_cast(sp)).GetRawData(); } DEF_RUNTIME_STUBS(NotifyBytecodePcChanged) @@ -1501,8 +1503,6 @@ DEF_RUNTIME_STUBS(ThrowDerivedMustReturnException) DEF_RUNTIME_STUBS(CallNative) { RUNTIME_STUBS_HEADER(CallNative); - JSTaggedValue numArgs = GetArg(argv, argc, 0); - auto sp = const_cast(thread->GetCurrentInterpretedFrame()); auto state = reinterpret_cast(sp) - 1; // leave frame prev is prevSp now, change it to current sp @@ -1512,9 +1512,9 @@ DEF_RUNTIME_STUBS(CallNative) frame->callsiteFp = reinterpret_cast(sp); JSMethod *method = ECMAObject::Cast(state->function.GetTaggedObject())->GetCallTarget(); - EcmaRuntimeCallInfo ecmaRuntimeCallInfo(thread, numArgs.GetInt(), sp); + EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast(sp); JSTaggedValue retValue = reinterpret_cast( - const_cast(method->GetNativePointer()))(&ecmaRuntimeCallInfo); + const_cast(method->GetNativePointer()))(ecmaRuntimeCallInfo); frame->callsiteFp = cachedFpValue; RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, JSTaggedValue::Exception().GetRawData()); return retValue.GetRawData(); @@ -1541,14 +1541,20 @@ DEF_RUNTIME_STUBS(GetAotUnmapedArgs) { RUNTIME_STUBS_HEADER(GetAotUnmapedArgs); JSTaggedValue actualNumArgs = GetArg(argv, argc, 0); - return RuntimeGetAotUnmapedArgs(thread, actualNumArgs.GetInt(), argv).GetRawData(); + return RuntimeGetAotUnmapedArgs(thread, actualNumArgs.GetInt()).GetRawData(); +} + +DEF_RUNTIME_STUBS(GetAotUnmapedArgsWithRestArgs) +{ + RUNTIME_STUBS_HEADER(GetAotUnmapedArgsWithRestArgs); + JSTaggedValue actualNumArgs = GetArg(argv, argc, 0); + return RuntimeGetAotUnmapedArgsWithRestArgs(thread, actualNumArgs.GetInt()).GetRawData(); } DEF_RUNTIME_STUBS(GetAotLexicalEnv) { RUNTIME_STUBS_HEADER(GetAotLexicalEnv); - JSFunction *jsFunc = GetPtrArg(argv, argc, 0); - return jsFunc->GetLexicalEnv().GetRawData(); + return RuntimeGetAotLexEnv(thread).GetRawData(); } DEF_RUNTIME_STUBS(NewAotLexicalEnvDyn) @@ -1562,18 +1568,30 @@ DEF_RUNTIME_STUBS(NewAotLexicalEnvDyn) DEF_RUNTIME_STUBS(NewAotLexicalEnvWithNameDyn) { RUNTIME_STUBS_HEADER(NewAotLexicalEnvWithNameDyn); - JSTaggedValue numVars = GetArg(argv, argc, 0); - JSTaggedValue scopeId = GetArg(argv, argc, 1); + JSTaggedValue taggedNumVars = GetArg(argv, argc, 0); + JSTaggedValue taggedScopeId = GetArg(argv, argc, 1); JSHandle currentLexEnv = GetHArg(argv, argc, 2); - return RuntimeNewAotLexicalEnvWithNameDyn(thread, static_cast(numVars.GetInt()), - static_cast(scopeId.GetInt()), currentLexEnv).GetRawData(); + JSHandle func = GetHArg(argv, argc, 3); + uint16_t numVars = static_cast(taggedNumVars.GetInt()); + uint16_t scopeId = static_cast(taggedScopeId.GetInt()); + return RuntimeNewAotLexicalEnvWithNameDyn(thread, numVars, scopeId, currentLexEnv, func).GetRawData(); +} + +DEF_RUNTIME_STUBS(PopAotLexicalEnv) +{ + RUNTIME_STUBS_HEADER(PopAotLexicalEnv); + JSTaggedValue currentLexenv = RuntimeGetAotLexEnv(thread); + JSTaggedValue parentLexenv = LexicalEnv::Cast(currentLexenv.GetTaggedObject())->GetParentEnv(); + RuntimeSetAotLexEnv(thread, parentLexenv); + return JSTaggedValue::VALUE_HOLE; } DEF_RUNTIME_STUBS(CopyAotRestArgs) { RUNTIME_STUBS_HEADER(CopyAotRestArgs); - JSTaggedValue restNumArgs = GetArg(argv, argc, 0); - return RuntimeCopyAotRestArgs(thread, restNumArgs.GetInt(), argv).GetRawData(); + JSTaggedValue actualArgc = GetArg(argv, argc, 0); + JSTaggedValue restIndex = GetArg(argv, argc, 1); + return RuntimeCopyAotRestArgs(thread, actualArgc.GetInt(), restIndex.GetInt()).GetRawData(); } DEF_RUNTIME_STUBS(NewAotObjDynRange) @@ -1582,13 +1600,69 @@ DEF_RUNTIME_STUBS(NewAotObjDynRange) return RuntimeNewAotObjDynRange(thread, argv, argc).GetRawData(); } +DEF_RUNTIME_STUBS(GetTypeArrayPropertyByIndex) +{ + RUNTIME_STUBS_HEADER(GetTypeArrayPropertyByIndex); + JSTaggedValue obj = GetArg(argv, argc, 0); + JSTaggedValue idx = GetArg(argv, argc, 1); + JSTaggedValue jsType = GetArg(argv, argc, 2); // 2:means the second parameter + return JSTypedArray::FastGetPropertyByIndex(thread, obj, idx.GetInt(), JSType(jsType.GetInt())).GetRawData(); +} + +DEF_RUNTIME_STUBS(SetTypeArrayPropertyByIndex) +{ + RUNTIME_STUBS_HEADER(SetTypeArrayPropertyByIndex); + JSTaggedValue obj = GetArg(argv, argc, 0); + JSTaggedValue idx = GetArg(argv, argc, 1); + JSTaggedValue value = GetArg(argv, argc, 2); // 2:means the second parameter + JSTaggedValue jsType = GetArg(argv, argc, 3); // 3:means the third parameter + return JSTypedArray::FastSetPropertyByIndex(thread, obj, idx.GetInt(), value, JSType(jsType.GetInt())).GetRawData(); +} + +DEF_RUNTIME_STUBS(AotNewObjWithIHClass) +{ + RUNTIME_STUBS_HEADER(AotNewObjWithIHClass); + return RuntimeAotNewObjWithIHClass(thread, argv, argc).GetRawData(); +} + +DEF_RUNTIME_STUBS(LdAotLexVarDyn) +{ + RUNTIME_STUBS_HEADER(LdAotLexVarDyn); + JSTaggedValue level = GetArg(argv, argc, 0); + JSTaggedValue slot = GetArg(argv, argc, 1); + JSTaggedValue env = RuntimeGetAotLexEnv(thread); + for (int32_t i = 0; i < level.GetInt(); i++) { + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + ASSERT(!taggedParentEnv.IsUndefined()); + env = taggedParentEnv; + } + return LexicalEnv::Cast(env.GetTaggedObject())->GetProperties(slot.GetInt()).GetRawData(); +} + +DEF_RUNTIME_STUBS(StAotLexVarDyn) +{ + RUNTIME_STUBS_HEADER(StAotLexVarDyn); + JSTaggedValue level = GetArg(argv, argc, 0); + JSTaggedValue slot = GetArg(argv, argc, 1); + JSTaggedValue value = GetArg(argv, argc, 2); + JSTaggedValue env = RuntimeGetAotLexEnv(thread); + + for (int32_t i = 0; i < level.GetInt(); i++) { + JSTaggedValue taggedParentEnv = LexicalEnv::Cast(env.GetTaggedObject())->GetParentEnv(); + ASSERT(!taggedParentEnv.IsUndefined()); + env = taggedParentEnv; + } + LexicalEnv::Cast(env.GetTaggedObject())->SetProperties(thread, slot.GetInt(), value); + return JSTaggedValue::VALUE_HOLE; +} + JSTaggedType RuntimeStubs::CreateArrayFromList([[maybe_unused]]uintptr_t argGlue, int32_t argc, JSTaggedValue *argvPtr) { auto thread = JSThread::GlueToJSThread(argGlue); ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - JSHandle taggedArray = factory->NewTaggedArray(argc); - for (int index = 0; index < argc; ++index) { - taggedArray->Set(thread, index, argvPtr[index]); + JSHandle taggedArray = factory->NewTaggedArray(argc - NUM_MANDATORY_JSFUNC_ARGS); + for (int index = NUM_MANDATORY_JSFUNC_ARGS; index < argc; ++index) { + taggedArray->Set(thread, index - NUM_MANDATORY_JSFUNC_ARGS, argvPtr[index]); } JSHandle arrHandle = JSArray::CreateArrayFromList(thread, taggedArray); return arrHandle.GetTaggedValue().GetRawData(); diff --git a/ecmascript/stubs/runtime_stubs.h b/ecmascript/stubs/runtime_stubs.h index 10fb250d68ec1cfd1679e755909997290537efaf..a66454575aa72dc5873ef8539a967d8f18428ef4 100644 --- a/ecmascript/stubs/runtime_stubs.h +++ b/ecmascript/stubs/runtime_stubs.h @@ -17,6 +17,7 @@ #define ECMASCRIPT_RUNTIME_STUBS_H #include "ecmascript/compiler/call_signature.h" +#include "ecmascript/frames.h" #include "ecmascript/stubs/test_runtime_stubs.h" #include "ecmascript/ecma_macros.h" #include "ecmascript/js_tagged_value.h" @@ -49,6 +50,7 @@ using JSFunctionEntryType = uint64_t (*)(uintptr_t glue, uintptr_t prevFp, uint3 V(PushCallNewAndDispatchNative) \ V(PushCallIRangeAndDispatchNative) \ V(PushCallIThisRangeAndDispatch) \ + V(JSCallWithArgV) \ V(ResumeRspAndDispatch) \ V(ResumeRspAndReturn) \ V(ResumeCaughtFrameAndDispatch) \ @@ -57,9 +59,8 @@ using JSFunctionEntryType = uint64_t (*)(uintptr_t glue, uintptr_t prevFp, uint3 V(CallGetter) \ V(CallRuntimeWithArgv) \ V(JSCall) \ - V(JSCallWithArgV) \ + V(JSProxyCallInternalWithArgV) \ V(JSFunctionEntry) \ - V(CallBuiltinTrampoline) \ V(OptimizedCallOptimized) #define RUNTIME_STUB_WITHOUT_GC_LIST(V) \ @@ -214,13 +215,20 @@ using JSFunctionEntryType = uint64_t (*)(uintptr_t glue, uintptr_t prevFp, uint3 V(LdBigInt) \ V(NewLexicalEnvWithNameDyn) \ V(GetAotUnmapedArgs) \ + V(GetAotUnmapedArgsWithRestArgs) \ V(CopyAotRestArgs) \ V(NotifyBytecodePcChanged) \ V(GetAotLexicalEnv) \ V(NewAotLexicalEnvDyn) \ V(NewAotLexicalEnvWithNameDyn) \ V(SuspendAotGenerator) \ - V(NewAotObjDynRange) + V(NewAotObjDynRange) \ + V(GetTypeArrayPropertyByIndex) \ + V(SetTypeArrayPropertyByIndex) \ + V(AotNewObjWithIHClass) \ + V(PopAotLexicalEnv) \ + V(LdAotLexVarDyn) \ + V(StAotLexVarDyn) #define RUNTIME_STUB_LIST(V) \ RUNTIME_ASM_STUB_LIST(V) \ @@ -461,15 +469,26 @@ private: static inline JSTaggedValue RuntimeThrowSyntaxError(JSThread *thread, const char *message); static inline JSTaggedValue RuntimeLdBigInt(JSThread *thread, const JSHandle &numberBigInt); static inline JSTaggedValue RuntimeNewLexicalEnvWithNameDyn(JSThread *thread, uint16_t numVars, uint16_t scopeId); - static inline JSTaggedValue RuntimeGetAotUnmapedArgs(JSThread *thread, uint32_t actualNumArgs, uintptr_t argv); + static inline JSTaggedValue RuntimeGetAotUnmapedArgs(JSThread *thread, uint32_t actualNumArgs); + static inline JSTaggedValue RuntimeGetAotUnmapedArgsWithRestArgs(JSThread *thread, uint32_t actualNumArgs); + static inline JSTaggedValue RuntimeGetUnmapedJSArgumentObj(JSThread *thread, + const JSHandle &argumentsList); static inline JSTaggedValue RuntimeNewAotLexicalEnvDyn(JSThread *thread, uint16_t numVars, JSHandle ¤tLexEnv); static inline JSTaggedValue RuntimeNewAotLexicalEnvWithNameDyn(JSThread *thread, uint16_t numVars, uint16_t scopeId, - JSHandle ¤tLexEnv); - static inline JSTaggedValue RuntimeCopyAotRestArgs(JSThread *thread, uint32_t restNumArgs, uintptr_t argv); + JSHandle ¤tLexEnv, + JSHandle &func); + static inline JSTaggedValue RuntimeCopyAotRestArgs(JSThread *thread, uint32_t actualArgc, uint32_t restIndex); static inline JSTaggedValue RuntimeSuspendAotGenerator(JSThread *thread, const JSHandle &genObj, const JSHandle &value); static inline JSTaggedValue RuntimeNewAotObjDynRange(JSThread *thread, uintptr_t argv, uint32_t argc); + + static inline JSTaggedValue RuntimeAotNewObjWithIHClass(JSThread *thread, uintptr_t argv, uint32_t argc); + static inline JSTaggedValue RuntimeGetAotLexEnv(JSThread *thread); + static inline void RuntimeSetAotLexEnv(JSThread *thread, JSTaggedValue lexEnv); + static inline JSTaggedValue RuntimeGenerateAotScopeInfo(JSThread *thread, uint16_t scopeId, JSTaggedValue func); + static inline JSTaggedType *GetActualArgv(JSThread *thread); + static inline OptimizedJSFunctionFrame *GetOptimizedJSFunctionFrame(JSThread *thread); }; } // namespace panda::ecmascript #endif diff --git a/ecmascript/symbol_table.h b/ecmascript/symbol_table.h index 3f9b0eb2979ea088d00a1b6bbc0ce53b59fc5318..5681c4a91ea22067b5f5da9e22e7e3ac8b93cdc9 100644 --- a/ecmascript/symbol_table.h +++ b/ecmascript/symbol_table.h @@ -27,7 +27,7 @@ namespace panda::ecmascript { class SymbolTable : public TaggedHashTable { public: using HashTable = TaggedHashTable; - static SymbolTable *Cast(ObjectHeader *object) + static SymbolTable *Cast(TaggedObject *object) { return reinterpret_cast(object); } diff --git a/ecmascript/tagged_array.h b/ecmascript/tagged_array.h index c2d4a85ef0e2434e735fa0b678f62f1287d994f5..8a4f3f825346d691f19118233592cf41166c1e76 100644 --- a/ecmascript/tagged_array.h +++ b/ecmascript/tagged_array.h @@ -28,7 +28,7 @@ public: static constexpr uint32_t MAX_ARRAY_INDEX = std::numeric_limits::max(); static constexpr uint32_t MAX_END_UNUSED = 4; - inline static TaggedArray *Cast(ObjectHeader *obj) + inline static TaggedArray *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsTaggedArray()); return static_cast(obj); diff --git a/ecmascript/tagged_list.cpp b/ecmascript/tagged_list.cpp index 33e4d5f2609eb30a725dc71b51cb445861bc17d0..e01ef7bc4006986f16dcf3cb7912c3e5e4dbb78a 100644 --- a/ecmascript/tagged_list.cpp +++ b/ecmascript/tagged_list.cpp @@ -361,10 +361,11 @@ JSTaggedValue TaggedSingleList::ReplaceAllElements(JSThread *thread, const JSHan for (int k = 0; k < length; k++) { JSTaggedValue kValue = taggedList->Get(k); JSTaggedValue key = JSTaggedValue(k); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, callbackFn, thisArg, undefined, 3); // 3:three args - info.SetCallArg(kValue, key, thisHandle.GetTaggedValue()); - JSTaggedValue funcResult = JSFunction::Call(&info); + RETURN_EXCEPTION_IF_ABRUPT_COMPLETION(thread); + info->SetCallArg(kValue, key, thisHandle.GetTaggedValue()); + JSTaggedValue funcResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, funcResult); JSHandle funcResultValue = JSHandle(thread, funcResult); TaggedSingleList::Set(thread, taggedList, k, funcResultValue); @@ -682,4 +683,4 @@ int TaggedDoubleList::FindPrevNodeByValueAtLast(const JSTaggedValue &element) } return -1; } -} // namespace panda::ecmascript +} // namespace panda::ecmascript \ No newline at end of file diff --git a/ecmascript/tagged_list.h b/ecmascript/tagged_list.h index e508a94fb39b4fd297723fbc7b579a5d8d199721..43c4d031792c6d1c20fe497792df2d213279cae2 100644 --- a/ecmascript/tagged_list.h +++ b/ecmascript/tagged_list.h @@ -113,7 +113,7 @@ public: class TaggedSingleList : public TaggedList { public: static const int ENTRY_SIZE = 2; - static TaggedSingleList *Cast(ObjectHeader *obj) + static TaggedSingleList *Cast(TaggedObject *obj) { return static_cast(obj); } @@ -152,7 +152,7 @@ public: class TaggedDoubleList : public TaggedList { public: static const int ENTRY_SIZE = 3; - static TaggedDoubleList *Cast(ObjectHeader *obj) + static TaggedDoubleList *Cast(TaggedObject *obj) { return static_cast(obj); } @@ -191,4 +191,4 @@ protected: inline JSTaggedValue FindElementByIndexAtLast(int index) const; }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_TAGGED_LIST_H +#endif // ECMASCRIPT_TAGGED_LIST_H \ No newline at end of file diff --git a/ecmascript/tagged_queue.h b/ecmascript/tagged_queue.h index f880bb517aab36e72b803556af38bb6372848a8d..6c8728734cef96213239cd79f12b808f8dc45618 100644 --- a/ecmascript/tagged_queue.h +++ b/ecmascript/tagged_queue.h @@ -24,7 +24,7 @@ namespace panda::ecmascript { class TaggedQueue : public TaggedArray { public: - static TaggedQueue *Cast(ObjectHeader *object) + static TaggedQueue *Cast(TaggedObject *object) { return reinterpret_cast(object); } @@ -37,6 +37,7 @@ public: uint32_t start = GetStart().GetArrayLength(); JSTaggedValue value = Get(start); + Set(thread, start, JSTaggedValue::Hole()); uint32_t capacity = GetCapacity().GetArrayLength(); ASSERT(capacity != 0); @@ -202,4 +203,4 @@ private: } }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_TAGGED_QUEUE_H \ No newline at end of file +#endif // ECMASCRIPT_TAGGED_QUEUE_H diff --git a/ecmascript/tagged_tree.h b/ecmascript/tagged_tree.h index 5c2722a1ec4591aeb993be4f7a1d34821a9db3f5..61117ef81d0d0a47342e7c1bcc4bd52c27c35894 100644 --- a/ecmascript/tagged_tree.h +++ b/ecmascript/tagged_tree.h @@ -142,12 +142,13 @@ public: JSHandle compareFn(thread, fn); JSHandle thisArgHandle = thread->GlobalConstants()->GetHandledUndefined(); - const size_t argsLength = 2; + const int32_t argsLength = 2; JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, compareFn, thisArgHandle, undefined, argsLength); - info.SetCallArg(valueX.GetTaggedValue(), valueY.GetTaggedValue()); - JSTaggedValue callResult = JSFunction::Call(&info); + RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); + info->SetCallArg(valueX.GetTaggedValue(), valueY.GetTaggedValue()); + JSTaggedValue callResult = JSFunction::Call(info); RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED); int compareResult = 0; if (callResult.IsInt()) { @@ -453,7 +454,7 @@ protected: class TaggedTreeMap : public TaggedTree { public: using RBTree = TaggedTree; - static TaggedTreeMap *Cast(ObjectHeader *obj) + static TaggedTreeMap *Cast(TaggedObject *obj) { return static_cast(obj); } @@ -521,7 +522,7 @@ public: class TaggedTreeSet : public TaggedTree { public: using RBTree = TaggedTree; - static TaggedTreeSet *Cast(ObjectHeader *obj) + static TaggedTreeSet *Cast(TaggedObject *obj) { return static_cast(obj); } diff --git a/ecmascript/template_map.h b/ecmascript/template_map.h index c40ed4da1f4a503a407a0a5733e6b8fccb90df69..c0309bbbc5c73393aaaefcd584f939e48af8fedf 100644 --- a/ecmascript/template_map.h +++ b/ecmascript/template_map.h @@ -30,7 +30,7 @@ public: static inline int Hash(const JSTaggedValue &obj) { ASSERT(obj.IsJSArray()); - JSArray *array = JSArray::Cast(obj.GetHeapObject()); + JSArray *array = JSArray::Cast(obj.GetTaggedObject()); uint32_t len = array->GetArrayLength(); return len; } @@ -50,7 +50,7 @@ public: { return ENTRY_SIZE; } - static TemplateMap *Cast(ObjectHeader *object) + static TemplateMap *Cast(TaggedObject *object) { return reinterpret_cast(object); } diff --git a/ecmascript/tests/BUILD.gn b/ecmascript/tests/BUILD.gn index 4661b25dd4eefcced6658dfc23ad040566a578c0..fd40a343e2b0738ca4a63392cee1166af6b97a71 100644 --- a/ecmascript/tests/BUILD.gn +++ b/ecmascript/tests/BUILD.gn @@ -17,7 +17,7 @@ import("//build/test.gni") module_output_path = "ark/js_runtime" -host_unittest_action("EcmaVmTest") { +host_unittest_action("EcmaVm_001_Test") { module_out_path = module_output_path sources = [ @@ -40,6 +40,8 @@ host_unittest_action("EcmaVmTest") { "js_api_arraylist_test.cpp", "js_api_deque_iterator_test.cpp", "js_api_deque_test.cpp", + "js_api_lightweightmap_test.cpp", + "js_api_lightweightset_test.cpp", "js_api_linked_list_test.cpp", "js_api_list_test.cpp", "js_api_plain_array_test.cpp", @@ -56,23 +58,46 @@ host_unittest_action("EcmaVmTest") { "js_array_buffer_test.cpp", "js_array_iterator_test.cpp", "js_array_test.cpp", + "js_async_function_test.cpp", "js_bigint_test.cpp", + ] + + configs = [ "//ark/js_runtime:ecma_test_config" ] + + deps = [ + "$ark_root/libpandabase:libarkbase", + "//ark/js_runtime:libark_jsruntime_test", + sdk_libc_secshared_dep, + ] +} + +host_unittest_action("EcmaVm_002_Test") { + module_out_path = module_output_path + + sources = [ + # test file "js_collator_test.cpp", "js_dataview_test.cpp", "js_date_test.cpp", "js_date_time_format_test.cpp", "js_displaynames_test.cpp", + "js_finalization_registry_test.cpp", "js_forin_iterator_test.cpp", "js_function_test.cpp", + "js_generator_object_test.cpp", "js_handle_test.cpp", + "js_hclass_test.cpp", "js_iterator_test.cpp", + "js_list_format_test.cpp", "js_locale_test.cpp", "js_map_test.cpp", + "js_number_format_test.cpp", "js_object_test.cpp", "js_primitive_ref_test.cpp", "js_promise_test.cpp", "js_proxy_test.cpp", "js_serializer_test.cpp", + "js_set_iterator_test.cpp", "js_set_test.cpp", "js_symbol_test.cpp", "js_tagged_queue_test.cpp", @@ -85,6 +110,7 @@ host_unittest_action("EcmaVmTest") { "native_pointer_test.cpp", "object_factory_test.cpp", "object_operator_test.cpp", + "read_only_space_test.cpp", "symbol_table_test.cpp", "tagged_tree_test.cpp", "tagged_value_test.cpp", @@ -110,12 +136,18 @@ group("unittest") { testonly = true # deps file - deps = [ ":EcmaVmTest" ] + deps = [ + ":EcmaVm_001_Test", + ":EcmaVm_002_Test", + ] } group("host_unittest") { testonly = true # deps file - deps = [ ":EcmaVmTestAction" ] + deps = [ + ":EcmaVm_001_TestAction", + ":EcmaVm_002_TestAction", + ] } diff --git a/ecmascript/tests/accessor_data_test.cpp b/ecmascript/tests/accessor_data_test.cpp index df8cfb90ae027a296c14ae6cc3bb562bd2914d34..555cff45e9d92984f1736809e456742389a4a5b4 100644 --- a/ecmascript/tests/accessor_data_test.cpp +++ b/ecmascript/tests/accessor_data_test.cpp @@ -51,7 +51,7 @@ public: /** * @tc.name: Cast - * @tc.desc: Convert an object of type ObjectHeader to type AccessorData object. + * @tc.desc: Convert an object of type TaggedObject to type AccessorData object. * @tc.type: FUNC * @tc.require: */ @@ -62,7 +62,7 @@ HWTEST_F_L0(AccessorDataTest, AccessorData_Cast) JSHandle accDynclassHandle = factory->NewEcmaDynClass(JSObject::SIZE, JSType::ACCESSOR_DATA, nullHandle); - ObjectHeader *accObject = factory->NewDynObject(accDynclassHandle); + TaggedObject *accObject = factory->NewDynObject(accDynclassHandle); AccessorData::Cast(accObject)->SetGetter(thread, JSTaggedValue::Undefined()); AccessorData::Cast(accObject)->SetSetter(thread, JSTaggedValue::Undefined()); EXPECT_TRUE(JSTaggedValue(accObject).IsAccessorData()); @@ -71,7 +71,7 @@ HWTEST_F_L0(AccessorDataTest, AccessorData_Cast) JSHandle internalAccDynClassHandle = factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullHandle); - ObjectHeader *internalAccObject = factory->NewDynObject(internalAccDynClassHandle); + TaggedObject *internalAccObject = factory->NewDynObject(internalAccDynClassHandle); EXPECT_TRUE(JSTaggedValue(internalAccObject).IsInternalAccessor()); AccessorData *internalAcc = AccessorData::Cast(internalAccObject); EXPECT_TRUE(JSTaggedValue(internalAcc).IsInternalAccessor()); @@ -96,7 +96,7 @@ HWTEST_F_L0(AccessorDataTest, IsInternal) JSHandle nullHandle(thread, JSTaggedValue::Null()); JSHandle accDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::ACCESSOR_DATA, nullHandle); - ObjectHeader *accObject = factory->NewDynObject(accDynclass); + TaggedObject *accObject = factory->NewDynObject(accDynclass); AccessorData *acc = AccessorData::Cast(accObject); acc->SetGetter(thread, JSTaggedValue::Undefined()); acc->SetSetter(thread, JSTaggedValue::Undefined()); @@ -104,7 +104,7 @@ HWTEST_F_L0(AccessorDataTest, IsInternal) JSHandle internalAccDynClass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullHandle); - ObjectHeader *internalAccObject = factory->NewDynObject(internalAccDynClass); + TaggedObject *internalAccObject = factory->NewDynObject(internalAccDynClass); AccessorData *internalAcc = AccessorData::Cast(internalAccObject); EXPECT_EQ(internalAcc->IsInternal(), true); } @@ -142,7 +142,7 @@ HWTEST_F_L0(AccessorDataTest, HasSetter) // 3.Create normal AccessorData object from dynamic class. JSHandle nullHandle(thread, JSTaggedValue::Null()); JSHandle accDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::ACCESSOR_DATA, nullHandle); - ObjectHeader *accObject = factory->NewDynObject(accDynclass); + TaggedObject *accObject = factory->NewDynObject(accDynclass); AccessorData *acc = AccessorData::Cast(accObject); acc->SetGetter(thread, JSTaggedValue::Undefined()); EXPECT_EQ(acc->HasSetter(), true); @@ -154,7 +154,7 @@ HWTEST_F_L0(AccessorDataTest, HasSetter) // 4.Create internal AccessorData object from dynamic class. JSHandle internalAccDynClass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::INTERNAL_ACCESSOR, nullHandle); - ObjectHeader *internalAccObject = factory->NewDynObject(internalAccDynClass); + TaggedObject *internalAccObject = factory->NewDynObject(internalAccDynClass); AccessorData *internalAcc = AccessorData::Cast(internalAccObject); EXPECT_EQ(internalAcc->HasSetter(), true); internalAcc->SetSetter(thread, JSTaggedValue::Undefined()); @@ -208,7 +208,7 @@ HWTEST_F_L0(AccessorDataTest, CallInternalSet) /** * @tc.name: Cast - * @tc.desc: Convert an object of type ObjectHeader to type CompletionRecord object. + * @tc.desc: Convert an object of type TaggedObject to type CompletionRecord object. * @tc.type: FUNC * @tc.require: */ @@ -219,7 +219,7 @@ HWTEST_F_L0(AccessorDataTest, CompletionRecord_Cast) JSHandle comRecordDynclassHandle = factory->NewEcmaDynClass(JSObject::SIZE, JSType::COMPLETION_RECORD, nullHandle); - ObjectHeader *comRecordObject = factory->NewDynObject(comRecordDynclassHandle); + TaggedObject *comRecordObject = factory->NewDynObject(comRecordDynclassHandle); EXPECT_TRUE(JSTaggedValue(comRecordObject).IsCompletionRecord()); CompletionRecord *comRecord = CompletionRecord::Cast(comRecordObject); EXPECT_TRUE(JSTaggedValue(comRecord).IsCompletionRecord()); diff --git a/ecmascript/tests/concurrent_sweep_test.cpp b/ecmascript/tests/concurrent_sweep_test.cpp index fa404f1b098056236afe051b6cba830c1131bcc9..3f64f3dc702b3fa71a872536053618b160cbd7c3 100644 --- a/ecmascript/tests/concurrent_sweep_test.cpp +++ b/ecmascript/tests/concurrent_sweep_test.cpp @@ -58,6 +58,6 @@ TEST_F(ConcurrentSweepTest, ConcurrentSweep) } JSHandle test2(thread, EcmaString::CreateFromUtf8(utf8, 4, vm, true)); ASSERT_EQ(test1->GetLength(), 4U); - ASSERT_NE(test1.GetTaggedValue().GetHeapObject(), test2.GetTaggedValue().GetHeapObject()); + ASSERT_NE(test1.GetTaggedValue().GetTaggedObject(), test2.GetTaggedValue().GetTaggedObject()); } } // namespace panda::test diff --git a/ecmascript/tests/dump_test.cpp b/ecmascript/tests/dump_test.cpp index 174fd3d5b1089276c41ee86344e59b5a33153493..fcf3578fd178d87a317d82222f9ccb9191bdd34e 100644 --- a/ecmascript/tests/dump_test.cpp +++ b/ecmascript/tests/dump_test.cpp @@ -33,6 +33,10 @@ #include "ecmascript/js_api_arraylist_iterator.h" #include "ecmascript/js_api_deque.h" #include "ecmascript/js_api_deque_iterator.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/js_api_lightweightset_iterator.h" #include "ecmascript/js_api_linked_list.h" #include "ecmascript/js_api_linked_list_iterator.h" #include "ecmascript/js_api_list.h" @@ -112,6 +116,11 @@ using namespace panda::ecmascript; using namespace panda::ecmascript::base; +// NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#define CHECK_DUMP_FIELDS(begin, end, num); \ + LOG_ECMA_IF((num) != ((end) - (begin)) / JSTaggedValue::TaggedTypeSize(), FATAL) \ + << "Fields in obj are not in dump list. " + namespace panda::test { class EcmaDumpTest : public testing::Test { public: @@ -271,11 +280,51 @@ static JSHandle NewJSRegExp(JSThread *thread, ObjectFactory *factory, JSHandle jSRegExp = JSHandle::Cast(factory->NewJSObject(jSRegExpClass)); jSRegExp->SetByteCodeBuffer(thread, JSTaggedValue::Undefined()); jSRegExp->SetOriginalSource(thread, JSTaggedValue::Undefined()); + jSRegExp->SetGroupName(thread, JSTaggedValue::Undefined()); jSRegExp->SetOriginalFlags(thread, JSTaggedValue(0)); jSRegExp->SetLength(0); return jSRegExp; } +static JSHandle NewJSAPILightWeightMap(JSThread *thread, ObjectFactory *factory) +{ + auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle proto = globalEnv->GetObjectFunctionPrototype(); + JSHandle lwmapClass = + factory->NewEcmaDynClass(JSAPILightWeightMap::SIZE, JSType::JS_API_LIGHT_WEIGHT_MAP, proto); + JSHandle jSAPILightWeightMap = + JSHandle::Cast(factory->NewJSObjectWithInit(lwmapClass)); + JSHandle hashArray = + JSHandle(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH)); + JSHandle keyArray = + JSHandle(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH)); + JSHandle valueArray = + JSHandle(factory->NewTaggedArray(JSAPILightWeightMap::DEFAULT_CAPACITY_LENGTH)); + jSAPILightWeightMap->SetHashes(thread, hashArray); + jSAPILightWeightMap->SetKeys(thread, keyArray); + jSAPILightWeightMap->SetValues(thread, valueArray); + jSAPILightWeightMap->SetLength(0); + return jSAPILightWeightMap; +} + +static JSHandle NewJSAPILightWeightSet(JSThread *thread, ObjectFactory *factory) +{ + auto globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle proto = globalEnv->GetObjectFunctionPrototype(); + JSHandle setClass = + factory->NewEcmaDynClass(JSAPILightWeightSet::SIZE, JSType::JS_API_LIGHT_WEIGHT_SET, proto); + JSHandle jSAPILightWeightSet = + JSHandle::Cast(factory->NewJSObjectWithInit(setClass)); + JSHandle hashes = + JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH); + JSHandle values = + JSAPILightWeightSet::CreateSlot(thread, JSAPILightWeightSet::DEFAULT_CAPACITY_LENGTH); + jSAPILightWeightSet->SetHashes(thread, hashes); + jSAPILightWeightSet->SetValues(thread, values); + jSAPILightWeightSet->SetLength(0); + return jSAPILightWeightSet; +} + static JSHandle NewJSAPIQueue(JSThread *thread, ObjectFactory *factory, JSHandle proto) { JSHandle queueClass = factory->NewEcmaDynClass(JSAPIQueue::SIZE, JSType::JS_API_QUEUE, proto); @@ -334,37 +383,39 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) case JSType::JS_EVAL_ERROR: case JSType::JS_RANGE_ERROR: case JSType::JS_TYPE_ERROR: + case JSType::JS_AGGREGATE_ERROR: case JSType::JS_REFERENCE_ERROR: case JSType::JS_URI_ERROR: + case JSType::JS_ARGUMENTS: case JSType::JS_SYNTAX_ERROR: case JSType::JS_OBJECT: { - CHECK_DUMP_FIELDS(ECMAObject::SIZE, JSObject::SIZE, 2U) + CHECK_DUMP_FIELDS(ECMAObject::SIZE, JSObject::SIZE, 2U); JSHandle jsObj = NewJSObject(thread, factory, globalEnv); DUMP_FOR_HANDLE(jsObj) break; } case JSType::JS_REALM: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSRealm::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSRealm::SIZE, 2U); JSHandle jsRealm = factory->NewJSRealm(); DUMP_FOR_HANDLE(jsRealm) break; } case JSType::JS_FUNCTION_BASE: { #ifdef PANDA_TARGET_64 - CHECK_DUMP_FIELDS(JSObject::SIZE, JSFunctionBase::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSFunctionBase::SIZE, 2U); #else - CHECK_DUMP_FIELDS(JSObject::SIZE, JSFunctionBase::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSFunctionBase::SIZE, 1U); #endif break; } case JSType::JS_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 8U) + CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSFunction::SIZE, 8U); JSHandle jsFunc = globalEnv->GetFunctionFunction(); DUMP_FOR_HANDLE(jsFunc) break; } case JSType::JS_PROXY_REVOC_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSProxyRevocFunction::SIZE, 1U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSProxyRevocFunction::SIZE, 1U); JSHandle proxyRevocClass = JSHandle::Cast(globalEnv->GetProxyRevocFunctionClass()); JSHandle proxyRevocFunc = factory->NewJSObjectWithInit(proxyRevocClass); @@ -372,7 +423,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_PROMISE_REACTIONS_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseReactionsFunction::SIZE, 2U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseReactionsFunction::SIZE, 2U); JSHandle promiseReactClass = JSHandle::Cast(globalEnv->GetPromiseReactionFunctionClass()); JSHandle promiseReactFunc = factory->NewJSObjectWithInit(promiseReactClass); @@ -380,7 +431,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_PROMISE_EXECUTOR_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseExecutorFunction::SIZE, 1U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseExecutorFunction::SIZE, 1U); JSHandle promiseExeClass = JSHandle::Cast(globalEnv->GetPromiseExecutorFunctionClass()); JSHandle promiseExeFunc = factory->NewJSObjectWithInit(promiseExeClass); @@ -388,59 +439,91 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_PROMISE_ALL_RESOLVE_ELEMENT_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAllResolveElementFunction::SIZE, 5U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAllResolveElementFunction::SIZE, 5U); JSHandle promiseAllClass = JSHandle::Cast(globalEnv->GetPromiseAllResolveElementFunctionClass()); JSHandle promiseAllFunc = factory->NewJSObjectWithInit(promiseAllClass); DUMP_FOR_HANDLE(promiseAllFunc) break; } + case JSType::JS_PROMISE_ANY_REJECT_ELEMENT_FUNCTION: { + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAnyRejectElementFunction::SIZE, 5U); + JSHandle promiseAnyClass = + JSHandle::Cast(globalEnv->GetPromiseAnyRejectElementFunctionClass()); + JSHandle promiseAnyFunc = factory->NewJSObjectWithInit(promiseAnyClass); + DUMP_FOR_HANDLE(promiseAnyFunc) + break; + } + case JSType::JS_PROMISE_ALL_SETTLED_ELEMENT_FUNCTION: { + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseAllSettledElementFunction::SIZE, 5U); + JSHandle promiseAllSettledClass = + JSHandle::Cast(globalEnv->GetPromiseAllSettledElementFunctionClass()); + JSHandle promiseAllSettledFunc = factory->NewJSObjectWithInit(promiseAllSettledClass); + DUMP_FOR_HANDLE(promiseAllSettledFunc) + break; + } + case JSType::JS_PROMISE_FINALLY_FUNCTION: { + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseFinallyFunction::SIZE, 2U); + JSHandle promiseFinallyClass = + JSHandle::Cast(globalEnv->GetPromiseFinallyFunctionClass()); + JSHandle promiseFinallyFunc = factory->NewJSObjectWithInit(promiseFinallyClass); + DUMP_FOR_HANDLE(promiseFinallyFunc) + break; + } + case JSType::JS_PROMISE_VALUE_THUNK_OR_THROWER_FUNCTION: { + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSPromiseValueThunkOrThrowerFunction::SIZE, 1U); + JSHandle promiseValueClass = + JSHandle::Cast(globalEnv->GetPromiseValueThunkOrThrowerFunctionClass()); + JSHandle promiseValueFunc = factory->NewJSObjectWithInit(promiseValueClass); + DUMP_FOR_HANDLE(promiseValueFunc) + break; + } case JSType::JS_GENERATOR_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSGeneratorFunction::SIZE, 0U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSGeneratorFunction::SIZE, 0U); break; } case JSType::JS_ASYNC_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncFunction::SIZE, 0U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncFunction::SIZE, 0U); break; } case JSType::JS_INTL_BOUND_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSIntlBoundFunction::SIZE, 3U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSIntlBoundFunction::SIZE, 3U); JSHandle intlBoundFunc = factory->NewJSIntlBoundFunction( MethodIndex::BUILTINS_NUMBER_FORMAT_NUMBER_FORMAT_INTERNAL_FORMAT_NUMBER); DUMP_FOR_HANDLE(intlBoundFunc) break; } case JSType::JS_ASYNC_AWAIT_STATUS_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncAwaitStatusFunction::SIZE, 1U) + CHECK_DUMP_FIELDS(JSFunction::SIZE, JSAsyncAwaitStatusFunction::SIZE, 1U); JSHandle asyncAwaitFunc = factory->NewJSAsyncAwaitStatusFunction( MethodIndex::BUILTINS_PROMISE_HANDLER_ASYNC_AWAIT_FULFILLED); DUMP_FOR_HANDLE(asyncAwaitFunc) break; } case JSType::JS_BOUND_FUNCTION: { - CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSBoundFunction::SIZE, 3U) + CHECK_DUMP_FIELDS(JSFunctionBase::SIZE, JSBoundFunction::SIZE, 3U); NEW_OBJECT_AND_DUMP(JSBoundFunction, JS_BOUND_FUNCTION) break; } case JSType::JS_REG_EXP: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSRegExp::SIZE, 4U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSRegExp::SIZE, 5U); NEW_OBJECT_AND_DUMP(JSRegExp, JS_REG_EXP) break; } case JSType::JS_SET: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSSet::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSSet::SIZE, 1U); JSHandle jsSet = NewJSSet(thread, factory, proto); DUMP_FOR_HANDLE(jsSet) break; } case JSType::JS_MAP: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSMap::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSMap::SIZE, 1U); JSHandle jsMap = NewJSMap(thread, factory, proto); DUMP_FOR_HANDLE(jsMap) break; } case JSType::JS_WEAK_MAP: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakMap::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakMap::SIZE, 1U); JSHandle weakMapClass = factory->NewEcmaDynClass(JSWeakMap::SIZE, JSType::JS_WEAK_MAP, proto); JSHandle jsWeakMap = JSHandle::Cast(factory->NewJSObjectWithInit(weakMapClass)); JSHandle weakLinkedMap(LinkedHashMap::Create(thread)); @@ -449,7 +532,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_WEAK_SET: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakSet::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakSet::SIZE, 1U); JSHandle weakSetClass = factory->NewEcmaDynClass(JSWeakSet::SIZE, JSType::JS_WEAK_SET, proto); JSHandle jsWeakSet = JSHandle::Cast(factory->NewJSObjectWithInit(weakSetClass)); JSHandle weakLinkedSet(LinkedHashSet::Create(thread)); @@ -458,7 +541,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_WEAK_REF: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakRef::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSWeakRef::SIZE, 1U); JSHandle weakRefClass = factory->NewEcmaDynClass(JSWeakRef::SIZE, JSType::JS_WEAK_REF, proto); JSHandle jsWeakRef = JSHandle::Cast(factory->NewJSObjectWithInit(weakRefClass)); jsWeakRef->SetWeakObject(thread, JSTaggedValue::Undefined()); @@ -466,7 +549,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_FINALIZATION_REGISTRY: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSFinalizationRegistry::SIZE, 5U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSFinalizationRegistry::SIZE, 5U); JSHandle finalizationRegistryClass = factory->NewEcmaDynClass(JSFinalizationRegistry::SIZE, JSType::JS_FINALIZATION_REGISTRY, proto); JSHandle jsFinalizationRegistry = @@ -477,13 +560,13 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::CELL_RECORD: { - CHECK_DUMP_FIELDS(Record::SIZE, CellRecord::SIZE, 2U) + CHECK_DUMP_FIELDS(Record::SIZE, CellRecord::SIZE, 2U); JSHandle cellRecord = factory->NewCellRecord(); DUMP_FOR_HANDLE(cellRecord) break; } case JSType::JS_DATE: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSDate::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSDate::SIZE, 2U); JSHandle dateClass = factory->NewEcmaDynClass(JSDate::SIZE, JSType::JS_DATE, proto); JSHandle date = JSHandle::Cast(factory->NewJSObjectWithInit(dateClass)); date->SetTimeValue(thread, JSTaggedValue(0.0)); @@ -491,32 +574,29 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) DUMP_FOR_HANDLE(date) break; } - case JSType::JS_ITERATOR: - // JS Iterate is a tool class, so we don't need to check it. - break; case JSType::JS_FORIN_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSForInIterator::SIZE, 4U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSForInIterator::SIZE, 4U); JSHandle array(thread, factory->NewJSArray().GetTaggedValue()); JSHandle forInIter = factory->NewJSForinIterator(array); DUMP_FOR_HANDLE(forInIter) break; } case JSType::JS_MAP_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSMapIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSMapIterator::SIZE, 2U); JSHandle jsMapIter = factory->NewJSMapIterator(NewJSMap(thread, factory, proto), IterationKind::KEY); DUMP_FOR_HANDLE(jsMapIter) break; } case JSType::JS_SET_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSSetIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSSetIterator::SIZE, 2U); JSHandle jsSetIter = factory->NewJSSetIterator(NewJSSet(thread, factory, proto), IterationKind::KEY); DUMP_FOR_HANDLE(jsSetIter) break; } case JSType::JS_REG_EXP_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSRegExpIterator::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSRegExpIterator::SIZE, 3U); JSHandle emptyString(thread->GlobalConstants()->GetHandledEmptyString()); JSHandle jsRegExp(NewJSRegExp(thread, factory, proto)); JSHandle jsRegExpIter = @@ -525,97 +605,92 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_ARRAY_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayIterator::SIZE, 2U); JSHandle arrayIter = factory->NewJSArrayIterator(JSHandle::Cast(factory->NewJSArray()), IterationKind::KEY); DUMP_FOR_HANDLE(arrayIter) break; } case JSType::JS_STRING_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSStringIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSStringIterator::SIZE, 2U); JSHandle stringIter = globalEnv->GetStringIterator(); DUMP_FOR_HANDLE(stringIter) break; } case JSType::JS_INTL: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSIntl::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSIntl::SIZE, 1U); NEW_OBJECT_AND_DUMP(JSIntl, JS_INTL) break; } case JSType::JS_LOCALE: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSLocale::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSLocale::SIZE, 1U); NEW_OBJECT_AND_DUMP(JSLocale, JS_LOCALE) break; } case JSType::JS_DATE_TIME_FORMAT: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSDateTimeFormat::SIZE, 9U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSDateTimeFormat::SIZE, 9U); NEW_OBJECT_AND_DUMP(JSDateTimeFormat, JS_DATE_TIME_FORMAT) break; } case JSType::JS_RELATIVE_TIME_FORMAT: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSRelativeTimeFormat::SIZE, 6U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSRelativeTimeFormat::SIZE, 6U); NEW_OBJECT_AND_DUMP(JSRelativeTimeFormat, JS_RELATIVE_TIME_FORMAT) break; } case JSType::JS_NUMBER_FORMAT: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSNumberFormat::SIZE, 13U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSNumberFormat::SIZE, 13U); NEW_OBJECT_AND_DUMP(JSNumberFormat, JS_NUMBER_FORMAT) break; } case JSType::JS_COLLATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSCollator::SIZE, 5U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSCollator::SIZE, 5U); NEW_OBJECT_AND_DUMP(JSCollator, JS_COLLATOR) break; } case JSType::JS_PLURAL_RULES: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSPluralRules::SIZE, 10U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSPluralRules::SIZE, 10U); NEW_OBJECT_AND_DUMP(JSPluralRules, JS_PLURAL_RULES) break; } case JSType::JS_DISPLAYNAMES: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSDisplayNames::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSDisplayNames::SIZE, 3U); NEW_OBJECT_AND_DUMP(JSDisplayNames, JS_DISPLAYNAMES) break; } case JSType::JS_LIST_FORMAT: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSListFormat::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSListFormat::SIZE, 3U); NEW_OBJECT_AND_DUMP(JSListFormat, JS_LIST_FORMAT) break; } case JSType::JS_SHARED_ARRAY_BUFFER: case JSType::JS_ARRAY_BUFFER: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayBuffer::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSArrayBuffer::SIZE, 2U); NEW_OBJECT_AND_DUMP(JSArrayBuffer, JS_ARRAY_BUFFER) break; } case JSType::JS_PROMISE: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSPromise::SIZE, 4U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSPromise::SIZE, 4U); NEW_OBJECT_AND_DUMP(JSPromise, JS_PROMISE) break; } case JSType::JS_DATA_VIEW: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSDataView::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSDataView::SIZE, 3U); NEW_OBJECT_AND_DUMP(JSDataView, JS_DATA_VIEW) break; } - case JSType::JS_ARGUMENTS: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSArguments::SIZE, 1U) - NEW_OBJECT_AND_DUMP(JSArguments, JS_ARGUMENTS) - break; - } case JSType::JS_GENERATOR_OBJECT: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSGeneratorObject::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSGeneratorObject::SIZE, 3U); NEW_OBJECT_AND_DUMP(JSGeneratorObject, JS_GENERATOR_OBJECT) break; } case JSType::JS_ASYNC_FUNC_OBJECT: { - CHECK_DUMP_FIELDS(JSGeneratorObject::SIZE, JSAsyncFuncObject::SIZE, 1U) + CHECK_DUMP_FIELDS(JSGeneratorObject::SIZE, JSAsyncFuncObject::SIZE, 1U); JSHandle asyncFuncObject = factory->NewJSAsyncFuncObject(); DUMP_FOR_HANDLE(asyncFuncObject) break; } case JSType::JS_ARRAY: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSArray::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSArray::SIZE, 1U); JSHandle jsArray = factory->NewJSArray(); DUMP_FOR_HANDLE(jsArray) break; @@ -632,30 +707,30 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) case JSType::JS_FLOAT64_ARRAY: case JSType::JS_BIGINT64_ARRAY: case JSType::JS_BIGUINT64_ARRAY: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSTypedArray::SIZE, 4U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSTypedArray::SIZE, 4U); NEW_OBJECT_AND_DUMP(JSTypedArray, JS_TYPED_ARRAY) break; } case JSType::JS_PRIMITIVE_REF: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSPrimitiveRef::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSPrimitiveRef::SIZE, 1U); NEW_OBJECT_AND_DUMP(JSPrimitiveRef, JS_PRIMITIVE_REF) break; } case JSType::JS_GLOBAL_OBJECT: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSGlobalObject::SIZE, 0U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSGlobalObject::SIZE, 0U); JSHandle globalObject = globalEnv->GetJSGlobalObject(); DUMP_FOR_HANDLE(globalObject) break; } case JSType::JS_PROXY: { - CHECK_DUMP_FIELDS(ECMAObject::SIZE, JSProxy::SIZE, 3U) + CHECK_DUMP_FIELDS(ECMAObject::SIZE, JSProxy::SIZE, 3U); JSHandle emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue()); JSHandle proxy = factory->NewJSProxy(emptyObj, emptyObj); DUMP_FOR_HANDLE(proxy) break; } case JSType::HCLASS: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), JSHClass::SIZE, 7U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), JSHClass::SIZE, 7U); JSHandle hclass = factory->NewEcmaDynClass(JSHClass::SIZE, JSType::HCLASS, proto); DUMP_FOR_HANDLE(hclass) break; @@ -678,64 +753,55 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) DUMP_FOR_HANDLE(dict) break; } - case JSType::FREE_OBJECT_WITH_ONE_FIELD: - case JSType::FREE_OBJECT_WITH_NONE_FIELD: - case JSType::FREE_OBJECT_WITH_TWO_FIELD: - { - break; - } - case JSType::JS_NATIVE_POINTER: { - break; - } case JSType::GLOBAL_ENV: { DUMP_FOR_HANDLE(globalEnv) break; } case JSType::ACCESSOR_DATA: case JSType::INTERNAL_ACCESSOR: { - CHECK_DUMP_FIELDS(Record::SIZE, AccessorData::SIZE, 2U) + CHECK_DUMP_FIELDS(Record::SIZE, AccessorData::SIZE, 2U); JSHandle accessor = factory->NewAccessorData(); DUMP_FOR_HANDLE(accessor) break; } case JSType::SYMBOL: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), JSSymbol::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), JSSymbol::SIZE, 2U); JSHandle symbol = factory->NewJSSymbol(); DUMP_FOR_HANDLE(symbol) break; } case JSType::JS_GENERATOR_CONTEXT: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), GeneratorContext::SIZE, 6U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), GeneratorContext::SIZE, 6U); JSHandle genContext = factory->NewGeneratorContext(); DUMP_FOR_HANDLE(genContext) break; } case JSType::PROTOTYPE_HANDLER: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), PrototypeHandler::SIZE, 3U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), PrototypeHandler::SIZE, 3U); JSHandle protoHandler = factory->NewPrototypeHandler(); DUMP_FOR_HANDLE(protoHandler) break; } case JSType::TRANSITION_HANDLER: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TransitionHandler::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TransitionHandler::SIZE, 2U); JSHandle transitionHandler = factory->NewTransitionHandler(); DUMP_FOR_HANDLE(transitionHandler) break; } case JSType::PROPERTY_BOX: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), PropertyBox::SIZE, 1U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), PropertyBox::SIZE, 1U); JSHandle PropertyBox = factory->NewPropertyBox(globalConst->GetHandledEmptyArray()); DUMP_FOR_HANDLE(PropertyBox) break; } case JSType::PROTO_CHANGE_MARKER: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ProtoChangeMarker::SIZE, 1U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ProtoChangeMarker::SIZE, 1U); JSHandle protoMaker = factory->NewProtoChangeMarker(); DUMP_FOR_HANDLE(protoMaker) break; } case JSType::PROTOTYPE_INFO: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ProtoChangeDetails::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ProtoChangeDetails::SIZE, 2U); JSHandle protoDetails = factory->NewProtoChangeDetails(); DUMP_FOR_HANDLE(protoDetails) break; @@ -746,50 +812,54 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::PROGRAM: { - CHECK_DUMP_FIELDS(ECMAObject::SIZE, Program::SIZE, 1U) + CHECK_DUMP_FIELDS(ECMAObject::SIZE, Program::SIZE, 1U); JSHandle program = factory->NewProgram(); DUMP_FOR_HANDLE(program) break; } case JSType::PROMISE_CAPABILITY: { - CHECK_DUMP_FIELDS(Record::SIZE, PromiseCapability::SIZE, 3U) + CHECK_DUMP_FIELDS(Record::SIZE, PromiseCapability::SIZE, 3U); JSHandle promiseCapa = factory->NewPromiseCapability(); DUMP_FOR_HANDLE(promiseCapa) break; } case JSType::PROMISE_RECORD: { - CHECK_DUMP_FIELDS(Record::SIZE, PromiseRecord::SIZE, 1U) + CHECK_DUMP_FIELDS(Record::SIZE, PromiseRecord::SIZE, 1U); JSHandle promiseRecord = factory->NewPromiseRecord(); DUMP_FOR_HANDLE(promiseRecord) break; } case JSType::RESOLVING_FUNCTIONS_RECORD: { - CHECK_DUMP_FIELDS(Record::SIZE, ResolvingFunctionsRecord::SIZE, 2U) + CHECK_DUMP_FIELDS(Record::SIZE, ResolvingFunctionsRecord::SIZE, 2U); JSHandle ResolvingFunc = factory->NewResolvingFunctionsRecord(); DUMP_FOR_HANDLE(ResolvingFunc) break; } case JSType::PROMISE_REACTIONS: { - CHECK_DUMP_FIELDS(Record::SIZE, PromiseReaction::SIZE, 3U) + CHECK_DUMP_FIELDS(Record::SIZE, PromiseReaction::SIZE, 3U); JSHandle promiseReact = factory->NewPromiseReaction(); DUMP_FOR_HANDLE(promiseReact) break; } case JSType::PROMISE_ITERATOR_RECORD: { - CHECK_DUMP_FIELDS(Record::SIZE, PromiseIteratorRecord::SIZE, 2U) + CHECK_DUMP_FIELDS(Record::SIZE, PromiseIteratorRecord::SIZE, 2U); JSHandle emptyObj(thread, NewJSObject(thread, factory, globalEnv).GetTaggedValue()); JSHandle promiseIter = factory->NewPromiseIteratorRecord(emptyObj, false); DUMP_FOR_HANDLE(promiseIter) break; } case JSType::MICRO_JOB_QUEUE: { - CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::MicroJobQueue::SIZE, 2U) + CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::MicroJobQueue::SIZE, 2U); JSHandle microJob = factory->NewMicroJobQueue(); DUMP_FOR_HANDLE(microJob) break; } case JSType::PENDING_JOB: { - CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 2U) +#if defined(ENABLE_HITRACE) + CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 6U); +#else + CHECK_DUMP_FIELDS(Record::SIZE, ecmascript::job::PendingJob::SIZE, 2U); +#endif JSHandle pendingClass(thread, JSHClass::Cast(globalConst->GetPendingJobClass().GetTaggedObject())); JSHandle pendingJob(thread, factory->NewDynObject(pendingClass)); @@ -799,101 +869,129 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::COMPLETION_RECORD: { - CHECK_DUMP_FIELDS(Record::SIZE, CompletionRecord::SIZE, 2U) + CHECK_DUMP_FIELDS(Record::SIZE, CompletionRecord::SIZE, 2U); JSHandle comRecord = factory->NewCompletionRecord(CompletionRecordType::NORMAL, globalConst->GetHandledEmptyArray()); DUMP_FOR_HANDLE(comRecord) break; } case JSType::MACHINE_CODE_OBJECT: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), MachineCode::DATA_OFFSET, 1U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), MachineCode::DATA_OFFSET, 1U); JSHandle machineCode = factory->NewMachineCodeObject(16, nullptr); DUMP_FOR_HANDLE(machineCode) break; } case JSType::CLASS_INFO_EXTRACTOR: { #ifdef PANDA_TARGET_64 - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 10U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 10U); #else - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 9U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), ClassInfoExtractor::SIZE, 9U); #endif JSHandle classInfoExtractor = factory->NewClassInfoExtractor(nullptr); DUMP_FOR_HANDLE(classInfoExtractor) break; } case JSType::TS_OBJECT_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSObjectType::SIZE, 3U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSObjectType::SIZE, 3U); JSHandle objectType = factory->NewTSObjectType(0); DUMP_FOR_HANDLE(objectType) break; } case JSType::TS_CLASS_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSClassType::SIZE, 5U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSClassType::SIZE, 5U); JSHandle classType = factory->NewTSClassType(); DUMP_FOR_HANDLE(classType) break; } case JSType::TS_INTERFACE_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSInterfaceType::SIZE, 3U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSInterfaceType::SIZE, 3U); JSHandle interfaceType = factory->NewTSInterfaceType(); DUMP_FOR_HANDLE(interfaceType) break; } case JSType::TS_IMPORT_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSImportType::SIZE, 3U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSImportType::SIZE, 3U); JSHandle importType = factory->NewTSImportType(); DUMP_FOR_HANDLE(importType) break; } case JSType::TS_CLASS_INSTANCE_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSClassInstanceType::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSClassInstanceType::SIZE, 2U); JSHandle classInstanceType = factory->NewTSClassInstanceType(); DUMP_FOR_HANDLE(classInstanceType) break; } case JSType::TS_UNION_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSUnionType::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSUnionType::SIZE, 2U); JSHandle unionType = factory->NewTSUnionType(1); DUMP_FOR_HANDLE(unionType) break; } case JSType::TS_FUNCTION_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSFunctionType::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSFunctionType::SIZE, 2U); JSHandle functionType = factory->NewTSFunctionType(1); DUMP_FOR_HANDLE(functionType) break; } case JSType::TS_ARRAY_TYPE: { - CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSArrayType::SIZE, 2U) + CHECK_DUMP_FIELDS(TaggedObject::TaggedObjectSize(), TSArrayType::SIZE, 2U); JSHandle arrayType = factory->NewTSArrayType(); DUMP_FOR_HANDLE(arrayType) break; } case JSType::JS_API_ARRAY_LIST: { // 1 : 1 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIArrayList::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIArrayList::SIZE, 1U); JSHandle jsArrayList = NewJSAPIArrayList(thread, factory, proto); DUMP_FOR_HANDLE(jsArrayList) break; } case JSType::JS_API_ARRAYLIST_ITERATOR: { // 2 : 2 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIArrayListIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIArrayListIterator::SIZE, 2U); JSHandle jsArrayList = NewJSAPIArrayList(thread, factory, proto); JSHandle jsArrayListIter = factory->NewJSAPIArrayListIterator(jsArrayList); DUMP_FOR_HANDLE(jsArrayListIter) break; } + case JSType::JS_API_LIGHT_WEIGHT_MAP: { + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightMap::SIZE, 4U); + JSHandle jSAPILightWeightMap = NewJSAPILightWeightMap(thread, factory); + DUMP_FOR_HANDLE(jSAPILightWeightMap) + break; + } + case JSType::JS_API_LIGHT_WEIGHT_MAP_ITERATOR: { + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightMapIterator::SIZE, 2U); + JSHandle jSAPILightWeightMap = NewJSAPILightWeightMap(thread, factory); + JSHandle jSAPILightWeightMapIterator = + factory->NewJSAPILightWeightMapIterator(jSAPILightWeightMap, IterationKind::KEY); + DUMP_FOR_HANDLE(jSAPILightWeightMapIterator) + break; + } + case JSType::JS_API_LIGHT_WEIGHT_SET: { + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightSet::SIZE, 3U); + JSHandle jSAPILightWeightSet = NewJSAPILightWeightSet(thread, factory); + DUMP_FOR_HANDLE(jSAPILightWeightSet) + break; + } + case JSType::JS_API_LIGHT_WEIGHT_SET_ITERATOR: { + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILightWeightSetIterator::SIZE, 2U); + JSHandle jSAPILightWeightSetIter = + factory->NewJSAPILightWeightSetIterator(NewJSAPILightWeightSet(thread, factory), + IterationKind::KEY); + DUMP_FOR_HANDLE(jSAPILightWeightSetIter) + break; + } case JSType::JS_API_QUEUE: { // 2 : 2 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIQueue::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIQueue::SIZE, 2U); JSHandle jsQueue = NewJSAPIQueue(thread, factory, proto); DUMP_FOR_HANDLE(jsQueue) break; } case JSType::JS_API_QUEUE_ITERATOR: { // 2 : 2 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIQueueIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIQueueIterator::SIZE, 2U); JSHandle jsQueue = NewJSAPIQueue(thread, factory, proto); JSHandle jsQueueIter = factory->NewJSAPIQueueIterator(jsQueue); @@ -901,13 +999,13 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_API_PLAIN_ARRAY: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIPlainArray::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIPlainArray::SIZE, 3U); JSHandle jSAPIPlainArray = NewJSAPIPlainArray(thread, factory); DUMP_FOR_HANDLE(jSAPIPlainArray) break; } case JSType::JS_API_PLAIN_ARRAY_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIPlainArrayIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIPlainArrayIterator::SIZE, 2U); JSHandle jSAPIPlainArray = NewJSAPIPlainArray(thread, factory); JSHandle jSAPIPlainArrayIter = factory->NewJSAPIPlainArrayIterator(jSAPIPlainArray, IterationKind::KEY); @@ -916,21 +1014,21 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) } case JSType::JS_API_TREE_MAP: { // 1 : 1 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMap::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMap::SIZE, 1U); JSHandle jsTreeMap = NewJSAPITreeMap(thread, factory); DUMP_FOR_HANDLE(jsTreeMap) break; } case JSType::JS_API_TREE_SET: { // 1 : 1 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSet::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSet::SIZE, 1U); JSHandle jsTreeSet = NewJSAPITreeSet(thread, factory); DUMP_FOR_HANDLE(jsTreeSet) break; } case JSType::JS_API_TREEMAP_ITERATOR: { // 3 : 3 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMapIterator::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeMapIterator::SIZE, 3U); JSHandle jsTreeMap = NewJSAPITreeMap(thread, factory); JSHandle jsTreeMapIter = factory->NewJSAPITreeMapIterator(jsTreeMap, IterationKind::KEY); @@ -939,7 +1037,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) } case JSType::JS_API_TREESET_ITERATOR: { // 3 : 3 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSetIterator::SIZE, 3U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPITreeSetIterator::SIZE, 3U); JSHandle jsTreeSet = NewJSAPITreeSet(thread, factory); JSHandle jsTreeSetIter = factory->NewJSAPITreeSetIterator(jsTreeSet, IterationKind::KEY); @@ -947,39 +1045,39 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_API_DEQUE: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIDeque::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIDeque::SIZE, 1U); JSHandle jsDeque = NewJSAPIDeque(thread, factory, proto); DUMP_FOR_HANDLE(jsDeque) break; } case JSType::JS_API_DEQUE_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIDequeIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIDequeIterator::SIZE, 2U); JSHandle jsDequeIter = factory->NewJSAPIDequeIterator(NewJSAPIDeque(thread, factory, proto)); DUMP_FOR_HANDLE(jsDequeIter) break; } case JSType::JS_API_STACK: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIStack::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIStack::SIZE, 1U); JSHandle jsStack = NewJSAPIStack(factory, proto); DUMP_FOR_HANDLE(jsStack) break; } case JSType::JS_API_STACK_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIStackIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIStackIterator::SIZE, 2U); JSHandle jsStackIter = factory->NewJSAPIStackIterator(NewJSAPIStack(factory, proto)); DUMP_FOR_HANDLE(jsStackIter) break; } case JSType::JS_API_VECTOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIVector::SIZE, 1) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIVector::SIZE, 1); JSHandle jsVector = NewJSAPIVector(factory, proto); DUMP_FOR_HANDLE(jsVector) break; } case JSType::JS_API_VECTOR_ITERATOR: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIVectorIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIVectorIterator::SIZE, 2U); JSHandle jsVectorIter = factory->NewJSAPIVectorIterator(NewJSAPIVector(factory, proto)); DUMP_FOR_HANDLE(jsVectorIter) @@ -987,21 +1085,21 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) } case JSType::JS_API_LIST: { // 1 : 1 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIList::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIList::SIZE, 1U); JSHandle jsAPIList = NewJSAPIList(thread, factory); DUMP_FOR_HANDLE(jsAPIList) break; } case JSType::JS_API_LINKED_LIST: { // 1 : 1 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILinkedList::SIZE, 1U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPILinkedList::SIZE, 1U); JSHandle jsAPILinkedList = NewJSAPILinkedList(thread, factory); DUMP_FOR_HANDLE(jsAPILinkedList) break; } case JSType::JS_API_LIST_ITERATOR: { // 2 : 2 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIListIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIListIterator::SIZE, 2U); JSHandle jsAPIList = NewJSAPIList(thread, factory); JSHandle jsAPIListIter = factory->NewJSAPIListIterator(jsAPIList); DUMP_FOR_HANDLE(jsAPIListIter) @@ -1009,7 +1107,7 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) } case JSType::JS_API_LINKED_LIST_ITERATOR: { // 2 : 2 dump fileds number - CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIListIterator::SIZE, 2U) + CHECK_DUMP_FIELDS(JSObject::SIZE, JSAPIListIterator::SIZE, 2U); JSHandle jsAPILinkedList = NewJSAPILinkedList(thread, factory); JSHandle jsAPILinkedListIter = factory->NewJSAPILinkedListIterator(jsAPILinkedList); @@ -1051,23 +1149,30 @@ HWTEST_F_L0(EcmaDumpTest, HeapProfileDump) break; } case JSType::JS_CJS_EXPORTS: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSCjsExports::SIZE, 1U); - JSHandle cjsExports = factory->NewCjsExports(); + CHECK_DUMP_FIELDS(JSObject::SIZE, CjsExports::SIZE, 1U); + JSHandle cjsExports = factory->NewCjsExports(); DUMP_FOR_HANDLE(cjsExports); break; } case JSType::JS_CJS_MODULE: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSCjsModule::SIZE, 5U); - JSHandle cjsModule = factory->NewCjsModule(); + CHECK_DUMP_FIELDS(JSObject::SIZE, CjsModule::SIZE, 5U); + JSHandle cjsModule = factory->NewCjsModule(); DUMP_FOR_HANDLE(cjsModule); break; } case JSType::JS_CJS_REQUIRE: { - CHECK_DUMP_FIELDS(JSObject::SIZE, JSCjsRequire::SIZE, 2U); - JSHandle cjsRequire = factory->NewCjsRequire(); + CHECK_DUMP_FIELDS(JSObject::SIZE, CjsRequire::SIZE, 2U); + JSHandle cjsRequire = factory->NewCjsRequire(); DUMP_FOR_HANDLE(cjsRequire); break; } + case JSType::JS_ITERATOR: + case JSType::FREE_OBJECT_WITH_ONE_FIELD: + case JSType::FREE_OBJECT_WITH_NONE_FIELD: + case JSType::FREE_OBJECT_WITH_TWO_FIELD: + case JSType::JS_NATIVE_POINTER: { + break; + } default: LOG_ECMA_MEM(ERROR) << "JSType " << static_cast(type) << " cannot be dumped."; UNREACHABLE(); diff --git a/ecmascript/tests/ecma_module_test.cpp b/ecmascript/tests/ecma_module_test.cpp index 104d99bf3f13de5c75af0bef0b5c0c3062139da4..85668219d65eb97b6311d87487e6ba9599671701 100644 --- a/ecmascript/tests/ecma_module_test.cpp +++ b/ecmascript/tests/ecma_module_test.cpp @@ -190,93 +190,4 @@ HWTEST_F_L0(EcmaModuleTest, GetModuleValue) moduleExport->GetModuleValue(thread, exportLocalNameHandle.GetTaggedValue(), false); EXPECT_EQ(exportValueHandle.GetTaggedValue(), importDefaultValue); } - -/* - * Feature: Module - * Function: EcmaModule use CjsModule - * SubFunction: - * FunctionPoints: EcmaModule use CjsModule - * CaseDescription: Simulated implementation of "module.export.obj = 'hello world cjs'","import {a as b} from "test.js, - * import cjs from "cjs"", print(cjs)", while exectue the ldModuleVar byteCode to load cjs var; - * use ParseCjsModule function to generate Cjsmodule which type is MODULETYPES::CJSMODULE - */ -HWTEST_F_L0(EcmaModuleTest, ParseCjsModule) -{ - ObjectFactory* factory = thread->GetEcmaVM()->GetFactory(); - JSHandle defaultValue = thread->GlobalConstants()->GetHandledUndefined(); - // fileName - CString ecmaFileName = "currentModule.js"; - CString cjsFileName = "cjs.js"; - CString requesFileName = "test.js"; - // current module - JSHandle EcmaModule = factory->NewSourceTextModule(); - JSHandle ecmaModuleFilename = factory->NewFromUtf8(ecmaFileName); - - JSHandle importName1 = JSHandle(factory->NewFromUtf8("a")); - JSHandle localName1 = JSHandle(factory->NewFromUtf8("b")); - JSHandle moduleRequest1 = JSHandle(factory->NewFromUtf8(requesFileName)); - JSHandle importEntry1 = factory->NewImportEntry(moduleRequest1, importName1, localName1); - JSHandle importName2 = JSHandle(factory->NewFromUtf8("default")); - JSHandle localName2 = JSHandle(factory->NewFromUtf8("cjs")); - JSHandle moduleRequest2 = JSHandle(factory->NewFromUtf8(cjsFileName)); - JSHandle importEntry2 = factory->NewImportEntry(moduleRequest2, importName2, localName2); - - JSHandle requestModuleArray = factory->NewTaggedArray(2); - requestModuleArray->Set(thread, 0, moduleRequest1); - requestModuleArray->Set(thread, 1, moduleRequest2); - - SourceTextModule::AddImportEntry(thread, EcmaModule, importEntry1); - SourceTextModule::AddImportEntry(thread, EcmaModule, importEntry2); - EcmaModule->SetRequestedModules(thread, requestModuleArray); - EcmaModule->SetEcmaModuleFilename(thread, ecmaModuleFilename); - EcmaModule->SetStatus(ModuleStatus::UNINSTANTIATED); - EcmaModule->SetTypes(ModuleTypes::ECMAMODULE); - - // export module - JSHandle exportModule = factory->NewSourceTextModule(); - JSHandle exportModuleValue =JSHandle::Cast(exportModule); - JSHandle exportModuleFilename = factory->NewFromUtf8(requesFileName); - JSHandle exportName = JSHandle(factory->NewFromUtf8("a")); - JSHandle localName3 = JSHandle(factory->NewFromUtf8("a")); - JSHandle exportEntry = factory->NewExportEntry(exportName, defaultValue, defaultValue, localName3); - - JSHandle requestModuleArray1 = factory->NewTaggedArray(0); - - SourceTextModule::AddLocalExportEntry(thread, exportModule, exportEntry); - exportModule->SetRequestedModules(thread, requestModuleArray1); - exportModule->SetEcmaModuleFilename(thread, exportModuleFilename); - exportModule->SetStatus(ModuleStatus::UNINSTANTIATED); - exportModule->SetTypes(ModuleTypes::ECMAMODULE); - - // cjs module - JSHandle cjsModule = ModuleDataExtractor::ParseCjsModule(thread, cjsFileName); - - const CString requesFile = "test.abc"; - const CString cjsFile = "cjs.abc"; - thread->GetEcmaVM()->GetModuleManager()->AddResolveImportedModule(requesFile, exportModuleValue); - thread->GetEcmaVM()->GetModuleManager()->AddResolveImportedModule(cjsFile, cjsModule); - - SourceTextModule::Instantiate(thread, EcmaModule); - JSTaggedValue moduleEnvironment = EcmaModule->GetEnvironment(); - - JSTaggedValue resolvedBinding1 = - LinkedHashMap::Cast(moduleEnvironment.GetTaggedObject())->Get(localName1.GetTaggedValue()); - JSTaggedValue resolvedBinding2 = - LinkedHashMap::Cast(moduleEnvironment.GetTaggedObject())->Get(localName2.GetTaggedValue()); - ResolvedBinding *binding1 = ResolvedBinding::Cast(resolvedBinding1.GetTaggedObject()); - ResolvedBinding *binding2 = ResolvedBinding::Cast(resolvedBinding2.GetTaggedObject()); - JSTaggedValue resolvedModule2 = binding2->GetModule(); - JSTaggedValue resolvedModule1 = binding1->GetModule(); - - SourceTextModule *module1 = SourceTextModule::Cast(resolvedModule1.GetHeapObject()); - SourceTextModule *module2 = SourceTextModule::Cast(resolvedModule2.GetHeapObject()); - - CString bindingName1 = ConvertToString(binding1->GetBindingName()); - CString bindingName2 = ConvertToString(binding2->GetBindingName()); - - EXPECT_EQ(module1->GetTypes(), ModuleTypes::ECMAMODULE); - EXPECT_EQ(module2->GetTypes(), ModuleTypes::CJSMODULE); - EXPECT_EQ(bindingName1, "a"); - EXPECT_EQ(bindingName2, "default"); -} } // namespace panda::test diff --git a/ecmascript/tests/ecma_vm_test.cpp b/ecmascript/tests/ecma_vm_test.cpp index 7ea08c4b50bb62d732d733c5b883f09c5c1cb68e..3962a0d51b2b3d435de7cdcefb471c78beba9da5 100644 --- a/ecmascript/tests/ecma_vm_test.cpp +++ b/ecmascript/tests/ecma_vm_test.cpp @@ -59,7 +59,8 @@ HWTEST_F_L0(EcmaVMTest, CreateEcmaVMInTwoWays) options2.SetEnableCpuprofiler(true); options2.SetArkProperties(ArkProperties::GC_STATS_PRINT); // A non-production gc strategy. Prohibit stw-gc 10 times. - EcmaVM *ecmaVm2 = EcmaVM::Create(options2); + auto config = ecmascript::EcmaParamConfiguration(false, MemMapAllocator::GetInstance()->GetCapacity()); + EcmaVM *ecmaVm2 = EcmaVM::Create(options2, config); EXPECT_TRUE(ecmaVm1 != ecmaVm2); diff --git a/ecmascript/tests/huge_object_test.cpp b/ecmascript/tests/huge_object_test.cpp index 68d0ced6404fd4b9aaa9644cdce9d53ce18c354e..82958c6d91938f7a81ddffccd50c21496da999ac 100644 --- a/ecmascript/tests/huge_object_test.cpp +++ b/ecmascript/tests/huge_object_test.cpp @@ -95,21 +95,21 @@ HWTEST_F_L0(HugeObjectTest, MultipleArrays) auto heap = ecmaVm->GetHeap(); { [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); - for (int i = 0; i <= 20; i++) { + for (int i = 0; i <= 14; i++) { JSHandle array1(thread, LargeArrayTestCreate(thread)); } } { [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); - for (int i = 0; i <= 20; i++) { + for (int i = 0; i <= 14; i++) { JSHandle array2(thread, LargeArrayTestCreate(thread)); } } { [[maybe_unused]] ecmascript::EcmaHandleScope scope(thread); - for (int i = 0; i <= 20; i++) { + for (int i = 0; i <= 14; i++) { JSHandle array2(thread, LargeArrayTestCreate(thread)); } } diff --git a/ecmascript/tests/js_api_arraylist_iterator_test.cpp b/ecmascript/tests/js_api_arraylist_iterator_test.cpp index 63c307cd544dd1a78744295d051be0d1e314eca8..a2c02753647ab71af19043310cc08b2f8056b240 100644 --- a/ecmascript/tests/js_api_arraylist_iterator_test.cpp +++ b/ecmascript/tests/js_api_arraylist_iterator_test.cpp @@ -25,7 +25,6 @@ using namespace panda; using namespace panda::ecmascript; -using namespace coretypes; namespace panda::test { class JSAPIArrayListIteratorTest : public testing::Test { @@ -70,8 +69,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::ArrayList))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -105,8 +104,8 @@ HWTEST_F_L0(JSAPIArrayListIteratorTest, Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(arrayListIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPIArrayListIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPIArrayListIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/tests/js_api_arraylist_test.cpp b/ecmascript/tests/js_api_arraylist_test.cpp index 4a7216f76f7f581103e7c009283e0a2585de7488..ab724c39dac7d9e396fa7d17a0ad97b58522536c 100644 --- a/ecmascript/tests/js_api_arraylist_test.cpp +++ b/ecmascript/tests/js_api_arraylist_test.cpp @@ -24,7 +24,6 @@ using namespace panda; using namespace panda::ecmascript; -using namespace coretypes; namespace panda::test { class JSAPIArrayListTest : public testing::Test { @@ -88,8 +87,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::ArrayList))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -398,7 +397,7 @@ HWTEST_F_L0(JSAPIArrayListTest, ReplaceAllElements) callInfo->SetThis(arrayList.GetTaggedValue()); callInfo->SetCallArg(0, func.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSHandle result(thread, JSAPIArrayList::ReplaceAllElements(thread, callInfo->GetThis(), callInfo->GetFunction(), callInfo->GetCallArg(0))); EXPECT_EQ(result.GetTaggedValue(), JSTaggedValue::Undefined()); @@ -457,7 +456,7 @@ HWTEST_F_L0(JSAPIArrayListTest, ForEach) callInfo->SetThis(arrayList.GetTaggedValue()); callInfo->SetCallArg(0, func.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, callInfo); JSHandle result(thread, JSAPIArrayList::ForEach(thread, callInfo->GetThis(), callInfo->GetFunction(), callInfo->GetCallArg(0))); EXPECT_EQ(result.GetTaggedValue(), JSTaggedValue::Undefined()); diff --git a/ecmascript/tests/js_api_deque_iterator_test.cpp b/ecmascript/tests/js_api_deque_iterator_test.cpp index e41a9870955896d2943a3967084d4e1fac71c9dc..31657e99126414dca7401500e7d2299d86228831 100644 --- a/ecmascript/tests/js_api_deque_iterator_test.cpp +++ b/ecmascript/tests/js_api_deque_iterator_test.cpp @@ -93,8 +93,8 @@ HWTEST_F_L0(JSAPIDequeIteratorTest, Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(dequeIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPIDequeIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPIDequeIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/tests/js_api_deque_test.cpp b/ecmascript/tests/js_api_deque_test.cpp index c7feb59bc5a75796e2fa1f068ac1c8709c370521..f02ce32a4bc4c9c4a22b14e1d1842188515b3afa 100644 --- a/ecmascript/tests/js_api_deque_test.cpp +++ b/ecmascript/tests/js_api_deque_test.cpp @@ -74,8 +74,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::Deque))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_api_lightweightmap_test.cpp b/ecmascript/tests/js_api_lightweightmap_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..06ef2de53b8643555195fb25863678124bf7cacd --- /dev/null +++ b/ecmascript/tests/js_api_lightweightmap_test.cpp @@ -0,0 +1,289 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/ecma_string.h" +#include "ecmascript/containers/containers_private.h" +#include "ecmascript/ecma_string.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_api_lightweightmap.h" +#include "ecmascript/js_api_lightweightmap_iterator.h" +#include "ecmascript/js_function.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/js_iterator.h" +#include "ecmascript/js_object-inl.h" +#include "ecmascript/js_tagged_value.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; + +using namespace panda::ecmascript; + +using namespace panda::ecmascript::containers; + +namespace panda::test { +class JSAPILightWeightMapTest : public testing::Test { +public: + const static int DEFAULT_SIZE = 8; + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; + +protected: + JSAPILightWeightMap *CreateLightWeightMap() + { + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + + JSHandle globalObject = env->GetJSGlobalObject(); + JSHandle key(factory->NewFromASCII("ArkPrivate")); + JSHandle value = JSObject::GetProperty(thread, + JSHandle(globalObject), key).GetValue(); + + auto objCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(value.GetTaggedValue()); + objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::LightWeightMap))); + + auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSHandle constructor = + JSHandle(thread, containers::ContainersPrivate::Load(objCallInfo)); + TestHelper::TearDownFrame(thread, prev); + JSHandle lightWeightMap = JSHandle:: + Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); + JSHandle hashArray = JSHandle(factory->NewTaggedArray(DEFAULT_SIZE)); + JSHandle keyArray = JSHandle(factory->NewTaggedArray(DEFAULT_SIZE)); + JSHandle valueArray = JSHandle(factory->NewTaggedArray(DEFAULT_SIZE)); + lightWeightMap->SetHashes(thread, hashArray); + lightWeightMap->SetKeys(thread, keyArray); + lightWeightMap->SetValues(thread, valueArray); + lightWeightMap->SetLength(0); + return *lightWeightMap; + } +}; + +HWTEST_F_L0(JSAPILightWeightMapTest, LightWeightMapCreate) +{ + JSAPILightWeightMap *lightWeightMap = CreateLightWeightMap(); + EXPECT_TRUE(lightWeightMap != nullptr); +} + +HWTEST_F_L0(JSAPILightWeightMapTest, SetHasKeyGetHasValue) +{ + JSAPILightWeightMap *lightWeightMap = CreateLightWeightMap(); + + JSHandle key(thread, JSTaggedValue(1)); + JSHandle value(thread, JSTaggedValue(2)); + JSHandle lwm(thread, lightWeightMap); + JSAPILightWeightMap::Set(thread, lwm, key, value); + EXPECT_TRUE(JSTaggedValue::Equal(thread, + JSHandle(thread, + JSAPILightWeightMap::Get(thread, lwm, key)), + value)); + + JSHandle key1(thread, JSTaggedValue(2)); + JSHandle value1(thread, JSTaggedValue(3)); + JSAPILightWeightMap::Set(thread, lwm, key1, value1); + + JSHandle key2(thread, JSTaggedValue(3)); + JSHandle value2(thread, JSTaggedValue(4)); + JSAPILightWeightMap::Set(thread, lwm, key2, value2); + + // test species + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + JSHandle key3 = env->GetSpeciesSymbol(); + JSHandle value3(thread, JSTaggedValue(5)); + JSAPILightWeightMap::Set(thread, lwm, key3, value3); + + EXPECT_TRUE(JSTaggedValue::Equal(thread, + JSHandle(thread, + JSAPILightWeightMap::Get(thread, lwm, key)), + value)); + EXPECT_EQ(JSAPILightWeightMap::HasKey(thread, lwm, key1), JSTaggedValue::True()); + EXPECT_EQ(JSAPILightWeightMap::HasKey(thread, lwm, key), JSTaggedValue::True()); + EXPECT_EQ(JSAPILightWeightMap::HasKey(thread, lwm, key3), JSTaggedValue::True()); + EXPECT_EQ(JSAPILightWeightMap::HasKey(thread, lwm, value), JSTaggedValue::True()); +} + +HWTEST_F_L0(JSAPILightWeightMapTest, GetIndexOfKeyAndGetIndexOfValue) +{ + constexpr uint32_t NODE_NUMBERS = 8; + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSMutableHandle key(thread, JSTaggedValue::Undefined()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + std::string myKey("mykey"); + std::string myValue("myvalue"); + JSHandle lwm(thread, CreateLightWeightMap()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ikey = myKey + std::to_string(i); + std::string ivalue = myValue + std::to_string(i); + key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); + value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + JSAPILightWeightMap::Set(thread, lwm, key, value); + EXPECT_TRUE(JSAPILightWeightMap::GetIndexOfKey(thread, lwm, key) != -1); + EXPECT_TRUE(JSAPILightWeightMap::GetIndexOfValue(thread, lwm, value) != -1); + uint32_t length = lwm->GetLength(); + EXPECT_EQ(length, i + 1); + } +} + +HWTEST_F_L0(JSAPILightWeightMapTest, IsEmptyGetKeyAtGetValue) +{ + JSHandle lwm(thread, CreateLightWeightMap()); + + JSHandle key(thread, JSTaggedValue(1)); + JSHandle value(thread, JSTaggedValue(2)); + JSAPILightWeightMap::Set(thread, lwm, key, value); + + JSHandle key1(thread, JSTaggedValue(2)); + JSHandle value1(thread, JSTaggedValue(3)); + JSAPILightWeightMap::Set(thread, lwm, key1, value1); + + JSHandle key2(thread, JSTaggedValue(3)); + JSHandle value2(thread, JSTaggedValue(4)); + JSAPILightWeightMap::Set(thread, lwm, key2, value2); + + JSHandle result = + JSHandle(thread, JSAPILightWeightMap::GetValueAt(thread, lwm, 0)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, value)); + result = JSHandle(thread, JSAPILightWeightMap::GetValueAt(thread, lwm, 1)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, value1)); + result = JSHandle(thread, JSAPILightWeightMap::GetValueAt(thread, lwm, 2)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, value2)); + + result = JSHandle(thread, JSAPILightWeightMap::GetKeyAt(thread, lwm, 0)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, key)); + result = JSHandle(thread, JSAPILightWeightMap::GetKeyAt(thread, lwm, 1)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, key1)); + result = JSHandle(thread, JSAPILightWeightMap::GetKeyAt(thread, lwm, 2)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, key2)); + + JSAPILightWeightMap::Clear(thread, lwm); + EXPECT_EQ(lwm->IsEmpty(), JSTaggedValue::True()); +} + +HWTEST_F_L0(JSAPILightWeightMapTest, RemoveRemoveAt) +{ + JSHandle lwm(thread, CreateLightWeightMap()); + JSHandle valueArray(thread, + JSTaggedValue(TaggedArray::Cast(lwm->GetValues().GetTaggedObject()))); + + JSHandle key(thread, JSTaggedValue(1)); + JSHandle value(thread, JSTaggedValue(2)); + JSAPILightWeightMap::Set(thread, lwm, key, value); + + JSHandle key1(thread, JSTaggedValue(2)); + JSHandle value1(thread, JSTaggedValue(3)); + JSAPILightWeightMap::Set(thread, lwm, key1, value1); + + JSHandle key2(thread, JSTaggedValue(3)); + JSHandle value2(thread, JSTaggedValue(4)); + JSAPILightWeightMap::Set(thread, lwm, key2, value2); + + JSHandle result = + JSHandle(thread, JSAPILightWeightMap::Remove(thread, lwm, key2)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, value2)); + EXPECT_EQ(JSAPILightWeightMap::RemoveAt(thread, lwm, 0), JSTaggedValue::True()); + result = JSHandle(thread, JSAPILightWeightMap::GetValueAt(thread, lwm, 0)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, value1)); + result = JSHandle(thread, JSAPILightWeightMap::GetKeyAt(thread, lwm, 0)); + EXPECT_TRUE(JSTaggedValue::Equal(thread, result, key1)); +} + +HWTEST_F_L0(JSAPILightWeightMapTest, IncreaseCapacityTo) +{ + constexpr uint32_t NODE_NUMBERS = 10; + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSMutableHandle key(thread, JSTaggedValue::Undefined()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + std::string myKey("mykey"); + std::string myValue("myvalue"); + JSHandle lwm(thread, CreateLightWeightMap()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string ikey = myKey + std::to_string(i); + std::string ivalue = myValue + std::to_string(i); + key.Update(factory->NewFromStdString(ikey).GetTaggedValue()); + value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); + JSAPILightWeightMap::Set(thread, lwm, key, value); + EXPECT_TRUE(JSAPILightWeightMap::GetIndexOfKey(thread, lwm, key) != -1); + EXPECT_TRUE(JSAPILightWeightMap::GetIndexOfValue(thread, lwm, value) != -1); + uint32_t length = lwm->GetLength(); + EXPECT_EQ(length, i + 1); + } + EXPECT_EQ(JSAPILightWeightMap::IncreaseCapacityTo(thread, lwm, 15), JSTaggedValue::True()); + EXPECT_EQ(JSAPILightWeightMap::IncreaseCapacityTo(thread, lwm, 9), JSTaggedValue::False()); +} + +HWTEST_F_L0(JSAPILightWeightMapTest, Iterator) +{ + constexpr uint32_t NODE_NUMBERS = 8; + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle lwm(thread, CreateLightWeightMap()); + + JSMutableHandle key(thread, JSTaggedValue::Undefined()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + key.Update(JSTaggedValue(i)); + value.Update(JSTaggedValue(i + 1)); + JSAPILightWeightMap::Set(thread, lwm, key, value); + } + + // test key or value + JSHandle keyIter(factory->NewJSAPILightWeightMapIterator(lwm, IterationKind::KEY)); + JSHandle valueIter(factory->NewJSAPILightWeightMapIterator(lwm, IterationKind::VALUE)); + JSMutableHandle keyIterResult(thread, JSTaggedValue::Undefined()); + JSMutableHandle valueIterResult(thread, JSTaggedValue::Undefined()); + JSMutableHandle keyHandle(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + keyIterResult.Update(JSIterator::IteratorStep(thread, keyIter).GetTaggedValue()); + valueIterResult.Update(JSIterator::IteratorStep(thread, valueIter).GetTaggedValue()); + JSTaggedValue k = JSIterator::IteratorValue(thread, keyIterResult).GetTaggedValue(); + keyHandle.Update(k); + JSTaggedValue v = JSIterator::IteratorValue(thread, valueIterResult).GetTaggedValue(); + EXPECT_EQ(JSAPILightWeightMap::HasKey(thread, lwm, keyHandle), JSTaggedValue::True()); + EXPECT_EQ(JSAPILightWeightMap::Get(thread, lwm, keyHandle), v); + } + + // test key and value + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + JSTaggedValue k = JSTaggedValue(i); + JSTaggedValue v = JSTaggedValue(i + 1); + keyHandle.Update(k); + EXPECT_EQ(JSAPILightWeightMap::HasKey(thread, lwm, keyHandle), JSTaggedValue::True()); + EXPECT_EQ(JSAPILightWeightMap::Get(thread, lwm, keyHandle), v); + } +} +} // namespace panda::test diff --git a/ecmascript/tests/js_api_lightweightset_test.cpp b/ecmascript/tests/js_api_lightweightset_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..27729a3dca5abfe12e0bf1b806ba5ad766b15da5 --- /dev/null +++ b/ecmascript/tests/js_api_lightweightset_test.cpp @@ -0,0 +1,288 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_api_lightweightset.h" +#include "ecmascript/containers/containers_private.h" +#include "ecmascript/ecma_string.h" +#include "ecmascript/ecma_vm.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_api_lightweightset_iterator.h" +#include "ecmascript/js_function.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/js_iterator.h" +#include "ecmascript/js_object-inl.h" +#include "ecmascript/js_tagged_value.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace panda::test { +class JSAPILightWeightSetTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; + +protected: + JSAPILightWeightSet *CreateLightWeightSet() + { + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + + JSHandle globalObject = env->GetJSGlobalObject(); + JSHandle key(factory->NewFromASCII("ArkPrivate")); + JSHandle value = + JSObject::GetProperty(thread, JSHandle(globalObject), key).GetValue(); + + auto objCallInfo = + TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); // 3 means the value + objCallInfo->SetFunction(JSTaggedValue::Undefined()); + objCallInfo->SetThis(value.GetTaggedValue()); + objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::LightWeightSet))); + + auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSHandle constructor = + JSHandle(thread, containers::ContainersPrivate::Load(objCallInfo)); + TestHelper::TearDownFrame(thread, prev); + JSHandle lightweightSet = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), + constructor)); + JSHandle hashArray = JSHandle(factory->NewTaggedArray(8)); // 8 means the value + JSHandle valueArray = JSHandle(factory->NewTaggedArray(8)); // 8 means the value + lightweightSet->SetHashes(thread, hashArray); + lightweightSet->SetValues(thread, valueArray); + lightweightSet->SetLength(0); // 0 means the value + return *lightweightSet; + } +}; + +HWTEST_F_L0(JSAPILightWeightSetTest, LightWeightSetCreate) +{ + JSAPILightWeightSet *lightweightSet = CreateLightWeightSet(); + EXPECT_TRUE(lightweightSet != nullptr); +} + +HWTEST_F_L0(JSAPILightWeightSetTest, AddIncreaseCapacityAddAll) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + JSHandle lws(thread, CreateLightWeightSet()); + JSHandle srcLws(thread, CreateLightWeightSet()); + JSHandle destLws(thread, CreateLightWeightSet()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + + // test IncreaseCapacityTo + std::string myValue("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + bool result = JSAPILightWeightSet::Add(thread, lws, value); + EXPECT_TRUE(result); + } + EXPECT_EQ(lws->GetSize(), NODE_NUMBERS); + + uint32_t tmp = NODE_NUMBERS * 3; // 3 means the value + JSAPILightWeightSet::IncreaseCapacityTo(thread, lws, static_cast(tmp)); + uint32_t capacity = TaggedArray::Cast(lws->GetValues().GetTaggedObject())->GetLength(); + EXPECT_EQ(JSTaggedValue(capacity), JSTaggedValue(tmp)); + + // test AddAll + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + bool result = JSAPILightWeightSet::Add(thread, srcLws, JSHandle(thread, JSTaggedValue(i))); + EXPECT_TRUE(result); + } + + for (uint32_t i = 0; i < NODE_NUMBERS + 2; i++) { + JSAPILightWeightSet::Add(thread, destLws, JSHandle(thread, JSTaggedValue(i))); + } + bool result = JSAPILightWeightSet::AddAll(thread, destLws, JSHandle::Cast(srcLws)); + EXPECT_TRUE(result); + tmp = NODE_NUMBERS * 2 + 2; // 2 means the value + EXPECT_EQ(destLws->GetSize(), tmp); +} + +HWTEST_F_L0(JSAPILightWeightSetTest, EqualClearNotEqual) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle lws(thread, CreateLightWeightSet()); + JSHandle equalLws(thread, CreateLightWeightSet()); + JSMutableHandle value1(thread, JSTaggedValue::Undefined()); + JSMutableHandle value2(thread, JSTaggedValue::Undefined()); + bool result = false; + // test equal + std::string myValue1("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string iValue = myValue1 + std::to_string(i); + value1.Update(factory->NewFromStdString(iValue).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, lws, value1); + EXPECT_TRUE(result); + } + EXPECT_EQ(lws->GetSize(), NODE_NUMBERS); + + std::string myValue2("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string iValue = myValue2 + std::to_string(i); + value2.Update(factory->NewFromStdString(iValue).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, equalLws, value2); + EXPECT_TRUE(result); + } + EXPECT_EQ(equalLws->GetSize(), NODE_NUMBERS); + result = JSAPILightWeightSet::Equal(thread, lws, JSHandle::Cast(equalLws)); + EXPECT_TRUE(result); + + equalLws->Clear(thread); + EXPECT_EQ(equalLws->GetSize(), static_cast(0)); // 0 means the value + + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string iValue = myValue2 + std::to_string(i); + if (i == 2) { + LOG_ECMA(ERROR) << " {} " << iValue; + } else { + value2.Update(factory->NewFromStdString(iValue).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, equalLws, value2); + EXPECT_TRUE(result); + } + } + EXPECT_EQ(equalLws->GetSize(), NODE_NUMBERS - 1); + result = JSAPILightWeightSet::Equal(thread, lws, JSHandle::Cast(equalLws)); + EXPECT_FALSE(result); +} + +HWTEST_F_L0(JSAPILightWeightSetTest, IsEmptyHasHasAll) +{ + constexpr uint32_t NODE_NUMBERS = 8; + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle lws(thread, CreateLightWeightSet()); + JSHandle hasAllLws(thread, CreateLightWeightSet()); + JSMutableHandle value1(thread, JSTaggedValue::Undefined()); + JSMutableHandle value2(thread, JSTaggedValue::Undefined()); + JSMutableHandle value3(thread, JSTaggedValue::Undefined()); + bool result = false; + std::string tValue; + // test IsEmpty + result = lws->IsEmpty(); + EXPECT_TRUE(result); + // test Has + std::string myValue1("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string iValue = myValue1 + std::to_string(i); + value1.Update(factory->NewFromStdString(iValue).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, lws, value1); + EXPECT_TRUE(result); + } + EXPECT_EQ(lws->GetSize(), NODE_NUMBERS); + + tValue = myValue1 + std::to_string(5); + value1.Update(factory->NewFromStdString(tValue).GetTaggedValue()); + result = lws->Has(value1); + EXPECT_TRUE(result); + + std::string myValue2("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS - 5; i++) { + if (i == 1) { + std::string myValue3("destValue"); + std::string iValue3 = myValue3 + std::to_string(i); + value3.Update(factory->NewFromStdString(iValue3).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, hasAllLws, value3); + } else { + std::string iValue = myValue2 + std::to_string(i); + value2.Update(factory->NewFromStdString(iValue).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, hasAllLws, value2); + EXPECT_TRUE(result); + } + } + EXPECT_EQ(hasAllLws->GetSize(), NODE_NUMBERS - 5); // 5 means the value + result = lws->HasAll(JSHandle::Cast(hasAllLws)); + EXPECT_FALSE(result); +} + +HWTEST_F_L0(JSAPILightWeightSetTest, GetIndexOfRemoveRemoveAtGetValueAt) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle lws(thread, CreateLightWeightSet()); + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + bool result = false; + + // test GetSize + std::string myValue("myvalue"); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + std::string iValue = myValue + std::to_string(i); + value.Update(factory->NewFromStdString(iValue).GetTaggedValue()); + result = JSAPILightWeightSet::Add(thread, lws, value); + } + EXPECT_EQ(lws->GetSize(), NODE_NUMBERS); + + // test GetIndexOf + std::string tValue("myvalue5"); + value.Update(factory->NewFromStdString(tValue).GetTaggedValue()); + int32_t index = lws->GetIndexOf(value); + EXPECT_EQ(index, 5); // 5 means the value + + // test GetValueAt + JSTaggedValue jsValue = lws->GetValueAt(5); // 5 means the value + EXPECT_EQ(value.GetTaggedValue(), jsValue); + + // test Remove + jsValue = lws->Remove(thread, value); + EXPECT_EQ(value.GetTaggedValue(), jsValue); + + // test RemoveAt + result = lws->RemoveAt(thread, 4); // 4 means the value + EXPECT_EQ(lws->GetSize(), NODE_NUMBERS - 2); // 2 means the value + EXPECT_TRUE(result); +} + +HWTEST_F_L0(JSAPILightWeightSetTest, Iterator) +{ + constexpr uint32_t NODE_NUMBERS = 8; // 8 means the value + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle lwm(thread, CreateLightWeightSet()); + + JSMutableHandle value(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + value.Update(JSTaggedValue(i)); + JSAPILightWeightSet::Add(thread, lwm, value); + } + + JSHandle valueIter(factory->NewJSAPILightWeightSetIterator(lwm, IterationKind::VALUE)); + JSMutableHandle valueIterResult(thread, JSTaggedValue::Undefined()); + for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + valueIterResult.Update(JSIterator::IteratorStep(thread, valueIter).GetTaggedValue()); + int v = JSIterator::IteratorValue(thread, valueIterResult)->GetInt(); + JSMutableHandle keyHandle(thread, JSTaggedValue(v)); + } +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_api_linked_list_test.cpp b/ecmascript/tests/js_api_linked_list_test.cpp index 494689d8003ea2eb48c1c6a0c4afc7e87219b375..e2cf5561b68c56edecc5e8e3ad7d09a7622cf0e6 100644 --- a/ecmascript/tests/js_api_linked_list_test.cpp +++ b/ecmascript/tests/js_api_linked_list_test.cpp @@ -78,9 +78,9 @@ protected: // 6 : 6 value is 6. objCallInfo->SetCallArg(0, JSTaggedValue(6)); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); JSHandle contianer = - JSHandle(thread, ContainersPrivate::Load(objCallInfo.get())); + JSHandle(thread, ContainersPrivate::Load(objCallInfo)); JSHandle linkedList = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(contianer), contianer)); diff --git a/ecmascript/tests/js_api_list_test.cpp b/ecmascript/tests/js_api_list_test.cpp index b1ba952399d5f5b460c48d09385cd0e154c92757..4e8836db794f1a7bd8809e9d4c1fa7dce1af9a44 100644 --- a/ecmascript/tests/js_api_list_test.cpp +++ b/ecmascript/tests/js_api_list_test.cpp @@ -77,8 +77,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::List))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_api_plain_array_test.cpp b/ecmascript/tests/js_api_plain_array_test.cpp index d79baa80f26b5c485fe85aa96293e6515c2977c4..3bba2f85062bb5c23f50c7520e661e20d7e4fb95 100644 --- a/ecmascript/tests/js_api_plain_array_test.cpp +++ b/ecmascript/tests/js_api_plain_array_test.cpp @@ -75,8 +75,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::PlainArray))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_api_queue_test.cpp b/ecmascript/tests/js_api_queue_test.cpp index bd4ed93b5a07e55760bc47bd55a82c24dfac4d41..0214de4a1966987afab9f21d0370b35fef5cd3ed 100644 --- a/ecmascript/tests/js_api_queue_test.cpp +++ b/ecmascript/tests/js_api_queue_test.cpp @@ -63,8 +63,8 @@ protected: ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::Queue))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_api_stack_iterator_test.cpp b/ecmascript/tests/js_api_stack_iterator_test.cpp index 92562469296e281097e2ceaee1fcd17aebdab054..9b0b660c5ff69b26156efcc1345228aa3d8f67fd 100644 --- a/ecmascript/tests/js_api_stack_iterator_test.cpp +++ b/ecmascript/tests/js_api_stack_iterator_test.cpp @@ -65,8 +65,8 @@ protected: ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::Stack))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -104,8 +104,8 @@ HWTEST_F_L0(JSAPIStackIteratorTest, Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(stackIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPIStackIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPIStackIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/tests/js_api_stack_test.cpp b/ecmascript/tests/js_api_stack_test.cpp index b3adb6f4419551774e766109b7e229bb50cc84bf..b8acd7da4da61c022d6c2b4dc6cd014ba098a812 100644 --- a/ecmascript/tests/js_api_stack_test.cpp +++ b/ecmascript/tests/js_api_stack_test.cpp @@ -76,8 +76,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::Stack))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -123,7 +123,7 @@ HWTEST_F_L0(JSAPIStackTest, Pop) JSHandle toor(thread, CreateStack()); std::string myValue("myvalue"); - for (uint32_t i = 0; i < NODE_NUMBERS; i++) { + for (uint32_t i = 1; i <= NODE_NUMBERS; i++) { std::string ivalue = myValue + std::to_string(i); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSTaggedValue result = JSAPIStack::Push(thread, toor, value); @@ -131,7 +131,7 @@ HWTEST_F_L0(JSAPIStackTest, Pop) EXPECT_EQ(toor->Peek(), value.GetTaggedValue()); } - for (uint32_t i = NODE_NUMBERS; i < 0; i--) { + for (uint32_t i = NODE_NUMBERS; i >= 1; i--) { std::string ivalue = myValue + std::to_string(i); value.Update(factory->NewFromStdString(ivalue).GetTaggedValue()); JSTaggedValue gValue = toor->Pop(); diff --git a/ecmascript/tests/js_api_tree_map_iterator_test.cpp b/ecmascript/tests/js_api_tree_map_iterator_test.cpp index f8fa08fbe5a82c2a0efc395a8ef5e5bc4bb2f990..1c112699533d254a486deafad295bd6da6a49f8a 100644 --- a/ecmascript/tests/js_api_tree_map_iterator_test.cpp +++ b/ecmascript/tests/js_api_tree_map_iterator_test.cpp @@ -67,8 +67,8 @@ protected: ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::TreeMap))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -224,8 +224,8 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, KEY_Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(treeMapKeyIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPITreeMapIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPITreeMapIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); @@ -263,8 +263,8 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, VALUE_Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(treeMapKeyIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPITreeMapIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPITreeMapIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); @@ -302,8 +302,8 @@ HWTEST_F_L0(JSAPITreeMapIteratorTest, KEY_AND_VALUE_Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(treeMapKeyIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPITreeMapIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPITreeMapIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/tests/js_api_tree_map_test.cpp b/ecmascript/tests/js_api_tree_map_test.cpp index 7e869d327163d4f3354afe2bb90edb635f587f48..daa8255659cfefeb5f7db35d2430522ee3622954 100644 --- a/ecmascript/tests/js_api_tree_map_test.cpp +++ b/ecmascript/tests/js_api_tree_map_test.cpp @@ -75,8 +75,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::TreeMap))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_api_tree_set_iterator_test.cpp b/ecmascript/tests/js_api_tree_set_iterator_test.cpp index 95b96fdcba0059c80befbf2e928950d76afaa245..64524c847e86257370ea3c0c6f3d3523c6052566 100644 --- a/ecmascript/tests/js_api_tree_set_iterator_test.cpp +++ b/ecmascript/tests/js_api_tree_set_iterator_test.cpp @@ -67,8 +67,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::TreeSet))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -212,8 +212,8 @@ HWTEST_F_L0(JSAPITreeSetIteratorTest, KEY_Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(treeSetIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPITreeSetIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPITreeSetIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); @@ -247,8 +247,8 @@ HWTEST_F_L0(JSAPITreeSetIteratorTest, KEY_AND_VALUE_Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(treeSetIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPITreeSetIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPITreeSetIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/tests/js_api_tree_set_test.cpp b/ecmascript/tests/js_api_tree_set_test.cpp index 843ee9d5d813027869fd66924ba1b639ffd43239..c707e0f27d4c5a952d402bead9b15ac70a48d203 100644 --- a/ecmascript/tests/js_api_tree_set_test.cpp +++ b/ecmascript/tests/js_api_tree_set_test.cpp @@ -75,8 +75,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::TreeSet))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_api_vector_iterator_test.cpp b/ecmascript/tests/js_api_vector_iterator_test.cpp index 28028215afa3ab264e1e0635af49e8016dab095e..b15e0c8961f787c5fc7b5db4668c9e0e24563771 100644 --- a/ecmascript/tests/js_api_vector_iterator_test.cpp +++ b/ecmascript/tests/js_api_vector_iterator_test.cpp @@ -67,8 +67,8 @@ protected: ecmaRuntimeCallInfo->SetThis(value.GetTaggedValue()); ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::Vector))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); @@ -160,8 +160,8 @@ HWTEST_F_L0(JSAPIVectorIteratorTest, Next) ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); ecmaRuntimeCallInfo->SetThis(vectorIterator.GetTaggedValue()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); - JSTaggedValue result = JSAPIVectorIterator::Next(ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue result = JSAPIVectorIterator::Next(ecmaRuntimeCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle resultObj(thread, result); diff --git a/ecmascript/tests/js_api_vector_test.cpp b/ecmascript/tests/js_api_vector_test.cpp index 08499bcc5b1d069ecd83f9f4e1d9f274fe0085a4..e56f24c4e34e8fb5602530f14ad3f09ea4e6bd40 100644 --- a/ecmascript/tests/js_api_vector_test.cpp +++ b/ecmascript/tests/js_api_vector_test.cpp @@ -76,8 +76,8 @@ protected: objCallInfo->SetThis(value.GetTaggedValue()); objCallInfo->SetCallArg(0, JSTaggedValue(static_cast(containers::ContainerTag::Vector))); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo.get()); - JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, objCallInfo); + JSTaggedValue result = containers::ContainersPrivate::Load(objCallInfo); TestHelper::TearDownFrame(thread, prev); JSHandle constructor(thread, result); diff --git a/ecmascript/tests/js_array_buffer_test.cpp b/ecmascript/tests/js_array_buffer_test.cpp index 96361e872834603e50c7a685f71edd1ea55dd89e..bcf8e76f476d79356c4a399412b1638d1de3f7e0 100644 --- a/ecmascript/tests/js_array_buffer_test.cpp +++ b/ecmascript/tests/js_array_buffer_test.cpp @@ -64,7 +64,6 @@ HWTEST_F_L0(JsArrayBufferTest, CopyDataBlockBytes) JSHandle toNativePointer = factory->NewJSNativePointer(toBuffer, nullptr, nullptr); uint8_t *data = static_cast(vm->GetNativeAreaAllocator()->AllocateBuffer(length)); if (memset_s(data, length, value, length) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; UNREACHABLE(); } void *formBuffer = vm->GetNativeAreaAllocator()->AllocateBuffer(length); @@ -98,7 +97,6 @@ HWTEST_F_L0(JsArrayBufferTest, Attach_Detach_IsDetach) void *buffer = vm->GetNativeAreaAllocator()->AllocateBuffer(100); uint8_t *data = static_cast(vm->GetNativeAreaAllocator()->AllocateBuffer(length)); if (memset_s(data, length, value, length) != EOK) { - LOG_ECMA(FATAL) << "memset_s failed"; UNREACHABLE(); } JSHandle nativePointer = diff --git a/ecmascript/tests/js_array_test.cpp b/ecmascript/tests/js_array_test.cpp index a94ba61ad9fbcd964a05617d4a78f0c9c57f792a..9a61168ed3c360b44c7595fe3e98545370c9fdb0 100644 --- a/ecmascript/tests/js_array_test.cpp +++ b/ecmascript/tests/js_array_test.cpp @@ -140,10 +140,10 @@ HWTEST_F_L0(JSArrayTest, Next) JSHandle iter(factory->NewJSArrayIterator(array, IterationKind::KEY)); auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 4); ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); - [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo.get()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); for (int i = 0; i < 5; i++) { ecmaRuntimeCallInfo->SetThis(iter.GetTaggedValue()); - JSTaggedValue ret = JSArrayIterator::Next(ecmaRuntimeCallInfo.get()); + JSTaggedValue ret = JSArrayIterator::Next(ecmaRuntimeCallInfo); JSHandle result(thread, ret); EXPECT_EQ(JSIterator::IteratorValue(thread, result)->GetInt(), i); } diff --git a/ecmascript/tests/js_async_function_test.cpp b/ecmascript/tests/js_async_function_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..aa2a6179f35c87a211ac43174e51120da4c93b03 --- /dev/null +++ b/ecmascript/tests/js_async_function_test.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_async_function.h" +#include "ecmascript/js_generator_object.h" +#include "ecmascript/global_env.h" +#include "ecmascript/jobs/micro_job_queue.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace panda::test { +class JSAsyncFunctionTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +/** + * @tc.name: SetAsyncContext + * @tc.desc: Call "NewJSAsyncAwaitStatusFunction" function to construct class JSAsyncAwaitStatusFunction object, calling + * "SetAsyncContext" function to set AsyncContext and check the AsyncContext is within expectations by calling + * "GetAsyncContext" function. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSAsyncFunctionTest, SetAsyncContext) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle asyncFuncObj = factory->NewJSAsyncFuncObject(); + JSHandle asyncFuncObjVal(thread, asyncFuncObj->GetGeneratorContext()); + + JSHandle fulFunc = + factory->NewJSAsyncAwaitStatusFunction(MethodIndex::BUILTINS_PROMISE_HANDLER_ASYNC_AWAIT_FULFILLED); + fulFunc->SetAsyncContext(thread, asyncFuncObjVal); + EXPECT_EQ(JSTaggedValue::SameValue(fulFunc->GetAsyncContext(), asyncFuncObjVal.GetTaggedValue()), true); + + JSHandle rejFunc = + factory->NewJSAsyncAwaitStatusFunction(MethodIndex::BUILTINS_PROMISE_HANDLER_ASYNC_AWAIT_REJECTED); + rejFunc->SetAsyncContext(thread, asyncFuncObj->GetGeneratorContext()); + EXPECT_EQ(JSTaggedValue::SameValue(rejFunc->GetAsyncContext(), asyncFuncObjVal.GetTaggedValue()), true); +} + +/** + * @tc.name: AsyncFunctionAwait + * @tc.desc: Call "NewJSAsyncFuncObject" function to construct class JSAsyncFuncObject object, calling + * "AsyncFunctionAwait" function remove asyncContext and run execution context,but context is + * undefined so cannot execute, the promise is undefined. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSAsyncFunctionTest, AsyncFunctionAwait) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle valueHandle(thread, JSTaggedValue(33)); + // asyncContext is undefined + JSHandle asyncFuncObj = factory->NewJSAsyncFuncObject(); + JSAsyncFunction::AsyncFunctionAwait(thread, asyncFuncObj, valueHandle); + + // check AsyncPromise queue and queue cannot execute + auto microJobQueue = instance->GetMicroJobQueue(); + EXPECT_FALSE(microJobQueue->GetPromiseJobQueue().IsUndefined()); + // promiese is undefined. + EXPECT_TRUE(asyncFuncObj->GetPromise().IsUndefined()); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_bigint_test.cpp b/ecmascript/tests/js_bigint_test.cpp index 42b6001f381258124a92b7df5260ac9c0915274b..c268685f3480c5a346d9d0e5f33c3255a8f85965 100644 --- a/ecmascript/tests/js_bigint_test.cpp +++ b/ecmascript/tests/js_bigint_test.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "ecmascript/js_bigint.h" #include "ecmascript/tests/test_helper.h" @@ -148,7 +149,7 @@ HWTEST_F_L0(JSBigintTest, InitializationZero) } EXPECT_NE(countZero, size); - BigInt::InitializationZero(thread, maxSafeIntPlusOne); + maxSafeIntPlusOne->InitializationZero(); for (uint32_t i = 0; i < size; i++) { uint32_t digit = maxSafeIntPlusOne->GetDigit(i); EXPECT_EQ(digit, 0U); @@ -343,4 +344,148 @@ HWTEST_F_L0(JSBigintTest, Exponentiate_Multiply_Divide_Remainder) JSHandle remRes3 = BigInt::Remainder(thread, resBigint4, resBigint3); EXPECT_TRUE(BigInt::Equal(remRes3.GetTaggedValue(), expBigint2.GetTaggedValue())); } + +/** + * @tc.name: ToInt64 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSBigintTest, ToInt64) +{ + CString resBigintStr1 = std::to_string(LLONG_MAX).c_str(); + CString resBigintStr2 = std::to_string(LLONG_MIN).c_str(); + CString resBigintStr3 = std::to_string(INT_MAX).c_str(); + CString resBigintStr4 = std::to_string(INT_MIN).c_str(); + CString resBigintStr5 = "0"; + + JSHandle resBigint1 = BigIntHelper::SetBigInt(thread, resBigintStr1); + JSHandle resBigint2 = BigIntHelper::SetBigInt(thread, resBigintStr2); + JSHandle resBigint3 = BigIntHelper::SetBigInt(thread, resBigintStr3); + JSHandle resBigint4 = BigIntHelper::SetBigInt(thread, resBigintStr4); + JSHandle resBigint5 = BigIntHelper::SetBigInt(thread, resBigintStr5); + + EXPECT_TRUE(resBigint1->ToInt64() == LLONG_MAX); + EXPECT_TRUE(resBigint2->ToInt64() == LLONG_MIN); + EXPECT_TRUE(resBigint3->ToInt64() == INT_MAX); + EXPECT_TRUE(resBigint4->ToInt64() == INT_MIN); + EXPECT_TRUE(resBigint5->ToInt64() == 0); +} + +/** + * @tc.name: ToUint64 + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSBigintTest, ToUint64) +{ + CString resBigintStr1 = std::to_string(ULLONG_MAX).c_str(); + CString resBigintStr2 = std::to_string(UINT_MAX).c_str(); + CString resBigintStr3 = "0"; + + JSHandle resBigint1 = BigIntHelper::SetBigInt(thread, resBigintStr1); + JSHandle resBigint2 = BigIntHelper::SetBigInt(thread, resBigintStr2); + JSHandle resBigint3 = BigIntHelper::SetBigInt(thread, resBigintStr3); + + EXPECT_TRUE(resBigint1->ToUint64() == ULLONG_MAX); + EXPECT_TRUE(resBigint2->ToUint64() == UINT_MAX); + EXPECT_TRUE(resBigint3->ToUint64() == 0); +} + +/** + * @tc.name: Int64ToBigInt + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSBigintTest, Int64ToBigInt) +{ + // JSHandle BigInt::Int64ToBigInt(JSThread *thread, const int64_t &number) + JSHandle resBigint1 = BigInt::Int64ToBigInt(thread, LLONG_MAX); + JSHandle resBigint2 = BigInt::Int64ToBigInt(thread, LLONG_MIN); + JSHandle resBigint3 = BigInt::Int64ToBigInt(thread, INT_MAX); + JSHandle resBigint4 = BigInt::Int64ToBigInt(thread, INT_MIN); + JSHandle resBigint5 = BigInt::Int64ToBigInt(thread, 0); + + EXPECT_TRUE(resBigint1->ToInt64() == LLONG_MAX); + EXPECT_TRUE(resBigint2->ToInt64() == LLONG_MIN); + EXPECT_TRUE(resBigint3->ToInt64() == INT_MAX); + EXPECT_TRUE(resBigint4->ToInt64() == INT_MIN); + EXPECT_TRUE(resBigint5->ToInt64() == 0); +} + +/** + * @tc.name: Uint64ToBigInt + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSBigintTest, Uint64ToBigInt) +{ + JSHandle resBigint1 = BigInt::Uint64ToBigInt(thread, ULLONG_MAX); + JSHandle resBigint2 = BigInt::Uint64ToBigInt(thread, UINT_MAX); + JSHandle resBigint3 = BigInt::Uint64ToBigInt(thread, 0); + + EXPECT_TRUE(resBigint1->ToUint64() == ULLONG_MAX); + EXPECT_TRUE(resBigint2->ToUint64() == UINT_MAX); + EXPECT_TRUE(resBigint3->ToUint64() == 0); +} + +void GetWordsArray(bool *signBit, size_t wordCount, uint64_t *words, JSHandle bigintVal) +{ + uint32_t len = bigintVal->GetLength(); + uint32_t count = 0; + uint32_t index = 0; + for (; index < wordCount - 1; ++index) { + words[index] = static_cast(bigintVal->GetDigit(count++)); + words[index] |= static_cast(bigintVal->GetDigit(count++)) << 32; // 32 : int32_t bits + } + if (len % 2 == 0) { // 2 : len is odd or even + words[index] = static_cast(bigintVal->GetDigit(count++)); + words[index] |= static_cast(bigintVal->GetDigit(count++)) << 32; // 32 : int32_t bits + } else { + words[index] = static_cast(bigintVal->GetDigit(count++)); + } + *signBit = bigintVal->GetSign(); +} + +/** + * @tc.name: CreateBigWords + * @tc.desc: + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSBigintTest, CreateBigWords) +{ + size_t wordCount = 4; + uint64_t words[] = { 0xFFFFFFFFFFFFFFFF, 34ULL, 56ULL, 0xFFFFFFFFFFFFFFFF }; + JSHandle bigintFalse = BigInt::CreateBigWords(thread, false, wordCount, words); + bool sign = true; + uint64_t wordsOut[] = { 0ULL, 0ULL, 0ULL, 0ULL }; + GetWordsArray(&sign, wordCount, wordsOut, bigintFalse); + EXPECT_TRUE(sign == false); + for (size_t i = 0; i < wordCount; i++) { + EXPECT_TRUE(words[i] == wordsOut[i]); + } + + JSHandle bigintTrue = BigInt::CreateBigWords(thread, true, wordCount, words); + GetWordsArray(&sign, wordCount, wordsOut, bigintTrue); + EXPECT_TRUE(sign == true); + for (size_t i = 0; i < wordCount; i++) { + EXPECT_TRUE(words[i] == wordsOut[i]); + } + + size_t wordCount1 = 5; + uint64_t words1[] = { 12ULL, 34ULL, 56ULL, 78ULL, 90ULL }; + JSHandle bigintFalse1 = BigInt::CreateBigWords(thread, false, wordCount1, words1); + + bool sign1 = true; + uint64_t wordsOut1[] = { 0ULL, 0ULL, 0ULL, 0ULL, 0ULL }; + GetWordsArray(&sign1, wordCount1, wordsOut1, bigintFalse1); + EXPECT_TRUE(sign1 == false); + for (size_t i = 0; i < wordCount1; i++) { + EXPECT_TRUE(words1[i] == wordsOut1[i]); + } +} } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_collator_test.cpp b/ecmascript/tests/js_collator_test.cpp index 5c04690020ac9e575c47d50f36cb4436a6c7c950..6c2d1577f441aef0989ec5d2dee0186e0d3f28aa 100644 --- a/ecmascript/tests/js_collator_test.cpp +++ b/ecmascript/tests/js_collator_test.cpp @@ -89,13 +89,15 @@ HWTEST_F_L0(JSCollatorTest, GetIcuCollatorAndCompare) EXPECT_EQ(result.GetInt(), 0); // equivalent result = JSCollator::CompareStrings(icuCollator1, string1, string3); EXPECT_EQ(result.GetInt(), -1); // less than - // test Collator is default locale - icuCollator = icu::Collator::createInstance(status); + // test Collator is zh-Hans-CN locale + icu::Locale zhLocale("zh", "Hans", "CN"); + icuCollator = icu::Collator::createInstance(zhLocale, status); + icuCollator->setStrength(icu::Collator::PRIMARY); JSCollator::SetIcuCollator(thread, collator, icuCollator, JSCollator::FreeIcuCollator); icu::Collator *icuCollator2 = collator->GetIcuCollator(); EXPECT_TRUE(icuCollator2 == icuCollator); result = JSCollator::CompareStrings(icuCollator2, string1, string2); - EXPECT_EQ(result.GetInt(), -1); // less than + EXPECT_EQ(result.GetInt(), 0); // equivalent } /** diff --git a/ecmascript/tests/js_date_time_format_test.cpp b/ecmascript/tests/js_date_time_format_test.cpp index 5354341e9312220df35e65e2c192f946844caed9..e2d0318e187c0c42a181a0560d5b4c2d315cda6f 100644 --- a/ecmascript/tests/js_date_time_format_test.cpp +++ b/ecmascript/tests/js_date_time_format_test.cpp @@ -61,7 +61,7 @@ public: }; void SetDateOptionsTest(JSThread *thread, JSHandle &optionsObj, - std::map dateOptions) + std::map &dateOptions) { auto vm = thread->GetEcmaVM(); auto factory = vm->GetFactory(); @@ -84,7 +84,7 @@ void SetDateOptionsTest(JSThread *thread, JSHandle &optionsObj, } void SetTimeOptionsTest(JSThread *thread, JSHandle &optionsObj, - std::map timeOptionsMap) + std::map &timeOptionsMap) { auto vm = thread->GetEcmaVM(); auto factory = vm->GetFactory(); @@ -147,6 +147,9 @@ HWTEST_F_L0(JSDateTimeFormatTest, Set_Get_IcuSimpleDateFormat) auto vm = thread->GetEcmaVM(); auto factory = vm->GetFactory(); auto env = vm->GetGlobalEnv(); + const icu::UnicodeString timeZoneId("Asia/Shanghai"); + icu::TimeZone *tz = icu::TimeZone::createTimeZone(timeZoneId); + icu::TimeZone::adoptDefault(tz); JSHandle ctor = env->GetDateTimeFormatFunction(); JSHandle dtf = JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); @@ -350,11 +353,14 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_001) icu::Locale icuLocale("zh", "Hans", "Cn"); JSHandle objFun = env->GetObjectFunction(); - JSHandle optionsEmtpy = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle hourCycleKey = globalConst->GetHandledHourCycleString(); JSHandle hourCycleValue(factory->NewFromASCII("h12")); - JSObject::SetProperty(thread, optionsEmtpy, hourCycleKey, hourCycleValue); - JSHandle dtf = CreateDateTimeFormatTest(thread, icuLocale, optionsEmtpy); + JSHandle timeZoneKey = globalConst->GetHandledTimeZoneString(); + JSHandle timeZoneValue(factory->NewFromASCII("ETC/GMT-8")); + JSObject::SetProperty(thread, options, timeZoneKey, timeZoneValue); + JSObject::SetProperty(thread, options, hourCycleKey, hourCycleValue); + JSHandle dtf = CreateDateTimeFormatTest(thread, icuLocale, options); double timeStamp1 = 1653448174000; // test "2022-05-25 11:09:34.000" double timeStamp2 = 1653921012999; // test "2022-05-30 22:30:12.999" @@ -376,12 +382,15 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_002) icu::Locale icuLocale("zh", "Hans", "Cn"); JSHandle objFun = env->GetObjectFunction(); - JSHandle optionsEmtpy = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle hourCycleKey = globalConst->GetHandledHourCycleString(); JSHandle hourCycleValue(factory->NewFromASCII("h12")); - JSObject::SetProperty(thread, optionsEmtpy, hourCycleKey, hourCycleValue); - JSHandle options = JSDateTimeFormat::ToDateTimeOptions( - thread, JSHandle::Cast(optionsEmtpy), RequiredOption::ANY, DefaultsOption::ALL); + JSHandle timeZoneKey = globalConst->GetHandledTimeZoneString(); + JSHandle timeZoneValue(factory->NewFromASCII("ETC/GMT-8")); + JSObject::SetProperty(thread, options, timeZoneKey, timeZoneValue); + JSObject::SetProperty(thread, options, hourCycleKey, hourCycleValue); + options = JSDateTimeFormat::ToDateTimeOptions( + thread, JSHandle::Cast(options), RequiredOption::ANY, DefaultsOption::ALL); JSHandle dtf = CreateDateTimeFormatTest(thread, icuLocale, options); double timeStamp1 = 1653448174000; // test "2022-05-25 11:09:34.000" @@ -403,13 +412,15 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_003) icu::Locale icuLocale("zh", "Hans", "Cn"); JSHandle objFun = env->GetObjectFunction(); - JSHandle optionsEmtpy = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle hourCycleKey = globalConst->GetHandledHourCycleString(); JSHandle hourCycleValue(factory->NewFromASCII("h12")); - JSObject::SetProperty(thread, optionsEmtpy, hourCycleKey, hourCycleValue); + JSHandle timeZoneKey = globalConst->GetHandledTimeZoneString(); + JSHandle timeZoneValue(factory->NewFromASCII("ETC/GMT-8")); + JSObject::SetProperty(thread, options, timeZoneKey, timeZoneValue); + JSObject::SetProperty(thread, options, hourCycleKey, hourCycleValue); // Set custom date time format. - JSHandle options = optionsEmtpy; std::map dateOptionsMap { { "weekday", "long" }, { "year", "2-digit" }, @@ -445,15 +456,17 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTime_004) auto env = vm->GetGlobalEnv(); auto globalConst = thread->GlobalConstants(); - icu::Locale icuLocale("en", "Hans", "US"); + icu::Locale icuLocale("en", "Latn", "US"); JSHandle objFun = env->GetObjectFunction(); - JSHandle optionsEmtpy = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle hourCycleKey = globalConst->GetHandledHourCycleString(); JSHandle hourCycleValue(factory->NewFromASCII("h12")); - JSObject::SetProperty(thread, optionsEmtpy, hourCycleKey, hourCycleValue); + JSHandle timeZoneKey = globalConst->GetHandledTimeZoneString(); + JSHandle timeZoneValue(factory->NewFromASCII("ETC/GMT-8")); + JSObject::SetProperty(thread, options, timeZoneKey, timeZoneValue); + JSObject::SetProperty(thread, options, hourCycleKey, hourCycleValue); // Set custom date time format. - JSHandle options = optionsEmtpy; std::map dateOptionsMap { { "weekday", "long" }, { "year", "2-digit" }, @@ -513,11 +526,14 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTimeToParts_001) icu::Locale icuLocale("zh", "Hans", "Cn"); JSHandle objFun = env->GetObjectFunction(); - JSHandle optionsEmtpy = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle hourCycleKey = globalConst->GetHandledHourCycleString(); JSHandle hourCycleValue(factory->NewFromASCII("h12")); - JSObject::SetProperty(thread, optionsEmtpy, hourCycleKey, hourCycleValue); - JSHandle dtf = CreateDateTimeFormatTest(thread, icuLocale, optionsEmtpy); + JSHandle timeZoneKey = globalConst->GetHandledTimeZoneString(); + JSHandle timeZoneValue(factory->NewFromASCII("ETC/GMT-8")); + JSObject::SetProperty(thread, options, timeZoneKey, timeZoneValue); + JSObject::SetProperty(thread, options, hourCycleKey, hourCycleValue); + JSHandle dtf = CreateDateTimeFormatTest(thread, icuLocale, options); double timeStamp = 1653448174123; // test "2022-05-25 11:09:34.123" // Use default date time format and format date and time to parts. @@ -555,6 +571,9 @@ HWTEST_F_L0(JSDateTimeFormatTest, FormatDateTimeToParts_002) JSHandle options = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); JSHandle hourCycleKey = globalConst->GetHandledHourCycleString(); JSHandle hourCycleValue(factory->NewFromASCII("h12")); + JSHandle timeZoneKey = globalConst->GetHandledTimeZoneString(); + JSHandle timeZoneValue(factory->NewFromASCII("ETC/GMT-8")); + JSObject::SetProperty(thread, options, timeZoneKey, timeZoneValue); JSObject::SetProperty(thread, options, hourCycleKey, hourCycleValue); double timeStamp = 1653448174123; // test "2022-05-25 11:09:34.123" diff --git a/ecmascript/tests/js_finalization_registry_test.cpp b/ecmascript/tests/js_finalization_registry_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..58778e666c3678ae1aeba444bf4e9f9d47efd839 --- /dev/null +++ b/ecmascript/tests/js_finalization_registry_test.cpp @@ -0,0 +1,472 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/builtins/builtins_finalization_registry.h" +#include "ecmascript/global_env.h" +#include "ecmascript/linked_hash_table.h" +#include "ecmascript/jobs/micro_job_queue.h" +#include "ecmascript/js_finalization_registry.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; +using namespace panda::ecmascript; +using namespace panda::ecmascript::builtins; + +static int testValue = 0; + +namespace panda::test { +class JSFinalizationRegistryTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; + + class TestClass : public base::BuiltinsBase { + public: + static JSTaggedValue callbackTest() + { + testValue++; + return JSTaggedValue::Undefined(); + } + }; +}; + +static JSHandle CreateFinalizationRegistry(JSThread *thread) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle finaRegFunc(env->GetBuiltinsFinalizationRegistryFunction()); + JSHandle callbackFunc = factory->NewJSFunction(env, reinterpret_cast( + JSFinalizationRegistryTest::TestClass::callbackTest)); + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue(*finaRegFunc), 6); + ecmaRuntimeCallInfo->SetFunction(finaRegFunc.GetTaggedValue()); + ecmaRuntimeCallInfo->SetThis(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetCallArg(0, callbackFunc.GetTaggedValue()); + + auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + JSTaggedValue finalizationRegistry = + BuiltinsFinalizationRegistry::FinalizationRegistryConstructor(ecmaRuntimeCallInfo); + JSHandle finalizationRegistryHandle(thread, finalizationRegistry); + TestHelper::TearDownFrame(thread, prev); + return finalizationRegistryHandle; +} + +/** + * @tc.name: Register + * @tc.desc: Register the target object to the JSFinalizationRegistry object, and call the callback method after the + * target object is garbage collected. And a unregistration token, which is passed to the unregister method + * when the finalizer is no longer needed. The held value, which is used to represent that object when + * cleaning it up in the finalizer. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSFinalizationRegistryTest, Register_001) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + JSHandle target(factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc)); + JSHandle key(factory->NewFromASCII("key1")); + JSHandle value(thread, JSTaggedValue(1)); + JSObject::SetProperty(thread, target, key, value); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken(thread, JSTaggedValue::Undefined()); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + + // If unregisterToken is undefined, use vector to store + JSHandle cellRecord = factory->NewCellRecord(); + cellRecord->SetToWeakRefTarget(target.GetTaggedValue()); + cellRecord->SetHeldValue(thread, heldValue); + JSHandle cell(cellRecord); + JSHandle expectNoUnregister(thread, finaRegObj->GetNoUnregister()); + expectNoUnregister = CellRecordVector::Append(thread, expectNoUnregister, cell); + + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + JSHandle noUnregister(thread, finaRegObj->GetNoUnregister()); + JSHandle finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue().GetRawData(), + JSHandle::Cast(finaRegObj).GetTaggedValue().GetRawData()); + EXPECT_EQ(expectNoUnregister.GetTaggedValue().GetRawData(), noUnregister.GetTaggedValue().GetRawData()); + EXPECT_EQ(testValue, 0); +} + +HWTEST_F_L0(JSFinalizationRegistryTest, Register_002) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + JSHandle target(factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc)); + JSHandle key(factory->NewFromASCII("key2")); + JSHandle value(thread, JSTaggedValue(2)); + JSObject::SetProperty(thread, target, key, value); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken = target; + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + + // If unregisterToken is not undefined, use hash map to store to facilitate subsequent delete operations + JSHandle cellRecord = factory->NewCellRecord(); + cellRecord->SetToWeakRefTarget(target.GetTaggedValue()); + cellRecord->SetHeldValue(thread, heldValue); + JSHandle cell(cellRecord); + JSHandle array = JSHandle(CellRecordVector::Create(thread)); + array = CellRecordVector::Append(thread, array, cell); + JSHandle arrayValue(array); + JSHandle expectMaybeUnregister(thread, finaRegObj->GetMaybeUnregister()); + expectMaybeUnregister = LinkedHashMap::SetWeakRef(thread, expectMaybeUnregister, unregisterToken, arrayValue); + + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + JSHandle maybeUnregister(thread, finaRegObj->GetMaybeUnregister()); + EXPECT_EQ(expectMaybeUnregister.GetTaggedValue().GetRawData(), maybeUnregister.GetTaggedValue().GetRawData()); + + JSHandle finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue().GetRawData(), + JSHandle::Cast(finaRegObj).GetTaggedValue().GetRawData()); + EXPECT_EQ(testValue, 0); +} + +HWTEST_F_L0(JSFinalizationRegistryTest, Register_003) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + vm->SetEnableForceGC(false); + JSHandle target(thread, JSTaggedValue::Undefined()); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken(thread, JSTaggedValue::Undefined()); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + EXPECT_EQ(testValue, 0); + } + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + EXPECT_EQ(testValue, 1); +} + +HWTEST_F_L0(JSFinalizationRegistryTest, Register_004) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + vm->SetEnableForceGC(false); + JSHandle target1(thread, JSTaggedValue::Undefined()); + JSHandle target2(thread, JSTaggedValue::Undefined()); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target1 = JSHandle::Cast(obj); + target2 = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken = JSHandle::Cast(obj); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj1(thread, constructor.GetTaggedValue()); + JSHandle finaRegObj2(thread, constructor.GetTaggedValue()); + + JSFinalizationRegistry::Register(thread, target1, heldValue, unregisterToken, finaRegObj1); + JSFinalizationRegistry::Register(thread, target2, heldValue, unregisterToken, finaRegObj2); + EXPECT_EQ(testValue, 0); + } + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + EXPECT_EQ(testValue, 2); +} + +/** + * @tc.name: Unregister + * @tc.desc: Unregister the JSFinalizationRegistry object from the finalization registry lists. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSFinalizationRegistryTest, Unregister_001) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + vm->SetEnableForceGC(false); + JSHandle target(thread, JSTaggedValue::Undefined()); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken = target; + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + JSFinalizationRegistry::Unregister(thread, target, finaRegObj); + EXPECT_EQ(testValue, 0); + } + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + EXPECT_EQ(testValue, 0); +} + +HWTEST_F_L0(JSFinalizationRegistryTest, Unregister_002) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + vm->SetEnableForceGC(false); + JSHandle target1(thread, JSTaggedValue::Undefined()); + JSHandle target2(thread, JSTaggedValue::Undefined()); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target1 = JSHandle::Cast(obj); + target2 = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken = JSHandle::Cast(obj); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj1(thread, constructor.GetTaggedValue()); + JSHandle finaRegObj2(thread, constructor.GetTaggedValue()); + + // only second finalization is be registered + JSFinalizationRegistry::Register(thread, target1, heldValue, unregisterToken, finaRegObj1); + JSFinalizationRegistry::Unregister(thread, target1, finaRegObj1); + + JSFinalizationRegistry::Register(thread, target2, heldValue, unregisterToken, finaRegObj2); + EXPECT_EQ(testValue, 0); + } + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + // only trigger second finalization callback + EXPECT_EQ(testValue, 1); +} + +/** + * @tc.name: CheckAndCall + * @tc.desc: Check whether each JSFinalizationRegistry object in finalization registry lists has been cleared. If so, + * clear the JSFinalizationRegistry object from the lists. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSFinalizationRegistryTest, CheckAndCall) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + JSHandle target(thread, JSTaggedValue::Undefined()); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + JSHandle finRegLists(thread, JSTaggedValue::Undefined()); + vm->SetEnableForceGC(false); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken(thread, JSTaggedValue::Undefined()); + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + EXPECT_EQ(testValue, 0); + } + finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue(), JSHandle::Cast(finaRegObj).GetTaggedValue()); + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + EXPECT_EQ(testValue, 1); + // If all objects registered in the current JSFinalizationRegistry are garbage collected, + // clear the JSFinalizationRegistry from the list + JSFinalizationRegistry::CheckAndCall(thread); + finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue(), JSTaggedValue::Undefined()); +} + +/** + * @tc.name: CleanupFinalizationRegistry + * @tc.desc: Check current JSFinalizationRegistry, While contains any record cell such that cell and WeakRefTarget is + * empty, than remove cell from JSFinalizationRegistry and return whether there are still objects that have + * not been cleaned up. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSFinalizationRegistryTest, CleanupFinalizationRegistry) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + JSHandle target(thread, JSTaggedValue::Undefined()); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + bool isCleared = false; + vm->SetEnableForceGC(false); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken(thread, JSTaggedValue::Undefined()); + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + EXPECT_EQ(testValue, 0); + + isCleared = JSFinalizationRegistry::CleanupFinalizationRegistry(thread, finaRegObj); + EXPECT_FALSE(isCleared); + } + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + EXPECT_EQ(testValue, 1); + isCleared = JSFinalizationRegistry::CleanupFinalizationRegistry(thread, finaRegObj); + EXPECT_TRUE(isCleared); +} + +/** + * @tc.name: CleanFinRegLists + * @tc.desc: Clear the JSFinalizationRegistry object from the finalization registry lists. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSFinalizationRegistryTest, CleanFinRegLists) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + JSHandle target(factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc)); + JSHandle key(factory->NewFromASCII("key3")); + JSHandle value(thread, JSTaggedValue(3)); + JSObject::SetProperty(thread, target, key, value); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken(thread, JSTaggedValue::Undefined()); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + + JSFinalizationRegistry::Register(thread, target, heldValue, unregisterToken, finaRegObj); + JSHandle finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue(), JSHandle::Cast(finaRegObj).GetTaggedValue()); + EXPECT_EQ(testValue, 0); + + JSFinalizationRegistry::CleanFinRegLists(thread, finaRegObj); + finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue(), JSTaggedValue::Undefined()); +} + +/** + * @tc.name: AddFinRegLists + * @tc.desc: Add a JSFinalizationRegistry object to the finalization registry lists. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSFinalizationRegistryTest, AddFinRegLists) +{ + testValue = 0; + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle objectFunc = env->GetObjectFunction(); + vm->SetEnableForceGC(false); + JSHandle target(thread, JSTaggedValue::Undefined()); + { + [[maybe_unused]] EcmaHandleScope handleScope(thread); + auto obj = factory->NewJSObjectByConstructor(JSHandle(objectFunc), objectFunc); + target = JSHandle::Cast(obj); + JSHandle heldValue(thread, JSTaggedValue(100)); + JSHandle unregisterToken(thread, JSTaggedValue::Undefined()); + JSHandle constructor = CreateFinalizationRegistry(thread); + JSHandle finaRegObj(thread, constructor.GetTaggedValue()); + + JSHandle cellRecord = factory->NewCellRecord(); + cellRecord->SetToWeakRefTarget(target.GetTaggedValue()); + cellRecord->SetHeldValue(thread, heldValue); + JSHandle cell(cellRecord); + JSHandle noUnregister(thread, finaRegObj->GetNoUnregister()); + noUnregister = CellRecordVector::Append(thread, noUnregister, cell); + finaRegObj->SetNoUnregister(thread, noUnregister); + JSFinalizationRegistry::AddFinRegLists(thread, finaRegObj); + JSHandle finRegLists = env->GetFinRegLists(); + EXPECT_EQ(finRegLists.GetTaggedValue(), JSHandle::Cast(finaRegObj).GetTaggedValue()); + EXPECT_EQ(testValue, 0); + } + vm->CollectGarbage(TriggerGCType::FULL_GC); + if (!thread->HasPendingException()) { + job::MicroJobQueue::ExecutePendingJob(thread, vm->GetMicroJobQueue()); + } + vm->SetEnableForceGC(true); + EXPECT_EQ(testValue, 1); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_function_test.cpp b/ecmascript/tests/js_function_test.cpp index af2aeb864daaa82ddb656b0e54a56acca96cef30..d9d0bc72d78f5e7ac832d3363fab2231a48194ec 100644 --- a/ecmascript/tests/js_function_test.cpp +++ b/ecmascript/tests/js_function_test.cpp @@ -147,9 +147,9 @@ HWTEST_F_L0(JSFunctionTest, Invoke) JSHandle calleeValue(calleeFunc); JSObject::SetProperty(thread, JSHandle(callee), calleeKey, calleeValue); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, callee, undefined, 1); - info.SetCallArg(JSTaggedValue(1)); - JSTaggedValue res = JSFunction::Invoke(&info, calleeKey); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, undefined, callee, undefined, 1); + info->SetCallArg(JSTaggedValue(1)); + JSTaggedValue res = JSFunction::Invoke(info, calleeKey); JSTaggedValue ruler = BuiltinsBase::GetTaggedBoolean(true); EXPECT_EQ(res.GetRawData(), ruler.GetRawData()); diff --git a/ecmascript/tests/js_generator_object_test.cpp b/ecmascript/tests/js_generator_object_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bf71dac86f3ed7ea13a57a4bcce6f181cd66f90b --- /dev/null +++ b/ecmascript/tests/js_generator_object_test.cpp @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/global_env.h" +#include "ecmascript/js_generator_object.h" +#include "ecmascript/interpreter/slow_runtime_stub.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace panda::test { +class JSGeneratorObjectTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +/** + * @tc.name: GeneratorValidate + * @tc.desc: Get the current status of the generator and return it. If the generator is executing, an exception will + * be thrown. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSGeneratorObjectTest, GeneratorValidate_001) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + JSHandle genOjb = factory->NewJSGeneratorObject(env->GetGeneratorFunctionFunction()); + JSGeneratorState state = JSGeneratorObject::GeneratorValidate(thread, JSHandle::Cast(genOjb)); + EXPECT_EQ(state, JSGeneratorState::UNDEFINED); +} + +HWTEST_F_L0(JSGeneratorObjectTest, GeneratorValidate_002) +{ + auto vm = thread->GetEcmaVM(); + auto env = vm->GetGlobalEnv(); + JSTaggedValue genObjTagVal = + SlowRuntimeStub::CreateGeneratorObj(thread, env->GetGeneratorFunctionFunction().GetTaggedValue()); + JSHandle genObj(thread, genObjTagVal); + JSGeneratorState state = JSGeneratorObject::GeneratorValidate(thread, JSHandle::Cast(genObj)); + EXPECT_EQ(state, JSGeneratorState::SUSPENDED_START); +} + +HWTEST_F_L0(JSGeneratorObjectTest, GeneratorValidate_003) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + JSHandle genClass = + factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_GENERATOR_OBJECT, env->GetGeneratorFunctionPrototype()); + TaggedObject *genObjectHeader = factory->NewDynObject(genClass); + JSHandle genObj(thread, JSGeneratorObject::Cast(genObjectHeader)); + JSGeneratorState state = JSGeneratorObject::GeneratorValidate(thread, JSHandle::Cast(genObj)); + EXPECT_EQ(state, JSGeneratorState::SUSPENDED_YIELD); + + genObj->SetGeneratorState(JSGeneratorState::COMPLETED); + state = JSGeneratorObject::GeneratorValidate(thread, JSHandle::Cast(genObj)); + EXPECT_EQ(state, JSGeneratorState::COMPLETED); +} + +/** + * @tc.name: GeneratorResume + * @tc.desc: Gets the next iteration value of the generator. If the generator has completed, returns + * object(Undefined, True). + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSGeneratorObjectTest, GeneratorResume) +{ + auto vm = thread->GetEcmaVM(); + auto env = vm->GetGlobalEnv(); + JSHandle valueKey = thread->GlobalConstants()->GetHandledValueString(); + JSHandle doneKey = thread->GlobalConstants()->GetHandledDoneString(); + JSTaggedValue genObjTagVal = + SlowRuntimeStub::CreateGeneratorObj(thread, env->GetGeneratorFunctionFunction().GetTaggedValue()); + JSHandle genObj(thread, genObjTagVal); + + // If state is completed, return object(undefined, true). + genObj->SetGeneratorState(JSGeneratorState::COMPLETED); + JSHandle result = JSGeneratorObject::GeneratorResume(thread, genObj, JSTaggedValue::Undefined()); + EXPECT_EQ((JSObject::GetProperty(thread, result, valueKey).GetValue()).GetTaggedValue(), + JSTaggedValue::Undefined()); + EXPECT_EQ((JSObject::GetProperty(thread, result, doneKey).GetValue()).GetTaggedValue(), JSTaggedValue::True()); +} + +/** + * @tc.name: GeneratorResumeAbrupt + * @tc.desc: If the status of the generator is completed, the value in abruptcompletion is returned. Otherwise, the + * generator is in a suspended state, and the Return or Throw value of the generator is returned. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSGeneratorObjectTest, GeneratorResumeAbrupt) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + JSHandle valueKey = thread->GlobalConstants()->GetHandledValueString(); + JSHandle doneKey = thread->GlobalConstants()->GetHandledDoneString(); + JSTaggedValue genObjTagVal = + SlowRuntimeStub::CreateGeneratorObj(thread, env->GetGeneratorFunctionFunction().GetTaggedValue()); + JSHandle genObj(thread, genObjTagVal); + genObj->SetGeneratorState(JSGeneratorState::COMPLETED); + CompletionRecordType type = CompletionRecordType::RETURN; + JSHandle value(thread, JSTaggedValue(1)); + JSHandle abruptCompletion = factory->NewCompletionRecord(type, value); + JSHandle result = JSGeneratorObject::GeneratorResumeAbrupt(thread, genObj, abruptCompletion); + EXPECT_EQ((JSObject::GetProperty(thread, result, valueKey).GetValue()).GetTaggedValue(), JSTaggedValue(1)); + EXPECT_EQ((JSObject::GetProperty(thread, result, doneKey).GetValue()).GetTaggedValue(), JSTaggedValue::True()); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_handle_test.cpp b/ecmascript/tests/js_handle_test.cpp index 3e3d0887a2dd2ea3e8364e05f8fa1ce3872774a3..98135ab8f16ec72d7d5b1c4950ab0bd20cc39ac7 100644 --- a/ecmascript/tests/js_handle_test.cpp +++ b/ecmascript/tests/js_handle_test.cpp @@ -14,7 +14,7 @@ */ #include "ecmascript/ecma_string-inl.h" -#include "ecmascript/ecma_global_storage-inl.h" +#include "ecmascript/ecma_global_storage.h" #include "ecmascript/ecma_vm.h" #include "ecmascript/js_handle.h" #include "ecmascript/object_factory.h" diff --git a/ecmascript/tests/js_hclass_test.cpp b/ecmascript/tests/js_hclass_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c03ea57070317a95f29acf9927e2fce5b1cbd2c4 --- /dev/null +++ b/ecmascript/tests/js_hclass_test.cpp @@ -0,0 +1,429 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_hclass-inl.h" +#include "ecmascript/js_object.h" +#include "ecmascript/global_env.h" +#include "ecmascript/ic/proto_change_details.h" +#include "ecmascript/layout_info.h" +#include "ecmascript/tagged_dictionary.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace panda::test { +class JSHClassTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +HWTEST_F_L0(JSHClassTest, InitializeClass) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + // Call NewEcmaDynClass function set object properties + JSHandle objectDynclass = + factory->NewEcmaDynClass(TaggedArray::SIZE, JSType::TAGGED_ARRAY, nullHandle); + // Get object properties + EXPECT_EQ(objectDynclass->GetLayout(), JSTaggedValue::Null()); + EXPECT_EQ(objectDynclass->GetPrototype(), JSTaggedValue::Null()); + EXPECT_EQ(objectDynclass->GetObjectType(), JSType::TAGGED_ARRAY); + EXPECT_TRUE(objectDynclass->IsExtensible()); + EXPECT_TRUE(!objectDynclass->IsPrototype()); + EXPECT_EQ(objectDynclass->GetTransitions(), JSTaggedValue::Undefined()); + EXPECT_EQ(objectDynclass->GetProtoChangeMarker(), JSTaggedValue::Null()); + EXPECT_EQ(objectDynclass->GetProtoChangeDetails(), JSTaggedValue::Null()); + EXPECT_EQ(objectDynclass->GetEnumCache(), JSTaggedValue::Null()); +} + +HWTEST_F_L0(JSHClassTest, SizeFromJSHClass) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + + JSHandle objectDynclass = factory->NewEcmaDynClass(TaggedArray::SIZE, JSType::TAGGED_ARRAY, nullHandle); + EXPECT_TRUE(*objectDynclass != nullptr); + size_t objectSize; +#ifndef PANDA_TARGET_32 + objectSize = objectDynclass->SizeFromJSHClass(*objectDynclass); + EXPECT_EQ(objectSize, 40U); +#endif + objectDynclass = factory->NewEcmaDynClass(EcmaString::SIZE, JSType::STRING, nullHandle); + objectSize = objectDynclass->SizeFromJSHClass(*objectDynclass); + EXPECT_EQ(objectSize, 16U); + + objectDynclass = factory->NewEcmaDynClass(MachineCode::SIZE, JSType::MACHINE_CODE_OBJECT, nullHandle); + objectSize = objectDynclass->SizeFromJSHClass(*objectDynclass); + EXPECT_EQ(objectSize, 24U); + // size is an integral multiple of eight + objectDynclass = factory->NewEcmaDynClass(JSObject::SIZE - 1, JSType::JS_OBJECT, nullHandle); + objectSize = objectDynclass->SizeFromJSHClass(*objectDynclass); + EXPECT_EQ(objectSize, 56U); + + objectDynclass = factory->NewEcmaDynClass(JSObject::SIZE + 1, JSType::JS_OBJECT, nullHandle); + objectSize = objectDynclass->SizeFromJSHClass(*objectDynclass); + EXPECT_EQ(objectSize, 64U); + + objectDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, nullHandle); + objectSize = objectDynclass->SizeFromJSHClass(*objectDynclass); + EXPECT_EQ(objectSize, 64U); +} + +HWTEST_F_L0(JSHClassTest, HasReferenceField) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + + JSHandle obj1Dynclass = factory->NewEcmaDynClass(TaggedArray::SIZE, JSType::STRING, nullHandle); + JSHandle obj2Dynclass = + factory->NewEcmaDynClass(TaggedArray::SIZE, JSType::JS_NATIVE_POINTER, nullHandle); + JSHandle obj3Dynclass = factory->NewEcmaDynClass(TaggedArray::SIZE, JSType::JS_OBJECT, nullHandle); + EXPECT_FALSE(obj1Dynclass->HasReferenceField()); + EXPECT_FALSE(obj2Dynclass->HasReferenceField()); + EXPECT_TRUE(obj3Dynclass->HasReferenceField()); +} + +HWTEST_F_L0(JSHClassTest, Clone) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + + JSHandle objectDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, nullHandle); + // withoutInlinedProperties is false + JSHandle cloneDynclass = JSHClass::Clone(thread, objectDynclass, false); + EXPECT_TRUE(*cloneDynclass != nullptr); + EXPECT_TRUE(objectDynclass->GetObjectSize() == cloneDynclass->GetObjectSize()); + EXPECT_EQ(cloneDynclass->GetObjectSize(), 64U); // 64 : 64 not missing the size of inlinedproperties + EXPECT_TRUE(objectDynclass->GetLayout() == cloneDynclass->GetLayout()); + EXPECT_EQ(JSTaggedValue::SameValue(objectDynclass->GetPrototype(), cloneDynclass->GetPrototype()), true); + EXPECT_TRUE(objectDynclass->GetBitField() == cloneDynclass->GetBitField()); + EXPECT_TRUE(objectDynclass->GetBitField1() == cloneDynclass->GetBitField1()); + EXPECT_TRUE(objectDynclass->NumberOfProps() == cloneDynclass->NumberOfProps()); + EXPECT_EQ(cloneDynclass->GetNextInlinedPropsIndex(), 0); // 0 : 0 mean index + // withoutInlinedProperties is true + cloneDynclass = JSHClass::Clone(thread, objectDynclass, true); + EXPECT_TRUE(*cloneDynclass != nullptr); + EXPECT_TRUE(objectDynclass->GetObjectSize() > cloneDynclass->GetObjectSize()); + EXPECT_EQ(cloneDynclass->GetObjectSize(), 32U); // 32 : 32 missing the size of inlinedproperties + EXPECT_TRUE(objectDynclass->GetLayout() == cloneDynclass->GetLayout()); + EXPECT_EQ(JSTaggedValue::SameValue(objectDynclass->GetPrototype(), cloneDynclass->GetPrototype()), true); + EXPECT_TRUE(objectDynclass->GetBitField() == cloneDynclass->GetBitField()); + EXPECT_TRUE(objectDynclass->GetBitField1() > cloneDynclass->GetBitField1()); + EXPECT_TRUE(objectDynclass->NumberOfProps() == cloneDynclass->NumberOfProps()); + EXPECT_EQ(cloneDynclass->GetNextNonInlinedPropsIndex(), 0); // 0 : 0 mean index +} + +HWTEST_F_L0(JSHClassTest, TransitionElementsToDictionary) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + + JSHandle env = vm->GetGlobalEnv(); + JSHandle objFun = env->GetObjectFunction(); + JSHandle jsObject = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSHandle objectClass(thread, jsObject->GetJSHClass()); + JSHandle objKey1(factory->NewFromASCII("key1")); + JSHandle objKey2(factory->NewFromASCII("key2")); + JSHandle objKey3(factory->NewFromASCII("key3")); + + JSHandle objValue1(thread, JSTaggedValue(1)); + JSHandle objValue2(thread, JSTaggedValue(2)); + JSHandle objValue3(thread, JSTaggedValue(3)); + + JSObject::SetProperty(thread, JSHandle(jsObject), objKey1, objValue1); + JSObject::SetProperty(thread, JSHandle(jsObject), objKey2, objValue2); + JSObject::SetProperty(thread, JSHandle(jsObject), objKey3, objValue3); + // class is not dictionary mode + EXPECT_FALSE(jsObject->GetJSHClass()->IsDictionaryMode()); + JSHClass::TransitionElementsToDictionary(thread, jsObject); + auto resultDict = NameDictionary::Cast(jsObject->GetProperties().GetTaggedObject()); + EXPECT_TRUE(resultDict != nullptr); + EXPECT_EQ(resultDict->EntriesCount(), 3); // 3 : 3 entry + + JSHandle dictionaryClass(thread, jsObject->GetJSHClass()); + EXPECT_TRUE(dictionaryClass->IsDictionaryMode()); + EXPECT_EQ(dictionaryClass->GetObjectSize() + 32U, objectClass->GetObjectSize()); + EXPECT_TRUE(dictionaryClass->IsDictionaryElement()); + EXPECT_FALSE(dictionaryClass->IsStableElements()); +} + +static JSHandle CreateJSHClass(JSThread *thread) +{ + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle objectFuncPrototype = env->GetObjectFunctionPrototype(); + JSHandle hclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, objectFuncPrototype); + return hclass; +} + +HWTEST_F_L0(JSHClassTest, SetPropertyOfObjHClass_001) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle accessorData(factory->NewAccessorData()); + JSHandle keyHandle = factory->NewFromASCII("key"); + JSHandle keyHandle0(factory->NewFromASCII("key0")); + JSHandle keyHandle2(factory->NewFromASCII("key2")); + JSHandle keyHandle4(factory->NewFromASCII("key4")); + // empty layoutInfo + JSHandle parentsDynclass = CreateJSHClass(thread); + + uint32_t length = 6; + JSHandle properties = factory->NewTaggedArray(length); + for (int i = 0; i < static_cast(length); i++) { + if (i % 2 == 0) { + JSHandle newValue(thread, JSTaggedValue(i)); + JSHandle newKey = + factory->ConcatFromString(keyHandle, JSTaggedValue::ToString(thread, newValue)); + properties->Set(thread, i, newKey.GetTaggedValue()); + continue; + } + properties->Set(thread, i, accessorData.GetTaggedValue()); + } + JSHandle childDynclass = factory->SetLayoutInObjHClass(properties, 3, parentsDynclass); + JSHandle childObj = factory->NewJSObject(childDynclass); + + std::vector keyVector; + JSObject::GetAllKeys(childObj, keyVector); + EXPECT_EQ(keyVector.size(), 3U); + EXPECT_TRUE(JSObject::HasProperty(thread, childObj, keyHandle0)); + EXPECT_TRUE(JSObject::HasProperty(thread, childObj, keyHandle2)); + EXPECT_TRUE(JSObject::HasProperty(thread, childObj, keyHandle4)); +} + +HWTEST_F_L0(JSHClassTest, SetPropertyOfObjHClass_002) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle objDynclass = CreateJSHClass(thread); + JSHandle Obj1 = factory->NewJSObject(objDynclass); + JSHandle Obj2 = factory->NewJSObject(objDynclass); + PropertyAttributes attr = PropertyAttributes::Default(); + + JSHandle keyE(factory->NewFromASCII("e")); + JSHandle keyF(factory->NewFromASCII("f")); + // not empty layoutInfo + JSObject::SetProperty(thread, Obj1, keyE, JSHandle(thread, JSTaggedValue(7))); + JSObject::SetProperty(thread, Obj2, keyF, JSHandle(thread, JSTaggedValue(8))); + + JSHandle propertyHclass = JSHClass::SetPropertyOfObjHClass(thread, objDynclass, keyE, attr); + JSHandle obj1Class(thread, Obj1->GetClass()); + EXPECT_TRUE(propertyHclass == obj1Class); + + propertyHclass = JSHClass::SetPropertyOfObjHClass(thread, objDynclass, keyF, attr); + JSHandle obj2Class(thread, Obj2->GetClass()); + EXPECT_TRUE(propertyHclass == obj2Class); +} + +HWTEST_F_L0(JSHClassTest, AddProperty) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle keyHandle = factory->NewFromASCII("key"); + JSHandle keyHandle0(factory->NewFromASCII("key0")); + JSHandle keyHandle1(factory->NewFromASCII("key1")); + JSHandle keyHandle2(factory->NewFromASCII("key2")); + PropertyAttributes attr = PropertyAttributes::Default(); + attr.SetIsInlinedProps(true); + // empty layoutInfo + JSHandle objDynclass = CreateJSHClass(thread); + JSHandle Obj = factory->NewJSObject(objDynclass); + JSHandle objClass(thread, Obj->GetClass()); + EXPECT_FALSE(objDynclass != objClass); + int keyLength = 3; + for (int i = 0; i keyValue(thread, JSTaggedValue(i)); + JSHandle keyHandleI( + factory->ConcatFromString(keyHandle, JSTaggedValue::ToString(thread, keyValue))); + attr.SetOffset(i); + JSHClass::AddProperty(thread, Obj, keyHandleI, attr); + } + EXPECT_TRUE(objDynclass == objClass); + std::vector keyVector; + JSObject::GetAllKeys(Obj, keyVector); + EXPECT_EQ(keyVector.size(), 3U); + EXPECT_TRUE(JSObject::HasProperty(thread, Obj, keyHandle0)); + EXPECT_TRUE(JSObject::HasProperty(thread, Obj, keyHandle1)); + EXPECT_TRUE(JSObject::HasProperty(thread, Obj, keyHandle2)); +} + +HWTEST_F_L0(JSHClassTest, TransitionExtension) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle preExtensionsKey = thread->GlobalConstants()->GetHandledPreventExtensionsString(); + JSHandle keyHandle0(factory->NewFromASCII("key0")); + JSHandle keyHandle1(factory->NewFromASCII("key1")); + JSHandle keyHandle2(factory->NewFromASCII("key2")); + PropertyAttributes attr = PropertyAttributes(0); + attr.SetIsInlinedProps(true); + JSHandle obj1DynClass = CreateJSHClass(thread); + JSHandle obj2DynClass = CreateJSHClass(thread); + obj2DynClass->SetExtensible(true); + JSHandle Obj1 = factory->NewJSObject(obj1DynClass); + JSHandle Obj2 = factory->NewJSObject(obj2DynClass); + JSObject::SetProperty(thread, Obj2, keyHandle0, JSHandle(thread, JSTaggedValue(7))); + JSObject::SetProperty(thread, Obj2, keyHandle1, JSHandle(thread, JSTaggedValue(8))); + JSObject::SetProperty(thread, Obj2, keyHandle2, JSHandle(thread, JSTaggedValue(9))); + // obj has key "PreventExtensions" + JSHClass::AddProperty(thread, Obj1, preExtensionsKey, attr); + JSHandle newDynClass1 = JSHClass::TransitionExtension(thread, obj1DynClass); + JSHandle objClass(thread, Obj1->GetClass()); + EXPECT_TRUE(newDynClass1 == objClass); + // obj has no key "PreventExtensions" + JSHandle newDynClass2 = JSHClass::TransitionExtension(thread, obj2DynClass); + EXPECT_FALSE(newDynClass2->IsExtensible()); + JSHandle dictionary(thread, obj2DynClass->GetTransitions()); + // find key + std::vector keyVector; + dictionary->GetAllKeysIntoVector(keyVector); + EXPECT_EQ(keyVector[0], keyHandle0.GetTaggedValue()); + EXPECT_EQ(keyVector[1], preExtensionsKey.GetTaggedValue()); +} + +HWTEST_F_L0(JSHClassTest, TransitionProto) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle env =vm->GetGlobalEnv(); + JSHandle funcPrototype = env->GetFunctionPrototype(); + JSHandle prototypeKey = thread->GlobalConstants()->GetHandledPrototypeString(); + JSHandle obj1Key(factory->NewFromASCII("key0")); + JSHandle obj2Key(factory->NewFromASCII("key1")); + JSHandle obj3Key(factory->NewFromASCII("key2")); + PropertyAttributes attr = PropertyAttributes(0); + attr.SetIsInlinedProps(true); + JSHandle objDynClass = CreateJSHClass(thread); + JSHandle Obj = factory->NewJSObject(objDynClass); + // obj has no key "prototype" + JSHClass::AddProperty(thread, Obj, obj1Key, attr); + JSHClass::AddProperty(thread, Obj, obj2Key, attr); + JSHClass::AddProperty(thread, Obj, obj3Key, attr); + JSHandle newDynClass = JSHClass::TransitionProto(thread, objDynClass, funcPrototype); + EXPECT_EQ(newDynClass->GetPrototype(), funcPrototype.GetTaggedValue()); + JSHandle transitionDictionary(thread, objDynClass->GetTransitions()); + // find key + std::vector keyVector; + transitionDictionary->GetAllKeysIntoVector(keyVector); + EXPECT_EQ(keyVector.size(), 2U); + EXPECT_EQ(keyVector[0], obj1Key.GetTaggedValue()); + EXPECT_EQ(keyVector[1], prototypeKey.GetTaggedValue()); +} + +HWTEST_F_L0(JSHClassTest, TransitionToDictionary) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle obj1Key(factory->NewFromASCII("key1")); + JSHandle obj2Key(factory->NewFromASCII("key2")); + JSHandle obj3Key(factory->NewFromASCII("key3")); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + JSHandle objDynclass = CreateJSHClass(thread); + objDynclass->SetIsPrototype(true); + JSHandle Obj0 = factory->NewJSObject(objDynclass); + JSHandle obj0Dynclass(thread, Obj0->GetJSHClass()); + JSHandle Obj1 = JSObject::ObjectCreate(thread, nullHandle); + JSHandle Obj2 = JSObject::ObjectCreate(thread, Obj1); + JSHandle obj2Dynclass(thread, Obj2->GetJSHClass()); + JSHandle Obj3 = JSObject::ObjectCreate(thread, Obj2); + JSObject::SetProperty(thread, Obj1, obj1Key, JSHandle(thread, JSTaggedValue(100))); + JSObject::SetProperty(thread, Obj2, obj2Key, JSHandle(thread, JSTaggedValue(101))); + JSObject::SetProperty(thread, Obj3, obj3Key, JSHandle(thread, JSTaggedValue(102))); + // empty object + JSHClass::TransitionToDictionary(thread, Obj0); + JSHandle obj0Class(thread, Obj0->GetClass()); + EXPECT_TRUE(obj0Class->GetObjectSize() < obj0Dynclass->GetObjectSize()); + EXPECT_EQ(obj0Class->NumberOfProps(), 0U); + EXPECT_TRUE(obj0Class->IsDictionaryMode()); + EXPECT_TRUE(obj0Class->IsPrototype()); + // not empty object + JSHandle obj3Dynclass(thread, Obj3->GetJSHClass()); + JSHClass::EnableProtoChangeMarker(thread, obj3Dynclass); + JSHClass::TransitionToDictionary(thread, Obj2); + // refresh users + JSHandle obj1Dynclass(thread, Obj1->GetJSHClass()); + JSTaggedValue protoDetails = obj1Dynclass->GetProtoChangeDetails(); + EXPECT_TRUE(protoDetails.IsProtoChangeDetails()); + JSTaggedValue listenersValue = ProtoChangeDetails::Cast(protoDetails.GetTaggedObject())->GetChangeListener(); + JSHandle listeners(thread, listenersValue.GetTaggedObject()); + uint32_t holeIndex = ChangeListener::CheckHole(listeners); + EXPECT_TRUE(holeIndex == 0U); + // new class + JSHandle newClass(thread, Obj2->GetClass()); + EXPECT_TRUE(newClass->GetObjectSize() < obj2Dynclass->GetObjectSize()); + EXPECT_EQ(newClass->NumberOfProps(), 0U); + EXPECT_TRUE(newClass->IsDictionaryMode()); + EXPECT_TRUE(newClass->IsPrototype()); +} + +HWTEST_F_L0(JSHClassTest, UpdatePropertyMetaData) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle objKey(factory->NewFromASCII("key0")); + PropertyAttributes oldAttr = PropertyAttributes(0); + PropertyAttributes newAttr = PropertyAttributes(1); + oldAttr.SetIsInlinedProps(true); + JSHandle objDynClass = CreateJSHClass(thread); + JSHandle Obj = factory->NewJSObject(objDynClass); + // Set Transitions + JSHClass::AddProperty(thread, Obj, objKey, oldAttr); + // update metaData + objDynClass->UpdatePropertyMetaData(thread, objKey.GetTaggedValue(), newAttr); + LayoutInfo *layoutInfo = LayoutInfo::Cast(objDynClass->GetLayout().GetTaggedObject()); + EXPECT_EQ(layoutInfo->GetAttr(oldAttr.GetOffset()).GetPropertyMetaData(), newAttr.GetPropertyMetaData()); +} + +HWTEST_F_L0(JSHClassTest, SetPrototype) +{ + EcmaVM *vm = thread->GetEcmaVM(); + ObjectFactory *factory = vm->GetFactory(); + JSHandle env =vm->GetGlobalEnv(); + JSHandle nullHandle(thread, JSTaggedValue::Null()); + JSHandle objectFuncPrototype = env->GetObjectFunctionPrototype(); + + JSHandle objectDynclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, nullHandle); + EXPECT_EQ(objectDynclass->GetPrototype(), nullHandle.GetTaggedValue()); + objectDynclass->SetPrototype(thread, objectFuncPrototype); + EXPECT_EQ(objectDynclass->GetPrototype(), objectFuncPrototype.GetTaggedValue()); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_list_format_test.cpp b/ecmascript/tests/js_list_format_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..019f9253db8f3683f9d0a00cc0a7e2efd262b3d0 --- /dev/null +++ b/ecmascript/tests/js_list_format_test.cpp @@ -0,0 +1,357 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/global_env.h" +#include "ecmascript/js_array.h" +#include "ecmascript/js_list_format.h" +#include "ecmascript/js_iterator.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda::ecmascript; + +namespace panda::test { +class JSListFormatTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + JSRuntimeOptions options; +#if PANDA_TARGET_LINUX + // for consistency requirement, use ohos_icu4j/data/icudt67l.dat as icu-data-path + options.SetIcuDataPath(ICU_PATH); +#endif + options.SetEnableForceGC(true); + instance = JSNApi::CreateEcmaVM(options); + instance->SetEnableForceGC(true); + ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM"; + thread = instance->GetJSThread(); + scope = new EcmaHandleScope(thread); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +HWTEST_F_L0(JSListFormatTest, Set_Get_IcuListFormatter_001) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + JSHandle ctor = env->GetListFormatFunction(); + JSHandle jsFormatter = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); + UErrorCode status = UErrorCode::U_ZERO_ERROR; + icu::Locale icuLocale("en", "Latn", "US"); + icu::ListFormatter* icuFormatter = icu::ListFormatter::createInstance(icuLocale, status); + JSListFormat::SetIcuListFormatter(thread, jsFormatter, icuFormatter, JSListFormat::FreeIcuListFormatter); + icu::ListFormatter *resFormatter = jsFormatter->GetIcuListFormatter(); + EXPECT_TRUE(resFormatter != nullptr); + + const int32_t itemNum = 3; + const icu::UnicodeString items[itemNum] = { "One", "Two", "Three" }; + icu::UnicodeString resStr = ""; + resStr = resFormatter->format(items, itemNum, resStr, status); + const icu::UnicodeString expectResStr("One, Two, and Three"); + EXPECT_TRUE(resStr.compare(expectResStr) == 0); +} + +HWTEST_F_L0(JSListFormatTest, Set_Get_IcuListFormatter_002) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + JSHandle ctor = env->GetListFormatFunction(); + JSHandle jsFormatter = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); + UErrorCode status = UErrorCode::U_ZERO_ERROR; + icu::Locale icuLocale("zh", "Hans", "Cn"); + icu::ListFormatter* icuFormatter = icu::ListFormatter::createInstance(icuLocale, status); + JSListFormat::SetIcuListFormatter(thread, jsFormatter, icuFormatter, JSListFormat::FreeIcuListFormatter); + icu::ListFormatter *resFormatter = jsFormatter->GetIcuListFormatter(); + EXPECT_TRUE(resFormatter != nullptr); + + const int32_t itemNum = 3; + const icu::UnicodeString items[itemNum] = { "一", "二", "三" }; + icu::UnicodeString resStr = ""; + resStr = resFormatter->format(items, itemNum, resStr, status); + const icu::UnicodeString expectResStr("一、二和三"); + EXPECT_TRUE(resStr.compare(expectResStr) == 0); +} + +JSHandle CreateJSListFormatterTest(JSThread *thread, icu::Locale icuLocale, JSHandle options) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + + JSHandle localeCtor = env->GetLocaleFunction(); + JSHandle listCtor = env->GetListFormatFunction(); + JSHandle locales = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(localeCtor), localeCtor)); + JSHandle listFormatter = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(listCtor), listCtor)); + + JSHandle optionsVal = JSHandle::Cast(options); + factory->NewJSIntlIcuData(locales, icuLocale, JSLocale::FreeIcuLocale); + listFormatter = JSListFormat::InitializeListFormat(thread, listFormatter, + JSHandle::Cast(locales), optionsVal); + return listFormatter; +} + +void SetFormatterOptionsTest(JSThread *thread, JSHandle &optionsObj, + std::map &options) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto globalConst = thread->GlobalConstants(); + JSHandle localeMatcherKey = globalConst->GetHandledLocaleMatcherString(); + JSHandle typeKey = globalConst->GetHandledTypeString(); + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle localeMatcherValue(factory->NewFromASCII(options["localeMatcher"].c_str())); + JSHandle typeValue(factory->NewFromASCII(options["type"].c_str())); + JSHandle styleValue(factory->NewFromASCII(options["style"].c_str())); + JSObject::SetProperty(thread, optionsObj, localeMatcherKey, localeMatcherValue); + JSObject::SetProperty(thread, optionsObj, typeKey, typeValue); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); +} + +HWTEST_F_L0(JSListFormatTest, InitializeListFormat) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + icu::Locale icuLocale("en", "Latn", "US"); + JSHandle objFun = env->GetObjectFunction(); + JSHandle object = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + std::map options { + { "localeMatcher", "best fit" }, + { "type", "conjunction" }, + { "style", "long" } + }; + SetFormatterOptionsTest(thread, object, options); + JSHandle localeCtor = env->GetLocaleFunction(); + JSHandle listCtor = env->GetListFormatFunction(); + JSHandle locales = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(localeCtor), localeCtor)); + JSHandle listFormatter = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(listCtor), listCtor)); + + JSHandle optionsVal = JSHandle::Cast(object); + factory->NewJSIntlIcuData(locales, icuLocale, JSLocale::FreeIcuLocale); + listFormatter = JSListFormat::InitializeListFormat(thread, listFormatter, + JSHandle::Cast(locales), optionsVal); + icu::ListFormatter *resFormatter = listFormatter->GetIcuListFormatter(); + EXPECT_TRUE(resFormatter != nullptr); + + const int32_t itemNum = 3; + UErrorCode status = UErrorCode::U_ZERO_ERROR; + const icu::UnicodeString items[itemNum] = { "Monday", "Tuesday", "Wednesday" }; + icu::UnicodeString resStr = ""; + resStr = resFormatter->format(items, itemNum, resStr, status); + const icu::UnicodeString expectResStr("Monday, Tuesday, and Wednesday"); + EXPECT_TRUE(resStr.compare(expectResStr) == 0); +} + +HWTEST_F_L0(JSListFormatTest, FormatList_001) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + icu::Locale icuLocale("en", "Latn", "US"); + JSHandle objFun = env->GetObjectFunction(); + JSHandle object = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + std::map options { + { "localeMatcher", "best fit" }, + { "type", "conjunction" }, + { "style", "long" } + }; + SetFormatterOptionsTest(thread, object, options); + JSHandle jsFormatter = CreateJSListFormatterTest(thread, icuLocale, object); + JSHandle valueObj = JSHandle::Cast(factory->NewJSArray()); + JSHandle key0(thread, JSTaggedValue(0)); + JSHandle key1(thread, JSTaggedValue(1)); + JSHandle key2(thread, JSTaggedValue(2)); + JSHandle value0(factory->NewFromStdString("Zero")); + JSHandle value1(factory->NewFromStdString("One")); + JSHandle value2(factory->NewFromStdString("Two")); + JSObject::SetProperty(thread, valueObj, key0, value0); + JSObject::SetProperty(thread, valueObj, key1, value1); + JSObject::SetProperty(thread, valueObj, key2, value2); + JSHandle valueArr = JSHandle::Cast(valueObj); + JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); + EXPECT_STREQ(CString(valueStr->GetCString().get()).c_str(), "Zero, One, and Two"); +} + +HWTEST_F_L0(JSListFormatTest, FormatList_002) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + icu::Locale icuLocale("en", "Latn", "US"); + JSHandle objFun = env->GetObjectFunction(); + JSHandle object = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + // when style is narrow, type can only be unit + std::map options { + { "localeMatcher", "best fit" }, + { "type", "unit" }, + { "style", "narrow" } + }; + SetFormatterOptionsTest(thread, object, options); + JSHandle jsFormatter = CreateJSListFormatterTest(thread, icuLocale, object); + JSHandle valueObj = JSHandle::Cast(factory->NewJSArray()); + JSHandle key0(thread, JSTaggedValue(0)); + JSHandle key1(thread, JSTaggedValue(1)); + JSHandle key2(thread, JSTaggedValue(2)); + JSHandle value0(factory->NewFromStdString("Zero")); + JSHandle value1(factory->NewFromStdString("One")); + JSHandle value2(factory->NewFromStdString("Two")); + JSObject::SetProperty(thread, valueObj, key0, value0); + JSObject::SetProperty(thread, valueObj, key1, value1); + JSObject::SetProperty(thread, valueObj, key2, value2); + JSHandle valueArr = JSHandle::Cast(valueObj); + JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); + EXPECT_STREQ(CString(valueStr->GetCString().get()).c_str(), "Zero One Two"); +} + +HWTEST_F_L0(JSListFormatTest, FormatList_003) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + icu::Locale icuLocale("zh", "Hans", "Cn"); + JSHandle objFun = env->GetObjectFunction(); + JSHandle object = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + std::map options { + { "localeMatcher", "best fit" }, + { "type", "disjunction" }, + { "style", "long" } + }; + SetFormatterOptionsTest(thread, object, options); + JSHandle jsFormatter = CreateJSListFormatterTest(thread, icuLocale, object); + JSHandle valueObj = JSHandle::Cast(factory->NewJSArray()); + JSHandle key0(thread, JSTaggedValue(0)); + JSHandle key1(thread, JSTaggedValue(1)); + JSHandle key2(thread, JSTaggedValue(2)); + JSHandle value0(factory->NewFromStdString("苹果")); + JSHandle value1(factory->NewFromStdString("梨子")); + JSHandle value2(factory->NewFromStdString("桃")); + JSObject::SetProperty(thread, valueObj, key0, value0); + JSObject::SetProperty(thread, valueObj, key1, value1); + JSObject::SetProperty(thread, valueObj, key2, value2); + JSHandle valueArr = JSHandle::Cast(valueObj); + JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); + EXPECT_STREQ(CString(valueStr->GetCString().get()).c_str(), "苹果、梨子或桃"); +} + +std::string GetListPartStringTest(JSThread *thread, JSHandle key, JSHandle part) +{ + JSHandle partObj = JSHandle::Cast(part); + JSHandle partValue = JSObject::GetProperty(thread, partObj, key).GetValue(); + JSHandle partEcmaStr = JSHandle::Cast(partValue); + std::string partStr = JSLocale::ConvertToStdString(partEcmaStr); + return partStr; +} + +HWTEST_F_L0(JSListFormatTest, FormatListToParts) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + auto env = vm->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + icu::Locale icuLocale("zh", "Hans", "Cn"); + JSHandle objFun = env->GetObjectFunction(); + JSHandle object = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + std::map options { + { "localeMatcher", "best fit" }, + { "type", "conjunction" }, + { "style", "long" } + }; + SetFormatterOptionsTest(thread, object, options); + JSHandle jsFormatter = CreateJSListFormatterTest(thread, icuLocale, object); + JSHandle valueObj = JSHandle::Cast(factory->NewJSArray()); + JSHandle key0(thread, JSTaggedValue(0)); + JSHandle key1(thread, JSTaggedValue(1)); + JSHandle key2(thread, JSTaggedValue(2)); + JSHandle value0(factory->NewFromStdString("苹果")); + JSHandle value1(factory->NewFromStdString("梨子")); + JSHandle value2(factory->NewFromStdString("桃")); + JSObject::SetProperty(thread, valueObj, key0, value0); + JSObject::SetProperty(thread, valueObj, key1, value1); + JSObject::SetProperty(thread, valueObj, key2, value2); + JSHandle valueArr = JSHandle::Cast(valueObj); + JSHandle valueStr = JSListFormat::FormatList(thread, jsFormatter, valueArr); + EXPECT_STREQ(CString(valueStr->GetCString().get()).c_str(), "苹果、梨子和桃"); + + JSHandle typeKey = globalConst->GetHandledTypeString(); + JSHandle valueKey = globalConst->GetHandledValueString(); + JSHandle parts = JSListFormat::FormatListToParts(thread, jsFormatter, valueArr); + auto element1 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(parts), 0).GetValue(); + auto literal1 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(parts), 1).GetValue(); + auto element2 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(parts), 2).GetValue(); + auto literal2 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(parts), 3).GetValue(); + auto element3 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(parts), 4).GetValue(); + EXPECT_STREQ(GetListPartStringTest(thread, typeKey, element1).c_str(), "element"); + EXPECT_STREQ(GetListPartStringTest(thread, valueKey, element1).c_str(), "苹果"); + EXPECT_STREQ(GetListPartStringTest(thread, typeKey, literal1).c_str(), "literal"); + EXPECT_STREQ(GetListPartStringTest(thread, valueKey, literal1).c_str(), "、"); + EXPECT_STREQ(GetListPartStringTest(thread, typeKey, element2).c_str(), "element"); + EXPECT_STREQ(GetListPartStringTest(thread, valueKey, element2).c_str(), "梨子"); + EXPECT_STREQ(GetListPartStringTest(thread, typeKey, literal2).c_str(), "literal"); + EXPECT_STREQ(GetListPartStringTest(thread, valueKey, literal2).c_str(), "和"); + EXPECT_STREQ(GetListPartStringTest(thread, typeKey, element3).c_str(), "element"); + EXPECT_STREQ(GetListPartStringTest(thread, valueKey, element3).c_str(), "桃"); +} + +HWTEST_F_L0(JSListFormatTest, StringListFromIterable) +{ + auto vm = thread->GetEcmaVM(); + auto factory = vm->GetFactory(); + JSHandle data = factory->NewTaggedArray(3); + JSHandle value0(factory->NewFromStdString("one")); + JSHandle value1(factory->NewFromStdString("two")); + JSHandle value2(factory->NewFromStdString("three")); + data->Set(thread, 0, value0.GetTaggedValue()); + data->Set(thread, 1, value1.GetTaggedValue()); + data->Set(thread, 2, value2.GetTaggedValue()); + JSHandle array(JSArray::CreateArrayFromList(thread, data)); + JSHandle iter(JSIterator::GetIterator(thread, array)); + JSHandle arrayString = + JSListFormat::StringListFromIterable(thread, JSHandle::Cast(iter)); + JSHandle strValue = JSHandle::Cast(arrayString); + EXPECT_EQ(strValue->GetArrayLength(), 3U); + + auto resValue0 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(strValue), 0).GetValue(); + auto resValue1 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(strValue), 1).GetValue(); + auto resValue2 = JSTaggedValue::GetProperty(thread, JSHandle::Cast(strValue), 2).GetValue(); + EXPECT_STREQ(CString(JSHandle::Cast(resValue0)->GetCString().get()).c_str(), "one"); + EXPECT_STREQ(CString(JSHandle::Cast(resValue1)->GetCString().get()).c_str(), "two"); + EXPECT_STREQ(CString(JSHandle::Cast(resValue2)->GetCString().get()).c_str(), "three"); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_number_format_test.cpp b/ecmascript/tests/js_number_format_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e78ab5d829f31626033478b439f52648165ba2e3 --- /dev/null +++ b/ecmascript/tests/js_number_format_test.cpp @@ -0,0 +1,224 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_number_format.h" +#include "ecmascript/napi/jsnapi_helper.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda::ecmascript; + +namespace panda::test { +class JSNumberFormatTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + JSRuntimeOptions options; +#if PANDA_TARGET_LINUX + // for consistency requirement, use ohos_icu4j/data/icudt67l.dat as icu-data-path + options.SetIcuDataPath(ICU_PATH); +#endif + options.SetEnableForceGC(true); + instance = JSNApi::CreateEcmaVM(options); + instance->SetEnableForceGC(true); + ASSERT_TRUE(instance != nullptr) << "Cannot create EcmaVM"; + thread = instance->GetJSThread(); + scope = new EcmaHandleScope(thread); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +/** + * @tc.name: GetIcuCallTarget + * @tc.desc: Call "NewJSIntlIcuData" function Set IcuCallTarget,check whether the IcuCallTarget through + * "GetIcuCallTarget" function is within expectations then call "formatInt" function format + * Int type data and check the returned value is within expectations. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSNumberFormatTest, GetIcuCallTarget) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + + JSHandle ctor = env->GetNumberFormatFunction(); + JSHandle numberFormat = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); + + icu::Locale icuLocale("en", "US"); + icu::number::LocalizedNumberFormatter icuNumberFormatter = + icu::number::NumberFormatter::withLocale(icuLocale).roundingMode(UNUM_ROUND_HALFUP); + // Set IcuCallTarget + factory->NewJSIntlIcuData(numberFormat, icuNumberFormatter, JSNumberFormat::FreeIcuNumberformat); + icu::number::LocalizedNumberFormatter *resultIcuNumberFormatter = numberFormat->GetIcuCallTarget(); + EXPECT_TRUE(resultIcuNumberFormatter != nullptr); + // Use IcuCallTarget format Int + int64_t value = -123456; + UErrorCode status = U_ZERO_ERROR; + icu::number::FormattedNumber formattedNumber = resultIcuNumberFormatter->formatInt(value, status); + icu::UnicodeString result = formattedNumber.toString(status); + JSHandle stringValue = JSLocale::IcuToString(thread, result); + EXPECT_STREQ("-123,456", CString(stringValue->GetCString().get()).c_str()); +} + +/** + * @tc.name: InitializeNumberFormat + * @tc.desc: Call "InitializeNumberFormat" function Initialize NumberFormat,and check whether the properties of + * the object is within expectations. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSNumberFormatTest, InitializeNumberFormat) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + + JSHandle ctor = env->GetNumberFormatFunction(); + JSHandle numberFormat = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); + EXPECT_TRUE(*numberFormat != nullptr); + + JSHandle locales(factory->NewFromASCII("zh-Hans-CN")); + JSHandle undefinedOptions(thread, JSTaggedValue::Undefined()); + JSNumberFormat::InitializeNumberFormat(thread, numberFormat, locales, undefinedOptions); + // Initialize attribute comparison + EXPECT_TRUE(numberFormat->GetNumberingSystem().IsUndefined()); + JSHandle localeStr(thread, numberFormat->GetLocale().GetTaggedObject()); + EXPECT_STREQ("zh-Hans-CN", CString(localeStr->GetCString().get()).c_str()); + EXPECT_EQ(NotationOption::STANDARD, numberFormat->GetNotation()); + EXPECT_EQ(CompactDisplayOption::SHORT, numberFormat->GetCompactDisplay()); + EXPECT_EQ(SignDisplayOption::AUTO, numberFormat->GetSignDisplay()); + EXPECT_EQ(CurrencyDisplayOption::SYMBOL, numberFormat->GetCurrencyDisplay()); + EXPECT_EQ(CurrencySignOption::STANDARD, numberFormat->GetCurrencySign()); + EXPECT_EQ(UnitDisplayOption::SHORT, numberFormat->GetUnitDisplay()); + EXPECT_EQ(numberFormat->GetMinimumIntegerDigits().GetInt(), 1); // 1 : 1 default minimum integer + EXPECT_EQ(numberFormat->GetMinimumFractionDigits().GetInt(), 0); // 0 : 0 default minimum fraction + EXPECT_EQ(numberFormat->GetMaximumFractionDigits().GetInt(), 3); // 1 : 1 default maximum fraction + EXPECT_EQ(numberFormat->GetMinimumSignificantDigits().GetInt(), 0); // 0 : 0 default minimum sigfraction + EXPECT_EQ(numberFormat->GetMaximumSignificantDigits().GetInt(), 0); // 0 : 0 default maximum sigfraction + EXPECT_TRUE(numberFormat->GetUseGrouping().IsTrue()); + EXPECT_TRUE(numberFormat->GetBoundFormat().IsUndefined()); + EXPECT_TRUE(numberFormat->GetUnit().IsUndefined()); + EXPECT_TRUE(numberFormat->GetCurrency().IsUndefined()); +} + +/** + * @tc.name: CurrencyDigits + * @tc.desc: If the ISO 4217 currency contains currency as an alphabetic code, return the minor unit value + * corresponding to the currency from the list + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSNumberFormatTest, CurrencyDigits) +{ + // Alphabetic code:USD + icu::UnicodeString usdCurrency("USD"); + // 2 : 2 fraction digits + EXPECT_EQ(JSNumberFormat::CurrencyDigits(usdCurrency), 2); + // Alphabetic code:EUR + icu::UnicodeString eurCurrency("EUR"); + // 2 : 2 fraction digits + EXPECT_EQ(JSNumberFormat::CurrencyDigits(eurCurrency), 2); + // Alphabetic code:CHF + icu::UnicodeString numberCurrency("CHF"); + // 2 : 2 fraction digits + EXPECT_EQ(JSNumberFormat::CurrencyDigits(numberCurrency), 2); +} + +/** + * @tc.name: FormatNumeric + * @tc.desc: Call "InitializeNumberFormat" function Initialize NumberFormat,Set the sytle attribute of the object to + * decimal,construct a bigint type data,and the object calls the FormatNumeric method to interpret the bigint + * type data into the corresponding decimal, and check whether the decimal meets the expectation. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSNumberFormatTest, FormatNumeric) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + auto globalConst = thread->GlobalConstants(); + + JSHandle objFun = env->GetObjectFunction(); + JSHandle ctor = env->GetNumberFormatFunction(); + JSHandle numberFormat = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(ctor), ctor)); + + JSHandle styleKey = globalConst->GetHandledStyleString(); + JSHandle styleValue(factory->NewFromASCII("decimal")); + JSHandle localeString(factory->NewFromASCII("en-US")); + JSHandle optionsObj = factory->NewJSObjectByConstructor(JSHandle(objFun), objFun); + JSObject::SetProperty(thread, optionsObj, styleKey, styleValue); + JSNumberFormat::InitializeNumberFormat(thread, numberFormat, localeString, JSHandle(optionsObj)); + // format BigInt + JSHandle number(thread, JSTaggedValue(123456789)); + JSHandle jsBigInt(thread, BigInt::NumberToBigInt(thread, number)); + JSHandle formatResult = + JSNumberFormat::FormatNumeric(thread, numberFormat, jsBigInt.GetTaggedValue()); + + JSHandle resultEcmaStr(thread, formatResult.GetTaggedValue()); + EXPECT_STREQ("123,456,789", CString(resultEcmaStr->GetCString().get()).c_str()); +} + +/** + * @tc.name: UnwrapNumberFormat + * @tc.desc: Construct an object,If it is a numberformat object,it will be returned.If it is an object of other types + * and inherits the numberformat object, it will get value from the fallbacksymbol key and return. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSNumberFormatTest, UnwrapNumberFormat) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + EcmaVM *vm = thread->GetEcmaVM(); + + JSHandle numberFormatFunc = env->GetNumberFormatFunction(); + JSHandle numberFormat( + factory->NewJSObjectByConstructor(JSHandle(numberFormatFunc), numberFormatFunc)); + + Local numberFormatLocal = JSNApiHelper::ToLocal(numberFormatFunc); + JSHandle disPlayNamesFunc = env->GetDisplayNamesFunction(); + Local disPlayNamesLocal = JSNApiHelper::ToLocal(disPlayNamesFunc); + // displaynames Inherit numberformat + disPlayNamesLocal->Inherit(vm, numberFormatLocal); + JSHandle disPlayNamesHandle = JSNApiHelper::ToJSHandle(disPlayNamesLocal); + JSHandle disPlayNamesObj( + factory->NewJSObjectByConstructor(JSHandle::Cast(disPlayNamesHandle), disPlayNamesHandle)); + // object has no Instance + JSHandle unwrapNumberFormat1 = JSNumberFormat::UnwrapNumberFormat(thread, numberFormat); + EXPECT_TRUE(JSTaggedValue::SameValue(numberFormat, unwrapNumberFormat1)); + // object has Instance + JSHandle unwrapNumberFormat2 = JSNumberFormat::UnwrapNumberFormat(thread, disPlayNamesObj); + EXPECT_TRUE(unwrapNumberFormat2->IsUndefined()); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_promise_test.cpp b/ecmascript/tests/js_promise_test.cpp index 604039d931e92c5ad47c563ad5cdc1b00379fc36..785c9c03f2236cc82bf82e6e0d2a50ed370cbaa6 100644 --- a/ecmascript/tests/js_promise_test.cpp +++ b/ecmascript/tests/js_promise_test.cpp @@ -104,9 +104,9 @@ HWTEST_F_L0(JSPromiseTest, FullFillPromise) JSHandle resolve(thread, capbility->GetResolve()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(33)); - JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, resolve, undefined, undefined, 1); + info->SetCallArg(JSTaggedValue(33)); + JSFunction::Call(info); EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::FULFILLED); EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseResult(), JSTaggedValue(33)), true); } @@ -123,9 +123,9 @@ HWTEST_F_L0(JSPromiseTest, RejectPromise) JSHandle reject(thread, capbility->GetReject()); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); - info.SetCallArg(JSTaggedValue(44)); - JSFunction::Call(&info); + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, reject, undefined, undefined, 1); + info->SetCallArg(JSTaggedValue(44)); + JSFunction::Call(info); EXPECT_EQ(newPromise->GetPromiseState(), PromiseState::REJECTED); EXPECT_EQ(JSTaggedValue::SameValue(newPromise->GetPromiseResult(), JSTaggedValue(44)), true); } diff --git a/ecmascript/tests/js_proxy_test.cpp b/ecmascript/tests/js_proxy_test.cpp index a151cc8a8c9c79264bae3ff9c308c199751018f9..2a188dd4c7d56b3e9fc0627754509ac357389c5e 100644 --- a/ecmascript/tests/js_proxy_test.cpp +++ b/ecmascript/tests/js_proxy_test.cpp @@ -561,10 +561,10 @@ HWTEST_F_L0(JSProxyTest, Call) EXPECT_TRUE(*proxyHandle != nullptr); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(proxyHandle), JSHandle(proxyHandle), undefined, 0); - JSTaggedValue res = JSProxy::CallInternal(&info); + JSTaggedValue res = JSProxy::CallInternal(info); EXPECT_TRUE(JSTaggedValue::SameValue(res, JSTaggedValue::True())); // 2. handler has "Call" @@ -575,10 +575,10 @@ HWTEST_F_L0(JSProxyTest, Call) JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); EXPECT_TRUE(*proxyHandle2 != nullptr); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(proxyHandle2), JSHandle(proxyHandle2), undefined, 0); - JSTaggedValue res2 = JSProxy::CallInternal(&runtimeInfo); + JSTaggedValue res2 = JSProxy::CallInternal(runtimeInfo); EXPECT_TRUE(JSTaggedValue::SameValue(res2, JSTaggedValue::False())); } @@ -624,9 +624,9 @@ HWTEST_F_L0(JSProxyTest, Construct) JSHandle proxyHandle = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); EXPECT_TRUE(*proxyHandle != nullptr); JSHandle undefined = thread->GlobalConstants()->GetHandledUndefined(); - EcmaRuntimeCallInfo info = + EcmaRuntimeCallInfo *info = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(proxyHandle), handlerHandle, undefined, 0); - JSTaggedValue res = JSProxy::ConstructInternal(&info); + JSTaggedValue res = JSProxy::ConstructInternal(info); JSHandle taggedRes(thread, res); JSHandle key(factory->NewFromASCII("x")); EXPECT_EQ(JSObject::GetProperty(thread, taggedRes, key).GetValue()->GetInt(), 1); @@ -638,9 +638,9 @@ HWTEST_F_L0(JSProxyTest, Construct) JSHandle proxyHandle2 = JSProxy::ProxyCreate(thread, targetHandle, handlerHandle); EXPECT_TRUE(*proxyHandle2 != nullptr); - EcmaRuntimeCallInfo runtimeInfo = + EcmaRuntimeCallInfo *runtimeInfo = EcmaInterpreter::NewRuntimeCallInfo(thread, JSHandle(proxyHandle2), targetHandle, undefined, 0); - JSTaggedValue res2 = JSProxy::ConstructInternal(&runtimeInfo); + JSTaggedValue res2 = JSProxy::ConstructInternal(runtimeInfo); JSHandle taggedRes2(thread, res2); EXPECT_EQ(JSObject::GetProperty(thread, taggedRes2, key).GetValue()->GetInt(), 2); } diff --git a/ecmascript/tests/js_serializer_test.cpp b/ecmascript/tests/js_serializer_test.cpp index 78d6cbbe8890a6ee95c2bc36e4e7be36066f0852..f797d3e47dd24c7cc93da1f3247b616f0ff13b7c 100644 --- a/ecmascript/tests/js_serializer_test.cpp +++ b/ecmascript/tests/js_serializer_test.cpp @@ -42,7 +42,8 @@ public: { JSRuntimeOptions options; options.SetEnableForceGC(true); - ecmaVm = EcmaVM::Create(options); + auto config = ecmascript::EcmaParamConfiguration(false, MemMapAllocator::GetInstance()->GetCapacity()); + ecmaVm = EcmaVM::Create(options, config); ecmaVm->SetEnableForceGC(true); EXPECT_TRUE(ecmaVm != nullptr) << "Cannot create Runtime"; thread = ecmaVm->GetJSThread(); @@ -148,20 +149,13 @@ public: JSHandle objValue2 = deserializer.DeserializeJSTaggedValue(); [[maybe_unused]] JSHandle objValue3 = deserializer.DeserializeJSTaggedValue(); - JSHandle retObj1 = JSHandle::Cast(objValue1); JSHandle retObj2 = JSHandle::Cast(objValue2); - JSHandle retObj3 = JSHandle::Cast(objValue3); - EXPECT_FALSE(retObj1.IsEmpty()); EXPECT_FALSE(retObj2.IsEmpty()); - EXPECT_FALSE(retObj3.IsEmpty()); JSHandle array2 = JSObject::GetOwnPropertyKeys(thread, retObj2); uint32_t length2 = array2->GetLength(); - EXPECT_EQ(length2, 4U); // 4 : test case + EXPECT_EQ(length2, 6U); // 6 : test case - JSHandle array3 = JSObject::GetOwnPropertyKeys(thread, retObj3); - uint32_t length3 = array3->GetLength(); - EXPECT_EQ(length3, 0U); // 0 : test case Destroy(); } @@ -716,15 +710,22 @@ HWTEST_F_L0(JSSerializerTest, SerializeJSPlainObject01) delete serializer; }; -static void* detach() +static void* detach(void *param1, void *param2, void *hint) { GTEST_LOG_(INFO) << "detach is running"; + if (param1 == nullptr && param2 == nullptr) { + GTEST_LOG_(INFO) << "detach: two params is nullptr"; + } + if (hint == nullptr) { + GTEST_LOG_(INFO) << "detach: hint is nullptr"; + } return nullptr; } -static void attach([[maybe_unused]] void* buffer) +static void* attach([[maybe_unused]] void *enginePointer, [[maybe_unused]] void *buffer, [[maybe_unused]] void *hint) { GTEST_LOG_(INFO) << "attach is running"; + return nullptr; } HWTEST_F_L0(JSSerializerTest, SerializeNativeBindingObject) @@ -754,8 +755,6 @@ HWTEST_F_L0(JSSerializerTest, SerializeNativeBindingObject) JSObject::SetProperty(thread, JSHandle(obj1), key1, value1); JSObject::SetProperty(thread, JSHandle(obj1), key2, value2); - JSObject::SetProperty(thread, JSHandle(obj2), key1, value1); - JSObject::SetProperty(thread, JSHandle(obj2), key2, value2); JSObject::SetProperty(thread, JSHandle(obj2), key3, value3); JSObject::SetProperty(thread, JSHandle(obj2), key4, value4); JSObject::SetProperty(thread, JSHandle(obj2), key5, value5); @@ -764,6 +763,8 @@ HWTEST_F_L0(JSSerializerTest, SerializeNativeBindingObject) JSObject::SetProperty(thread, JSHandle(obj2), key8, value8); JSObject::SetProperty(thread, JSHandle(obj3), key1, value1); JSObject::SetProperty(thread, JSHandle(obj3), key2, value2); + JSObject::SetProperty(thread, JSHandle(obj3), key3, value3); + JSObject::SetProperty(thread, JSHandle(obj3), key4, value4); JSSerializer *serializer = new JSSerializer(thread); bool success1 = serializer->SerializeJSTaggedValue(JSHandle::Cast(obj1)); diff --git a/ecmascript/tests/js_set_iterator_test.cpp b/ecmascript/tests/js_set_iterator_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..34f21cb307261332aaac343cab8336d3099413dc --- /dev/null +++ b/ecmascript/tests/js_set_iterator_test.cpp @@ -0,0 +1,211 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/js_set_iterator.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_array.h" +#include "ecmascript/js_set.h" +#include "ecmascript/linked_hash_table.h" +#include "ecmascript/tests/test_helper.h" + +using namespace panda; +using namespace panda::ecmascript; + +namespace panda::test { +class JSSetIteratorTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; + JSThread *thread {nullptr}; +}; + +static JSSet *CreateJSSet(JSThread *thread) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle env = thread->GetEcmaVM()->GetGlobalEnv(); + + JSHandle constructor = env->GetBuiltinsSetFunction(); + JSHandle set = + JSHandle::Cast(factory->NewJSObjectByConstructor(JSHandle(constructor), constructor)); + JSHandle hashSet = LinkedHashSet::Create(thread); + set->SetLinkedSet(thread, hashSet); + return JSSet::Cast(set.GetTaggedValue().GetTaggedObject()); +} + +/** + * @tc.name: CreateSetIterator + * @tc.desc: Call "CreateSetIterator" function create SetIterator,Check whether the the attribute setting of SetIterator + * through "GetNextIndex" and "GetIterationKind" function is within expectations. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSSetIteratorTest, CreateSetIterator) +{ + JSHandle jsSet(thread, CreateJSSet(thread)); + EXPECT_TRUE(*jsSet != nullptr); + + JSHandle setIteratorValue1 = + JSSetIterator::CreateSetIterator(thread, JSHandle(jsSet), IterationKind::KEY); + + EXPECT_EQ(setIteratorValue1->IsJSSetIterator(), true); + JSHandle setIterator1(setIteratorValue1); + EXPECT_EQ(JSTaggedValue::SameValue(setIterator1->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(setIterator1->GetNextIndex(), 0U); + EXPECT_EQ(setIterator1->GetIterationKind(), IterationKind::KEY); + + JSHandle setIteratorValue2 = + JSSetIterator::CreateSetIterator(thread, JSHandle(jsSet), IterationKind::VALUE); + + EXPECT_EQ(setIteratorValue2->IsJSSetIterator(), true); + JSHandle setIterator2(setIteratorValue2); + EXPECT_EQ(JSTaggedValue::SameValue(setIterator2->GetIteratedSet(), jsSet->GetLinkedSet()), true); + EXPECT_EQ(setIterator2->GetNextIndex(), 0U); + EXPECT_EQ(setIterator2->GetIterationKind(), IterationKind::VALUE); +} + +/** + * @tc.name: Update + * @tc.desc: Call "NewJSSetIterator" function create SetIterator with emty IteratedSet,create other JSSet and add key + * to it,the old JSSet call "Rehash" function set new JSSet to the next table, then SetIterator call "Update" + * function upadate IteratedSet,check whether the IteratedSet is within expectations. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSSetIteratorTest, Update) +{ + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle jsSet1(thread, CreateJSSet(thread)); + JSHandle jsSet2(thread, CreateJSSet(thread)); + + JSHandle keyHandle1(factory->NewFromASCII("key1")); + JSHandle keyHandle2(factory->NewFromASCII("key2")); + JSHandle keyHandle3(factory->NewFromASCII("key3")); + // add key to jsSet2 + JSSet::Add(thread, jsSet2, keyHandle1); + JSSet::Add(thread, jsSet2, keyHandle2); + JSSet::Add(thread, jsSet2, keyHandle3); + + JSHandle setHandle1(thread, LinkedHashSet::Cast(jsSet1->GetLinkedSet().GetTaggedObject())); + JSHandle setHandle2(thread, LinkedHashSet::Cast(jsSet2->GetLinkedSet().GetTaggedObject())); + setHandle1->Rehash(thread, *setHandle2); + // create SetIterator with jsSet1 + JSHandle setIterator = factory->NewJSSetIterator(jsSet1, IterationKind::KEY); + // update SetIterator + setIterator->Update(thread); + LinkedHashSet *resultSet = LinkedHashSet::Cast(setIterator->GetIteratedSet().GetTaggedObject()); + EXPECT_TRUE(resultSet->Has(keyHandle1.GetTaggedValue())); + EXPECT_TRUE(resultSet->Has(keyHandle2.GetTaggedValue())); + EXPECT_TRUE(resultSet->Has(keyHandle3.GetTaggedValue())); +} + +/** + * @tc.name: Next + * @tc.desc: get the next value in setiterator,Check whether the return value obtained by the function is + * the next value in the array element. + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F_L0(JSSetIteratorTest, KEY_Next) +{ + JSHandle jsSet(thread, CreateJSSet(thread)); + EXPECT_TRUE(*jsSet != nullptr); + + for (int i = 0; i < 3; i++) { // 3 : 3 default numberOfElements + JSHandle key(thread, JSTaggedValue(i)); + JSSet::Add(thread, jsSet, key); + } + // set IterationKind(key or value) + JSHandle setIteratorValue = + JSSetIterator::CreateSetIterator(thread, JSHandle(jsSet), IterationKind::KEY); + JSHandle setIterator(setIteratorValue); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(setIteratorValue.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + + for (int i = 0; i <= 3; i++) { // 3 : 3 default numberOfElements + JSTaggedValue result = JSSetIterator::Next(ecmaRuntimeCallInfo); + JSHandle resultObj(thread, result); + if (i < 3) { + EXPECT_EQ(setIterator->GetNextIndex(), static_cast(i+1)); + EXPECT_EQ(i, JSIterator::IteratorValue(thread, resultObj)->GetInt()); + } + else { + EXPECT_EQ(JSIterator::IteratorValue(thread, resultObj).GetTaggedValue(), JSTaggedValue::Undefined()); + } + } + TestHelper::TearDownFrame(thread, prev); +} + +HWTEST_F_L0(JSSetIteratorTest, KEY_AND_VALUE_Next) +{ + JSHandle jsSet(thread, CreateJSSet(thread)); + EXPECT_TRUE(*jsSet != nullptr); + JSHandle index0(thread, JSTaggedValue(0)); + JSHandle index1(thread, JSTaggedValue(1)); + + for (int i = 0; i < 3; i++) { // default numberOfElements + JSHandle key(thread, JSTaggedValue(i)); + JSSet::Add(thread, jsSet, key); + } + // set IterationKind(key and value) + JSHandle setIteratorValue = + JSSetIterator::CreateSetIterator(thread, JSHandle(jsSet), IterationKind::KEY_AND_VALUE); + JSHandle setIterator(setIteratorValue); + + auto ecmaRuntimeCallInfo = TestHelper::CreateEcmaRuntimeCallInfo(thread, JSTaggedValue::Undefined(), 6); + ecmaRuntimeCallInfo->SetFunction(JSTaggedValue::Undefined()); + ecmaRuntimeCallInfo->SetThis(setIteratorValue.GetTaggedValue()); + ecmaRuntimeCallInfo->SetCallArg(0, JSTaggedValue::Undefined()); + [[maybe_unused]] auto prev = TestHelper::SetupFrame(thread, ecmaRuntimeCallInfo); + + for (int i = 0; i <= 3; i++) { // 3 : 3 default numberOfElements + JSTaggedValue result = JSSetIterator::Next(ecmaRuntimeCallInfo); + JSHandle resultObj(thread, result); + if (i < 3) { + JSHandle arrayList(thread, JSIterator::IteratorValue(thread, resultObj).GetTaggedValue()); + EXPECT_EQ(setIterator->GetNextIndex(), static_cast(i+1)); + EXPECT_EQ(JSArray::GetProperty(thread, JSHandle(arrayList), index0).GetValue()->GetInt(), i); + EXPECT_EQ(JSArray::GetProperty(thread, JSHandle(arrayList), index1).GetValue()->GetInt(), i); + } + else { + EXPECT_EQ(JSIterator::IteratorValue(thread, resultObj).GetTaggedValue(), JSTaggedValue::Undefined()); + } + } + TestHelper::TearDownFrame(thread, prev); +} +} // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tests/js_typed_array_test.cpp b/ecmascript/tests/js_typed_array_test.cpp index 684b76c77c48a0d0c73ea14149e5394efde916bb..232e7e4e967f8e254f5279219b79fc7aaedc8784 100644 --- a/ecmascript/tests/js_typed_array_test.cpp +++ b/ecmascript/tests/js_typed_array_test.cpp @@ -52,7 +52,7 @@ public: // CVector pushed with JSTaggedValue made from compatible input value for the JSType const CVector cVecHandleTagValValueForTypedArray { - // Use "(S)(...)" cast to make v in "JSTaggedValue(T v) : coretypes::TaggedValue(v) {}" compatible with S + // Use "(S)(...)" cast to make v in "JSTaggedValue(T v) {}" compatible with S JSTaggedValue((int8_t)(-111)), JSTaggedValue((uint8_t)(222)), JSTaggedValue((uint8_t)(222)), JSTaggedValue((int16_t)(-31111)), JSTaggedValue((uint16_t)(61111)), // int32 : -2147483648->2147483647, uint32 : 0->4294967295 diff --git a/ecmascript/tests/object_operator_test.cpp b/ecmascript/tests/object_operator_test.cpp index 5fad3cd8b9d928263d8c81e9b4a26264275e016f..9c620f1a8fab714809b912c85db87fb266d4b13b 100644 --- a/ecmascript/tests/object_operator_test.cpp +++ b/ecmascript/tests/object_operator_test.cpp @@ -240,12 +240,13 @@ JSTaggedValue TestDefinedSetter([[maybe_unused]] EcmaRuntimeCallInfo *argv) return JSTaggedValue(12); } -JSTaggedValue TestBoolSetter([[maybe_unused]] EcmaRuntimeCallInfo *argv) +bool TestBoolSetter([[maybe_unused]] JSThread *thread, + [[maybe_unused]] JSHandle &jsObject, + [[maybe_unused]] JSHandle &value, + [[maybe_unused]] bool success) { - // 12 : test case - return JSTaggedValue(JSTaggedValue::True()); + return true; } - static JSFunction *JSObjectTestCreate(JSThread *thread) { JSHandle globalEnv = thread->GetEcmaVM()->GetGlobalEnv(); diff --git a/ecmascript/tests/read_only_space_test.cpp b/ecmascript/tests/read_only_space_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..77458f34dbed4b3c2d081b51ea8d9879a9b3999d --- /dev/null +++ b/ecmascript/tests/read_only_space_test.cpp @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/ecma_vm.h" +#include "ecmascript/global_env.h" +#include "ecmascript/js_handle.h" +#include "ecmascript/mem/concurrent_marker.h" +#include "ecmascript/mem/space.h" +#include "ecmascript/mem/verification.h" +#include "ecmascript/object_factory.h" +#include "ecmascript/tagged_array-inl.h" +#include "ecmascript/tests/test_helper.h" +#include "generated/base_options.h" + +#include +#include +using namespace panda::ecmascript; + +namespace panda::test { +class ReadOnlySpaceTest : public testing::Test { +public: + static void SetUpTestCase() + { + GTEST_LOG_(INFO) << "SetUpTestCase"; + } + + static void TearDownTestCase() + { + GTEST_LOG_(INFO) << "TearDownCase"; + } + + void SetUp() override + { + InitializeLogger(); + TestHelper::CreateEcmaVMWithScope(instance, thread, scope); + factory = thread->GetEcmaVM()->GetFactory(); + const_cast(thread->GetEcmaVM()->GetHeap())->SetMarkType(MarkType::MARK_FULL); + } + + void InitializeLogger() + { + base_options::Options baseOptions(""); + baseOptions.SetLogLevel("error"); + arg_list_t logComponents; + logComponents.emplace_back("all"); + baseOptions.SetLogComponents(logComponents); + Logger::Initialize(baseOptions); + } + + void TearDown() override + { + TestHelper::DestroyEcmaVMWithScope(instance, scope); + } + + JSThread *thread {nullptr}; + ObjectFactory *factory {nullptr}; + EcmaVM *instance {nullptr}; + ecmascript::EcmaHandleScope *scope {nullptr}; +}; + +static sigjmp_buf g_env; +static bool g_segmentfault_flag = false; +class ReadOnlyTestManager { +public: + // static constexpr int RO_SEGMENTFAULT = 1; + static void ProcessReadOnlySegmentFault(int sig) + { + g_segmentfault_flag = true; + siglongjmp(g_env, sig); + } + + static int RegisterSignal() + { + struct sigaction act; + act.sa_handler = ProcessReadOnlySegmentFault; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGQUIT); + act.sa_flags = SA_RESETHAND; + return sigaction(SIGSEGV, &act, NULL); + } +}; + +HWTEST_F_L0(ReadOnlySpaceTest, ReadOnlyTest) +{ + auto *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + if (ReadOnlyTestManager::RegisterSignal() == -1) { + perror("sigaction error"); + exit(1); + } + auto ret = sigsetjmp(g_env, 1); + if (ret != SIGSEGV) { + heap->AllocateReadOnlyOrHugeObject( + JSHClass::Cast(thread->GlobalConstants()->GetBigIntClass().GetTaggedObject())); + } else { + // catch signal SIGSEGV caused by modify read only memory + EXPECT_TRUE(g_segmentfault_flag); + } +} + +HWTEST_F_L0(ReadOnlySpaceTest, AllocateTest) +{ + auto *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + heap->GetReadOnlySpace()->ClearReadOnly(); + auto *object = heap->AllocateReadOnlyOrHugeObject( + JSHClass::Cast(thread->GlobalConstants()->GetBigIntClass().GetTaggedObject())); + auto *region = Region::ObjectAddressToRange(object); + EXPECT_TRUE(region->InReadOnlySpace()); +} + +HWTEST_F_L0(ReadOnlySpaceTest, CompactHeapBeforeForkTest) +{ + auto *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + heap->GetReadOnlySpace()->ClearReadOnly(); + std::string rawStr = "test string"; + JSHandle string = factory->NewFromStdString(rawStr); + JSHandle obj = factory->NewEmptyJSObject(); + auto *regionBefore = Region::ObjectAddressToRange(string.GetObject()); + auto *objRegionBefore = Region::ObjectAddressToRange(obj.GetObject()); + EXPECT_FALSE(regionBefore->InReadOnlySpace()); + EXPECT_FALSE(objRegionBefore->InReadOnlySpace()); + heap->CompactHeapBeforeFork(); + auto *regionAfter = Region::ObjectAddressToRange(string.GetObject()); + auto *objRegionAfter = Region::ObjectAddressToRange(obj.GetObject()); + EXPECT_TRUE(regionAfter->InReadOnlySpace()); + EXPECT_FALSE(objRegionAfter->InReadOnlySpace()); +} + +HWTEST_F_L0(ReadOnlySpaceTest, GCTest) +{ + auto *heap = const_cast(thread->GetEcmaVM()->GetHeap()); + heap->GetReadOnlySpace()->ClearReadOnly(); + auto *object = heap->AllocateReadOnlyOrHugeObject( + JSHClass::Cast(thread->GlobalConstants()->GetBigIntClass().GetTaggedObject())); + heap->CollectGarbage(TriggerGCType::YOUNG_GC); + heap->CollectGarbage(TriggerGCType::OLD_GC); + heap->CollectGarbage(TriggerGCType::FULL_GC); + auto *region = Region::ObjectAddressToRange(object); + EXPECT_TRUE(region->InReadOnlySpace()); +} +} // namespace panda::test diff --git a/ecmascript/tests/test_helper.h b/ecmascript/tests/test_helper.h index 3d67ae9890ab068626f2904bb95cfd886cca7417..7b7ce56191edbb2e8da0937c7e3f567628a8e00f 100644 --- a/ecmascript/tests/test_helper.h +++ b/ecmascript/tests/test_helper.h @@ -30,6 +30,8 @@ using panda::ecmascript::EcmaHandleScope; using panda::ecmascript::EcmaRuntimeCallInfo; using panda::ecmascript::EcmaVM; using panda::ecmascript::InterpretedFrame; +using panda::ecmascript::InterpretedBuiltinFrame; +using panda::ecmascript::InterpretedEntryFrame; using panda::ecmascript::JSTaggedType; using panda::ecmascript::JSTaggedValue; using panda::ecmascript::JSThread; @@ -41,32 +43,34 @@ using ecmascript::JSRuntimeOptions; class TestHelper { public: - static std::unique_ptr CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue newTgt, - uint32_t argvLength) + static EcmaRuntimeCallInfo* CreateEcmaRuntimeCallInfo(JSThread *thread, JSTaggedValue newTgt, uint32_t argvLength) { const uint8_t testDecodedSize = 2; // argvLength includes number of int64_t to store value and tag of function, 'this' and call args // It doesn't include new.target argument - uint32_t numActualArgs = argvLength / testDecodedSize + 1; + int32_t numActualArgs = argvLength / testDecodedSize + 1; JSTaggedType *sp = const_cast(thread->GetCurrentSPFrame()); - size_t frameSize = ecmascript::INTERPRETER_FRAME_STATE_SIZE + numActualArgs; + size_t frameSize = InterpretedFrame::NumOfMembers() + numActualArgs; JSTaggedType *newSp = sp - frameSize; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) for (int i = numActualArgs; i > 0; i--) { newSp[i - 1] = JSTaggedValue::Undefined().GetRawData(); } - auto callInfo = std::make_unique(thread, numActualArgs - NUM_MANDATORY_JSFUNC_ARGS, newSp); - callInfo->SetNewTarget(newTgt); - return callInfo; + EcmaRuntimeCallInfo *ecmaRuntimeCallInfo = reinterpret_cast(newSp - 2); + *(--newSp) = numActualArgs; + *(--newSp) = ToUintPtr(thread); + ecmaRuntimeCallInfo->SetNewTarget(newTgt); + return ecmaRuntimeCallInfo; } static JSTaggedType *SetupFrame(JSThread *thread, EcmaRuntimeCallInfo *info) { JSTaggedType *sp = const_cast(thread->GetCurrentSPFrame()); - size_t frameSize = ecmascript::INTERPRETER_FRAME_STATE_SIZE + info->GetArgsNumber() + NUM_MANDATORY_JSFUNC_ARGS; + size_t frameSize = + InterpretedFrame::NumOfMembers() + info->GetArgsNumber() + NUM_MANDATORY_JSFUNC_ARGS + 2; JSTaggedType *newSp = sp - frameSize; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic) - InterpretedFrame *state = reinterpret_cast(newSp) - 1; - state->base.type = ecmascript::FrameType::INTERPRETER_FRAME; + InterpretedBuiltinFrame *state = reinterpret_cast(newSp) - 1; + state->base.type = ecmascript::FrameType::INTERPRETER_BUILTIN_FRAME; state->base.prev = sp; state->pc = nullptr; state->function = methodFunction_.GetTaggedValue(); diff --git a/ecmascript/tooling/BUILD.gn b/ecmascript/tooling/BUILD.gn index 01fb896b0e7de120ecc1bdbadd1566c4907d8c53..61f347e80eabd58f5f49f3d259ebc83d985c5e67 100644 --- a/ecmascript/tooling/BUILD.gn +++ b/ecmascript/tooling/BUILD.gn @@ -32,6 +32,7 @@ debugger_sources = [ "agent/heapprofiler_impl.cpp", "agent/profiler_impl.cpp", "agent/runtime_impl.cpp", + "agent/tracing_impl.cpp", "backend/debugger_executor.cpp", "backend/js_pt_extractor.cpp", "backend/js_pt_hooks.cpp", @@ -57,6 +58,14 @@ source_set("libark_ecma_debugger_set") { "//third_party/cJSON:cjson_static", ] + if (is_ohos && is_standard_system) { + if (enable_hilog) { + defines = [ "ENABLE_HILOG" ] + include_dirs = + [ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include" ] + } + } + cflags_cc = [ "-fvisibility=hidden" ] } @@ -68,6 +77,12 @@ ohos_shared_library("libark_ecma_debugger") { install_enable = true + if (is_ohos && is_standard_system) { + if (enable_hilog) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] + } + } + output_extension = "so" if (!is_standard_system) { relative_install_dir = "ark" @@ -83,6 +98,14 @@ source_set("libark_ecma_debugger_test_set") { defines = [ "DEBUGGER_TEST" ] + if (is_ohos && is_standard_system) { + if (enable_hilog) { + defines += [ "ENABLE_HILOG" ] + include_dirs = + [ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include" ] + } + } + deps = [ "$ark_root/libpandabase:libarkbase", "$ark_root/libpandafile:libarkfile", @@ -93,12 +116,12 @@ source_set("libark_ecma_debugger_test_set") { ohos_shared_library("libark_ecma_debugger_test") { deps = [ ":libark_ecma_debugger_test_set", - "//ark/js_runtime:libark_jsruntime_test_set", + "//ark/js_runtime:libark_jsruntime_test", ] if (is_ohos && is_standard_system) { - if (build_public_version) { - external_deps = [ "hitrace_native:hitrace_meter" ] + if (enable_hilog) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } } diff --git a/ecmascript/tooling/agent/debugger_impl.cpp b/ecmascript/tooling/agent/debugger_impl.cpp index d46f146100ba0584fe59df428a348d2ecd67b1fd..171f73a543616c8c06ac830de83176fded472fdc 100644 --- a/ecmascript/tooling/agent/debugger_impl.cpp +++ b/ecmascript/tooling/agent/debugger_impl.cpp @@ -25,8 +25,7 @@ #include "ecmascript/tooling/base/pt_types.h" #include "ecmascript/tooling/backend/debugger_executor.h" #include "ecmascript/tooling/dispatcher.h" -#include "ecmascript/tooling/protocol_channel.h" -#include "libpandabase/utils/logger.h" +#include "ecmascript/tooling/protocol_handler.h" namespace panda::ecmascript::tooling { using namespace boost::beast::detail; @@ -63,7 +62,7 @@ DebuggerImpl::~DebuggerImpl() bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &fileName) { if (fileName.substr(0, DATA_APP_PATH.length()) != DATA_APP_PATH) { - LOG(WARNING, DEBUGGER) << "NotifyScriptParsed: unsupport file: " << fileName; + LOG_DEBUGGER(WARN) << "NotifyScriptParsed: unsupport file: " << fileName; return false; } @@ -71,7 +70,7 @@ bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &file return true; }; if (MatchScripts(scriptFunc, fileName, ScriptMatchType::FILE_NAME)) { - LOG(WARNING, DEBUGGER) << "NotifyScriptParsed: already loaded: " << fileName; + LOG_DEBUGGER(WARN) << "NotifyScriptParsed: already loaded: " << fileName; return false; } const JSPandaFile *jsPandaFile = nullptr; @@ -84,13 +83,13 @@ bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &file return true; }); if (jsPandaFile == nullptr) { - LOG(ERROR, DEBUGGER) << "NotifyScriptParsed: unknown file: " << fileName; + LOG_DEBUGGER(ERROR) << "NotifyScriptParsed: unknown file: " << fileName; return false; } JSPtExtractor *extractor = GetExtractor(jsPandaFile); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "NotifyScriptParsed: Unsupported file: " << fileName; + LOG_DEBUGGER(ERROR) << "NotifyScriptParsed: Unsupported file: " << fileName; return false; } @@ -99,7 +98,7 @@ bool DebuggerImpl::NotifyScriptParsed(ScriptId scriptId, const std::string &file const std::string &url = extractor->GetSourceFile(mainMethodIndex); const uint32_t MIN_SOURCE_CODE_LENGTH = 5; // maybe return 'ANDA' when source code is empty if (source.size() < MIN_SOURCE_CODE_LENGTH) { - LOG(ERROR, DEBUGGER) << "NotifyScriptParsed: invalid file: " << fileName; + LOG_DEBUGGER(ERROR) << "NotifyScriptParsed: invalid file: " << fileName; return false; } // store here for performance of get extractor from url @@ -122,7 +121,7 @@ bool DebuggerImpl::NotifySingleStep(const JSPtLocation &location) return false; } pauseOnNextByteCode_ = false; - LOG(INFO, DEBUGGER) << "StepComplete: pause on next bytecode"; + LOG_DEBUGGER(INFO) << "StepComplete: pause on next bytecode"; return true; } @@ -140,7 +139,8 @@ bool DebuggerImpl::NotifySingleStep(const JSPtLocation &location) return false; } - LOG(INFO, DEBUGGER) << "StepComplete: pause on current byte_code"; + singleStepper_.reset(); + LOG_DEBUGGER(INFO) << "StepComplete: pause on current byte_code"; return true; } @@ -152,7 +152,7 @@ bool DebuggerImpl::IsSkipLine(const JSPtLocation &location) return true; }; if (!MatchScripts(scriptFunc, location.GetPandaFile(), ScriptMatchType::FILE_NAME) || extractor == nullptr) { - LOG(INFO, DEBUGGER) << "StepComplete: skip unknown file"; + LOG_DEBUGGER(INFO) << "StepComplete: skip unknown file"; return true; } @@ -162,7 +162,7 @@ bool DebuggerImpl::IsSkipLine(const JSPtLocation &location) File::EntityId methodId = location.GetMethodId(); uint32_t offset = location.GetBytecodeOffset(); if (extractor->MatchLineWithOffset(callbackFunc, methodId, offset)) { - LOG(INFO, DEBUGGER) << "StepComplete: skip -1"; + LOG_DEBUGGER(INFO) << "StepComplete: skip -1"; return true; } @@ -198,7 +198,7 @@ void DebuggerImpl::NotifyPaused(std::optional location, PauseReaso if (!MatchScripts(scriptFunc, location->GetPandaFile(), ScriptMatchType::FILE_NAME) || extractor == nullptr || !extractor->MatchLineWithOffset(callbackLineFunc, methodId, offset) || !extractor->MatchColumnWithOffset(callbackColumnFunc, methodId, offset)) { - LOG(ERROR, DEBUGGER) << "NotifyPaused: unknown " << location->GetPandaFile(); + LOG_DEBUGGER(ERROR) << "NotifyPaused: unknown " << location->GetPandaFile(); return; } hitBreakpoints.emplace_back(BreakpointDetails::ToString(detail)); @@ -210,7 +210,7 @@ void DebuggerImpl::NotifyPaused(std::optional location, PauseReaso // Notify paused event std::vector> callFrames; if (!GenerateCallFrames(&callFrames)) { - LOG(ERROR, DEBUGGER) << "NotifyPaused: GenerateCallFrames failed"; + LOG_DEBUGGER(ERROR) << "NotifyPaused: GenerateCallFrames failed"; return; } tooling::Paused paused; @@ -234,6 +234,12 @@ void DebuggerImpl::NotifyPendingJobEntry() } } +void DebuggerImpl::NotifyHandleProtocolCommand() +{ + auto *handler = vm_->GetJsDebuggerManager()->GetDebuggerHandler(); + handler->ProcessCommand(); +} + void DebuggerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) { static std::unordered_map dispatcherTable { @@ -254,7 +260,7 @@ void DebuggerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) }; const std::string &method = request.GetMethod(); - LOG(DEBUG, DEBUGGER) << "dispatch [" << method << "] to DebuggerImpl"; + LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to DebuggerImpl"; auto entry = dispatcherTable.find(method); if (entry != dispatcherTable.end() && entry->second != nullptr) { (this->*(entry->second))(request); @@ -286,14 +292,17 @@ void DebuggerImpl::DispatcherImpl::Disable(const DispatchRequest &request) void DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame(const DispatchRequest &request) { - std::unique_ptr params = - EvaluateOnCallFrameParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = EvaluateOnCallFrameParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; } std::unique_ptr result1; DispatchResponse response = debugger_->EvaluateOnCallFrame(*params, &result1); + if (result1 == nullptr) { + SendResponse(request, response); + return; + } EvaluateOnCallFrameReturns result(std::move(result1)); SendResponse(request, response, result); @@ -301,8 +310,7 @@ void DebuggerImpl::DispatcherImpl::EvaluateOnCallFrame(const DispatchRequest &re void DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints(const DispatchRequest &request) { - std::unique_ptr params = - GetPossibleBreakpointsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetPossibleBreakpointsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -315,8 +323,7 @@ void DebuggerImpl::DispatcherImpl::GetPossibleBreakpoints(const DispatchRequest void DebuggerImpl::DispatcherImpl::GetScriptSource(const DispatchRequest &request) { - std::unique_ptr params = - GetScriptSourceParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetScriptSourceParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -335,8 +342,7 @@ void DebuggerImpl::DispatcherImpl::Pause(const DispatchRequest &request) void DebuggerImpl::DispatcherImpl::RemoveBreakpoint(const DispatchRequest &request) { - std::unique_ptr params = - RemoveBreakpointParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = RemoveBreakpointParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -347,7 +353,7 @@ void DebuggerImpl::DispatcherImpl::RemoveBreakpoint(const DispatchRequest &reque void DebuggerImpl::DispatcherImpl::Resume(const DispatchRequest &request) { - std::unique_ptr params = ResumeParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = ResumeParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -364,8 +370,7 @@ void DebuggerImpl::DispatcherImpl::SetAsyncCallStackDepth(const DispatchRequest void DebuggerImpl::DispatcherImpl::SetBreakpointByUrl(const DispatchRequest &request) { - std::unique_ptr params = - SetBreakpointByUrlParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = SetBreakpointByUrlParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -380,8 +385,7 @@ void DebuggerImpl::DispatcherImpl::SetBreakpointByUrl(const DispatchRequest &req void DebuggerImpl::DispatcherImpl::SetPauseOnExceptions(const DispatchRequest &request) { - std::unique_ptr params = - SetPauseOnExceptionsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = SetPauseOnExceptionsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -393,7 +397,7 @@ void DebuggerImpl::DispatcherImpl::SetPauseOnExceptions(const DispatchRequest &r void DebuggerImpl::DispatcherImpl::StepInto(const DispatchRequest &request) { - std::unique_ptr params = StepIntoParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StepIntoParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -410,7 +414,7 @@ void DebuggerImpl::DispatcherImpl::StepOut(const DispatchRequest &request) void DebuggerImpl::DispatcherImpl::StepOver(const DispatchRequest &request) { - std::unique_ptr params = StepOverParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StepOverParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -520,16 +524,16 @@ DispatchResponse DebuggerImpl::EvaluateOnCallFrame(const EvaluateOnCallFramePara { CallFrameId callFrameId = params.GetCallFrameId(); const std::string &expression = params.GetExpression(); - if (callFrameId < 0 || callFrameId >= static_cast(callFrameHandlers_.size())) { + if (callFrameId < 0 || callFrameId >= static_cast(callFrameHandlers_.size())) { return DispatchResponse::Fail("Invalid callFrameId."); } std::string dest; if (!DecodeAndCheckBase64(expression, dest)) { - LOG(ERROR, DEBUGGER) << "EvaluateValue: base64 decode failed"; + LOG_DEBUGGER(ERROR) << "EvaluateValue: base64 decode failed"; auto ret = CmptEvaluateValue(callFrameId, expression, result); if (ret.has_value()) { - LOG(ERROR, DEBUGGER) << "Evaluate fail, expression: " << expression; + LOG_DEBUGGER(ERROR) << "Evaluate fail, expression: " << expression; } return DispatchResponse::Create(ret); } @@ -539,7 +543,7 @@ DispatchResponse DebuggerImpl::EvaluateOnCallFrame(const EvaluateOnCallFramePara auto res = DebuggerApi::EvaluateViaFuncCall(const_cast(vm_), funcRef, callFrameHandlers_[callFrameId]); if (vm_->GetJSThread()->HasPendingException()) { - LOG(ERROR, DEBUGGER) << "EvaluateValue: has pending exception"; + LOG_DEBUGGER(ERROR) << "EvaluateValue: has pending exception"; std::string msg; DebuggerApi::HandleUncaughtException(vm_, msg); *result = RemoteObject::FromTagged(vm_, @@ -562,7 +566,7 @@ DispatchResponse DebuggerImpl::GetPossibleBreakpoints(const GetPossibleBreakpoin } JSPtExtractor *extractor = GetExtractor(iter->second->GetUrl()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "GetPossibleBreakpoints: extractor is null"; + LOG_DEBUGGER(ERROR) << "GetPossibleBreakpoints: extractor is null"; return DispatchResponse::Fail("Unknown file name."); } @@ -601,14 +605,14 @@ DispatchResponse DebuggerImpl::Pause() DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams ¶ms) { std::string id = params.GetBreakpointId(); - LOG(INFO, DEBUGGER) << "RemoveBreakpoint: " << id; + LOG_DEBUGGER(INFO) << "RemoveBreakpoint: " << id; BreakpointDetails metaData{}; if (!BreakpointDetails::ParseBreakpointId(id, &metaData)) { return DispatchResponse::Fail("Parse breakpoint id failed"); } JSPtExtractor *extractor = GetExtractor(metaData.url_); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "RemoveBreakpoint: extractor is null"; + LOG_DEBUGGER(ERROR) << "RemoveBreakpoint: extractor is null"; return DispatchResponse::Fail("Unknown file name."); } @@ -618,7 +622,7 @@ DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams &pa return true; }; if (!MatchScripts(scriptFunc, metaData.url_, ScriptMatchType::URL)) { - LOG(ERROR, DEBUGGER) << "RemoveBreakpoint: Unknown url: " << metaData.url_; + LOG_DEBUGGER(ERROR) << "RemoveBreakpoint: Unknown url: " << metaData.url_; return DispatchResponse::Fail("Unknown file name."); } @@ -627,12 +631,12 @@ DispatchResponse DebuggerImpl::RemoveBreakpoint(const RemoveBreakpointParams &pa return DebuggerApi::RemoveBreakpoint(jsDebugger_, location); }; if (!extractor->MatchWithLocation(callbackFunc, metaData.line_, metaData.column_)) { - LOG(ERROR, DEBUGGER) << "failed to set breakpoint location number: " + LOG_DEBUGGER(ERROR) << "failed to set breakpoint location number: " << metaData.line_ << ":" << metaData.column_; return DispatchResponse::Fail("Breakpoint not found."); } - LOG(INFO, DEBUGGER) << "remove breakpoint32_t line number:" << metaData.line_; + LOG_DEBUGGER(INFO) << "remove breakpoint line number:" << metaData.line_; return DispatchResponse::Ok(); } @@ -645,8 +649,7 @@ DispatchResponse DebuggerImpl::Resume([[maybe_unused]] const ResumeParams ¶m DispatchResponse DebuggerImpl::SetAsyncCallStackDepth() { - LOG(ERROR, DEBUGGER) << "SetAsyncCallStackDepth not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("SetAsyncCallStackDepth not support now"); } DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams ¶ms, @@ -660,7 +663,7 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams JSPtExtractor *extractor = GetExtractor(url); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "SetBreakpointByUrl: extractor is null"; + LOG_DEBUGGER(ERROR) << "SetBreakpointByUrl: extractor is null"; return DispatchResponse::Fail("Unknown file name."); } @@ -672,7 +675,7 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams return true; }; if (!MatchScripts(scriptFunc, url, ScriptMatchType::URL)) { - LOG(ERROR, DEBUGGER) << "SetBreakpointByUrl: Unknown url: " << url; + LOG_DEBUGGER(ERROR) << "SetBreakpointByUrl: Unknown url: " << url; return DispatchResponse::Fail("Unknown file name."); } @@ -682,20 +685,20 @@ DispatchResponse DebuggerImpl::SetBreakpointByUrl(const SetBreakpointByUrlParams if (condition.has_value() && !condition.value().empty()) { std::string dest; if (!DecodeAndCheckBase64(condition.value(), dest)) { - LOG(ERROR, DEBUGGER) << "SetBreakpointByUrl: base64 decode failed"; + LOG_DEBUGGER(ERROR) << "SetBreakpointByUrl: base64 decode failed"; return false; } condFuncRef = DebuggerApi::GenerateFuncFromBuffer(vm_, dest.data(), dest.size(), JSPandaFile::ENTRY_MAIN_FUNCTION); if (condFuncRef->IsUndefined()) { - LOG(ERROR, DEBUGGER) << "SetBreakpointByUrl: generate function failed"; + LOG_DEBUGGER(ERROR) << "SetBreakpointByUrl: generate function failed"; return false; } } return DebuggerApi::SetBreakpoint(jsDebugger_, location, condFuncRef); }; if (!extractor->MatchWithLocation(callbackFunc, lineNumber, columnNumber)) { - LOG(ERROR, DEBUGGER) << "failed to set breakpoint location number: " << lineNumber << ":" << columnNumber; + LOG_DEBUGGER(ERROR) << "failed to set breakpoint location number: " << lineNumber << ":" << columnNumber; return DispatchResponse::Fail("Breakpoint not found."); } @@ -722,7 +725,7 @@ DispatchResponse DebuggerImpl::StepInto([[maybe_unused]] const StepIntoParams &p JSMethod *method = DebuggerApi::GetMethod(vm_); JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "StepOver: extractor is null"; + LOG_DEBUGGER(ERROR) << "StepOver: extractor is null"; return DispatchResponse::Fail("Unknown file name."); } singleStepper_ = extractor->GetStepIntoStepper(vm_); @@ -736,7 +739,7 @@ DispatchResponse DebuggerImpl::StepOut() JSMethod *method = DebuggerApi::GetMethod(vm_); JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "StepOut: extractor is null"; + LOG_DEBUGGER(ERROR) << "StepOut: extractor is null"; return DispatchResponse::Fail("Unknown file name."); } singleStepper_ = extractor->GetStepOutStepper(vm_); @@ -750,7 +753,7 @@ DispatchResponse DebuggerImpl::StepOver([[maybe_unused]] const StepOverParams &p JSMethod *method = DebuggerApi::GetMethod(vm_); JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "StepOver: extractor is null"; + LOG_DEBUGGER(ERROR) << "StepOver: extractor is null"; return DispatchResponse::Fail("Unknown file name."); } singleStepper_ = extractor->GetStepOverStepper(vm_); @@ -761,8 +764,7 @@ DispatchResponse DebuggerImpl::StepOver([[maybe_unused]] const StepOverParams &p DispatchResponse DebuggerImpl::SetBlackboxPatterns() { - LOG(ERROR, DEBUGGER) << "SetBlackboxPatterns not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("SetBlackboxPatterns not support now"); } void DebuggerImpl::CleanUpOnPaused() @@ -805,7 +807,7 @@ bool DebuggerImpl::GenerateCallFrames(std::vector> *c auto walkerFunc = [this, &callFrameId, &callFrames](const FrameHandler *frameHandler) -> StackState { JSMethod *method = DebuggerApi::GetMethod(frameHandler); if (method->IsNativeWithCallField()) { - LOG(INFO, DEBUGGER) << "GenerateCallFrames: Skip CFrame and Native method"; + LOG_DEBUGGER(INFO) << "GenerateCallFrames: Skip CFrame and Native method"; return StackState::CONTINUE; } std::unique_ptr callFrame = std::make_unique(); @@ -836,7 +838,7 @@ bool DebuggerImpl::GenerateCallFrame(CallFrame *callFrame, JSMethod *method = DebuggerApi::GetMethod(frameHandler); JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "GenerateCallFrame: extractor is null"; + LOG_DEBUGGER(ERROR) << "GenerateCallFrame: extractor is null"; return false; } @@ -848,7 +850,7 @@ bool DebuggerImpl::GenerateCallFrame(CallFrame *callFrame, return true; }; if (!MatchScripts(scriptFunc, url, ScriptMatchType::URL)) { - LOG(ERROR, DEBUGGER) << "GenerateCallFrame: Unknown url: " << url; + LOG_DEBUGGER(ERROR) << "GenerateCallFrame: Unknown url: " << url; return false; } auto callbackLineFunc = [&location](int32_t line) -> bool { @@ -862,7 +864,7 @@ bool DebuggerImpl::GenerateCallFrame(CallFrame *callFrame, File::EntityId methodId = method->GetMethodId(); if (!extractor->MatchLineWithOffset(callbackLineFunc, methodId, DebuggerApi::GetBytecodeOffset(frameHandler)) || !extractor->MatchColumnWithOffset(callbackColumnFunc, methodId, DebuggerApi::GetBytecodeOffset(frameHandler))) { - LOG(ERROR, DEBUGGER) << "GenerateCallFrame: unknown offset: " << DebuggerApi::GetBytecodeOffset(frameHandler); + LOG_DEBUGGER(ERROR) << "GenerateCallFrame: unknown offset: " << DebuggerApi::GetBytecodeOffset(frameHandler); return false; } @@ -894,12 +896,12 @@ std::unique_ptr DebuggerImpl::GetLocalScopeChain(const FrameHandler *fram JSMethod *method = DebuggerApi::GetMethod(frameHandler); JSPtExtractor *extractor = GetExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "GetScopeChain: extractor is null"; + LOG_DEBUGGER(ERROR) << "GetScopeChain: extractor is null"; return localScope; } std::unique_ptr local = std::make_unique(); - Local localObj(local->NewObject(vm_)); + Local localObj = ObjectRef::New(vm_); local->SetType(ObjectType::Object) .SetObjectId(runtime_->curObjectId_) .SetClassName(ObjectClassName::Object) @@ -1015,12 +1017,12 @@ std::unique_ptr DebuggerImpl::GetGlobalScopeChain() } void DebuggerImpl::UpdateScopeObject(const FrameHandler *frameHandler, - std::string_view varName, const Local &newVal) + std::string_view varName, Local newVal) { auto *sp = DebuggerApi::GetSp(frameHandler); auto iter = scopeObjects_.find(sp); if (iter == scopeObjects_.end()) { - LOG(ERROR, DEBUGGER) << "UpdateScopeObject: object not found"; + LOG_DEBUGGER(ERROR) << "UpdateScopeObject: object not found"; return; } @@ -1028,11 +1030,11 @@ void DebuggerImpl::UpdateScopeObject(const FrameHandler *frameHandler, Local localObj = runtime_->properties_[objectId].ToLocal(vm_); Local name = StringRef::NewFromUtf8(vm_, varName.data()); if (localObj->Has(vm_, name)) { - LOG(DEBUG, DEBUGGER) << "UpdateScopeObject: set new value"; + LOG_DEBUGGER(DEBUG) << "UpdateScopeObject: set new value"; PropertyAttribute descriptor(newVal, true, true, true); localObj->DefineProperty(vm_, name, descriptor); } else { - LOG(ERROR, DEBUGGER) << "UpdateScopeObject: not found " << varName; + LOG_DEBUGGER(ERROR) << "UpdateScopeObject: not found " << varName; } } diff --git a/ecmascript/tooling/agent/debugger_impl.h b/ecmascript/tooling/agent/debugger_impl.h index 38bceeac609f1dd651447c5962bb9ad1ba87401d..1c2eda68e82d01f124e7cc839b4a4a6af7ed6a44 100644 --- a/ecmascript/tooling/agent/debugger_impl.h +++ b/ecmascript/tooling/agent/debugger_impl.h @@ -38,6 +38,7 @@ public: bool NotifySingleStep(const JSPtLocation &location); void NotifyPaused(std::optional location, PauseReason reason); void NotifyPendingJobEntry(); + void NotifyHandleProtocolCommand(); DispatchResponse Enable(const EnableParams ¶ms, UniqueDebuggerId *id); DispatchResponse Disable(); @@ -141,7 +142,7 @@ private: void GetLocalVariables(const FrameHandler *frameHandler, const JSMethod *method, Local &thisVal, Local &localObj); void CleanUpOnPaused(); - void UpdateScopeObject(const FrameHandler *frameHandler, std::string_view varName, const Local &newVal); + void UpdateScopeObject(const FrameHandler *frameHandler, std::string_view varName, Local newVal); Local ConvertToLocal(const std::string &varValue); bool DecodeAndCheckBase64(const std::string &src, std::string &dest); bool IsSkipLine(const JSPtLocation &location); diff --git a/ecmascript/tooling/agent/heapprofiler_impl.cpp b/ecmascript/tooling/agent/heapprofiler_impl.cpp index b88e8272bcf139f90b739c7b86abd47a6dc0b1bc..c88cad3a8e9a895a0294cd90935563bc98d59eb2 100644 --- a/ecmascript/tooling/agent/heapprofiler_impl.cpp +++ b/ecmascript/tooling/agent/heapprofiler_impl.cpp @@ -34,7 +34,7 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) }; const std::string &method = request.GetMethod(); - LOG(DEBUG, DEBUGGER) << "dispatch [" << method << "] to HeapProfilerImpl"; + LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to HeapProfilerImpl"; auto entry = dispatcherTable.find(method); if (entry != dispatcherTable.end() && entry->second != nullptr) { (this->*(entry->second))(request); @@ -45,8 +45,7 @@ void HeapProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) void HeapProfilerImpl::DispatcherImpl::AddInspectedHeapObject(const DispatchRequest &request) { - std::unique_ptr params = - AddInspectedHeapObjectParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = AddInspectedHeapObjectParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -75,8 +74,7 @@ void HeapProfilerImpl::DispatcherImpl::Disable(const DispatchRequest &request) void HeapProfilerImpl::DispatcherImpl::GetHeapObjectId(const DispatchRequest &request) { - std::unique_ptr params = - GetHeapObjectIdParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetHeapObjectIdParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -90,8 +88,7 @@ void HeapProfilerImpl::DispatcherImpl::GetHeapObjectId(const DispatchRequest &re void HeapProfilerImpl::DispatcherImpl::GetObjectByHeapObjectId(const DispatchRequest &request) { - std::unique_ptr params = - GetObjectByHeapObjectIdParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetObjectByHeapObjectIdParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -99,6 +96,11 @@ void HeapProfilerImpl::DispatcherImpl::GetObjectByHeapObjectId(const DispatchReq std::unique_ptr remoteObjectResult; DispatchResponse response = heapprofiler_->GetObjectByHeapObjectId(*params, &remoteObjectResult); + if (remoteObjectResult == nullptr) { + SendResponse(request, response); + return; + } + GetObjectByHeapObjectIdReturns result(std::move(remoteObjectResult)); SendResponse(request, response, result); } @@ -107,6 +109,11 @@ void HeapProfilerImpl::DispatcherImpl::GetSamplingProfile(const DispatchRequest { std::unique_ptr profile; DispatchResponse response = heapprofiler_->GetSamplingProfile(&profile); + if (profile == nullptr) { + SendResponse(request, response); + return; + } + // The return value type of GetSamplingProfile is the same as of StopSampling. StopSamplingReturns result(std::move(profile)); SendResponse(request, response, result); @@ -114,8 +121,7 @@ void HeapProfilerImpl::DispatcherImpl::GetSamplingProfile(const DispatchRequest void HeapProfilerImpl::DispatcherImpl::StartSampling(const DispatchRequest &request) { - std::unique_ptr params = - StartSamplingParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StartSamplingParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -127,7 +133,7 @@ void HeapProfilerImpl::DispatcherImpl::StartSampling(const DispatchRequest &requ void HeapProfilerImpl::DispatcherImpl::StartTrackingHeapObjects(const DispatchRequest &request) { std::unique_ptr params = - StartTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + StartTrackingHeapObjectsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -141,14 +147,18 @@ void HeapProfilerImpl::DispatcherImpl::StopSampling(const DispatchRequest &reque { std::unique_ptr profile; DispatchResponse response = heapprofiler_->StopSampling(&profile); + if (profile == nullptr) { + SendResponse(request, response); + return; + } + StopSamplingReturns result(std::move(profile)); SendResponse(request, response, result); } void HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects(const DispatchRequest &request) { - std::unique_ptr params = - StopTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StopTrackingHeapObjectsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -159,8 +169,7 @@ void HeapProfilerImpl::DispatcherImpl::StopTrackingHeapObjects(const DispatchReq void HeapProfilerImpl::DispatcherImpl::TakeHeapSnapshot(const DispatchRequest &request) { - std::unique_ptr params = - StopTrackingHeapObjectsParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StopTrackingHeapObjectsParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -174,7 +183,7 @@ bool HeapProfilerImpl::Frontend::AllowNotify() const return channel_ != nullptr; } -void HeapProfilerImpl::Frontend::AddHeapSnapshotChunk(char *data, int size) +void HeapProfilerImpl::Frontend::AddHeapSnapshotChunk(char *data, int32_t size) { if (!AllowNotify()) { return; @@ -182,7 +191,7 @@ void HeapProfilerImpl::Frontend::AddHeapSnapshotChunk(char *data, int size) tooling::AddHeapSnapshotChunk addHeapSnapshotChunk; addHeapSnapshotChunk.GetChunk().resize(size); - for (int i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { addHeapSnapshotChunk.GetChunk()[i] = data[i]; } @@ -203,13 +212,13 @@ void HeapProfilerImpl::Frontend::ReportHeapSnapshotProgress(int32_t done, int32_ channel_->SendNotification(reportHeapSnapshotProgress); } -void HeapProfilerImpl::Frontend::HeapStatsUpdate(HeapStat* updateData, int count) +void HeapProfilerImpl::Frontend::HeapStatsUpdate(HeapStat* updateData, int32_t count) { if (!AllowNotify()) { return; } - std::vector statsDiff; - for (int i = 0; i < count; ++i) { + std::vector statsDiff; + for (int32_t i = 0; i < count; ++i) { statsDiff.emplace_back(updateData[i].index_); statsDiff.emplace_back(updateData[i].count_); statsDiff.emplace_back(updateData[i].size_); @@ -219,7 +228,7 @@ void HeapProfilerImpl::Frontend::HeapStatsUpdate(HeapStat* updateData, int count channel_->SendNotification(heapStatsUpdate); } -void HeapProfilerImpl::Frontend::LastSeenObjectId(uint32_t lastSeenObjectId) +void HeapProfilerImpl::Frontend::LastSeenObjectId(int32_t lastSeenObjectId) { if (!AllowNotify()) { return; @@ -227,12 +236,13 @@ void HeapProfilerImpl::Frontend::LastSeenObjectId(uint32_t lastSeenObjectId) tooling::LastSeenObjectId lastSeenObjectIdEvent; lastSeenObjectIdEvent.SetLastSeenObjectId(lastSeenObjectId); - size_t timestamp = 0; + int64_t timestamp = 0; struct timeval tv = {0, 0}; gettimeofday(&tv, nullptr); const int THOUSAND = 1000; - timestamp = static_cast(tv.tv_usec + tv.tv_sec * THOUSAND * THOUSAND); - lastSeenObjectIdEvent.SetTimestamp(timestamp); + timestamp = static_cast(tv.tv_usec + tv.tv_sec * THOUSAND * THOUSAND); + double timestampMS = static_cast(timestamp) / THOUSAND; + lastSeenObjectIdEvent.SetTimestamp(timestampMS); channel_->SendNotification(lastSeenObjectIdEvent); } @@ -243,28 +253,23 @@ void HeapProfilerImpl::Frontend::ResetProfiles() } } -DispatchResponse HeapProfilerImpl::AddInspectedHeapObject( - [[maybe_unused]] const AddInspectedHeapObjectParams ¶ms) +DispatchResponse HeapProfilerImpl::AddInspectedHeapObject([[maybe_unused]] const AddInspectedHeapObjectParams ¶ms) { - LOG(ERROR, DEBUGGER) << "AddInspectedHeapObject not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("AddInspectedHeapObject not support now"); } DispatchResponse HeapProfilerImpl::CollectGarbage() { - LOG(ERROR, DEBUGGER) << "CollectGarbage not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("CollectGarbage not support now"); } DispatchResponse HeapProfilerImpl::Enable() { - LOG(ERROR, DEBUGGER) << "Enable not support now."; return DispatchResponse::Ok(); } DispatchResponse HeapProfilerImpl::Disable() { - LOG(ERROR, DEBUGGER) << "Disable not support now."; return DispatchResponse::Ok(); } @@ -273,34 +278,30 @@ DispatchResponse HeapProfilerImpl::GetHeapObjectId([[maybe_unused]] const GetHea { ASSERT(objectId != nullptr); *objectId = 0; - LOG(ERROR, DEBUGGER) << "GetHeapObjectId not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("GetHeapObjectId not support now"); } DispatchResponse HeapProfilerImpl::GetObjectByHeapObjectId( [[maybe_unused]] const GetObjectByHeapObjectIdParams ¶ms, [[maybe_unused]] std::unique_ptr *remoteObjectResult) { - LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectId not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("GetObjectByHeapObjectId not support now"); } DispatchResponse HeapProfilerImpl::GetSamplingProfile([[maybe_unused]]std::unique_ptr *profile) { - LOG(ERROR, DEBUGGER) << "GetSamplingProfile not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("GetSamplingProfile not support now"); } DispatchResponse HeapProfilerImpl::StartSampling([[maybe_unused]]const StartSamplingParams ¶ms) { - LOG(ERROR, DEBUGGER) << "StartSampling not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("StartSampling not support now"); } -DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects( - [[maybe_unused]]const StartTrackingHeapObjectsParams ¶ms) +DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects(const StartTrackingHeapObjectsParams ¶ms) { - bool result = panda::DFXJSNApi::StartHeapTracking(vm_, INTERVAL, true, &stream_); + bool traceAllocation = params.GetTrackAllocations(); + bool result = panda::DFXJSNApi::StartHeapTracking(vm_, INTERVAL, true, &stream_, traceAllocation); if (result) { return DispatchResponse::Ok(); } else { @@ -310,8 +311,7 @@ DispatchResponse HeapProfilerImpl::StartTrackingHeapObjects( DispatchResponse HeapProfilerImpl::StopSampling([[maybe_unused]]std::unique_ptr *profile) { - LOG(ERROR, DEBUGGER) << "StopSampling not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("StopSampling not support now."); } DispatchResponse HeapProfilerImpl::StopTrackingHeapObjects(const StopTrackingHeapObjectsParams ¶ms) diff --git a/ecmascript/tooling/agent/heapprofiler_impl.h b/ecmascript/tooling/agent/heapprofiler_impl.h index a5c2bc60c2f0cedef7c5af438116a9ada6834acb..266a7487ee4afb1b956c7644b29f4741f545aaab 100644 --- a/ecmascript/tooling/agent/heapprofiler_impl.h +++ b/ecmascript/tooling/agent/heapprofiler_impl.h @@ -27,7 +27,6 @@ #include "ecmascript/tooling/protocol_handler.h" #include "ecmascript/tooling/protocol_channel.h" #include "ecmascript/napi/include/dfx_jsnapi.h" -#include "libpandabase/utils/logger.h" static const double INTERVAL = 0.05; @@ -89,10 +88,10 @@ private: public: explicit Frontend(ProtocolChannel *channel) : channel_(channel) {} - void AddHeapSnapshotChunk(char *data, int size); + void AddHeapSnapshotChunk(char *data, int32_t size); void ReportHeapSnapshotProgress(int32_t done, int32_t total); - void HeapStatsUpdate(HeapStat* updateData, int count); - void LastSeenObjectId(uint32_t lastSeenObjectId); + void HeapStatsUpdate(HeapStat* updateData, int32_t count); + void LastSeenObjectId(int32_t lastSeenObjectId); void ResetProfiles(); private: @@ -112,7 +111,7 @@ private: static const int heapProfilerChunkSise = 102400; return heapProfilerChunkSise; } - bool WriteChunk(char *data, int size) override + bool WriteChunk(char *data, int32_t size) override { if (!Good()) { return false; @@ -125,7 +124,7 @@ private: return frontend_ != nullptr; } - void UpdateHeapStats(HeapStat* updateData, int count) override + void UpdateHeapStats(HeapStat* updateData, int32_t count) override { if (!Good()) { return; @@ -133,7 +132,7 @@ private: frontend_->HeapStatsUpdate(updateData, count); } - void UpdateLastSeenObjectId(uint32_t lastSeenObjectId) override + void UpdateLastSeenObjectId(int32_t lastSeenObjectId) override { if (!Good()) { return; diff --git a/ecmascript/tooling/agent/profiler_impl.cpp b/ecmascript/tooling/agent/profiler_impl.cpp index 022030a075282c0d6f2d768c74b31694abd09e8f..c76606e9e19433d1f89e62badddd912d8b778fcf 100644 --- a/ecmascript/tooling/agent/profiler_impl.cpp +++ b/ecmascript/tooling/agent/profiler_impl.cpp @@ -18,7 +18,6 @@ #include "ecmascript/napi/include/dfx_jsnapi.h" #include "ecmascript/tooling/base/pt_events.h" #include "ecmascript/tooling/protocol_channel.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript::tooling { void ProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) @@ -39,7 +38,7 @@ void ProfilerImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) }; const std::string &method = request.GetMethod(); - LOG(DEBUG, DEBUGGER) << "dispatch [" << method << "] to ProfilerImpl"; + LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to ProfilerImpl"; auto entry = dispatcherTable.find(method); if (entry != dispatcherTable.end() && entry->second != nullptr) { (this->*(entry->second))(request); @@ -70,14 +69,18 @@ void ProfilerImpl::DispatcherImpl::Stop(const DispatchRequest &request) { std::unique_ptr profile; DispatchResponse response = profiler_->Stop(&profile); + if (profile == nullptr) { + SendResponse(request, response); + return; + } + StopReturns result(std::move(profile)); SendResponse(request, response, result); } void ProfilerImpl::DispatcherImpl::SetSamplingInterval(const DispatchRequest &request) { - std::unique_ptr params = - SetSamplingIntervalParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = SetSamplingIntervalParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -106,8 +109,7 @@ void ProfilerImpl::DispatcherImpl::TakePreciseCoverage(const DispatchRequest &re void ProfilerImpl::DispatcherImpl::StartPreciseCoverage(const DispatchRequest &request) { - std::unique_ptr params = - StartPreciseCoverageParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = StartPreciseCoverageParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -171,13 +173,11 @@ void ProfilerImpl::Frontend::PreciseCoverageDeltaUpdate() DispatchResponse ProfilerImpl::Disable() { - LOG(ERROR, DEBUGGER) << "Disable not support now."; return DispatchResponse::Ok(); } DispatchResponse ProfilerImpl::Enable() { - LOG(ERROR, DEBUGGER) << "Enable not support now."; return DispatchResponse::Ok(); } @@ -191,7 +191,7 @@ DispatchResponse ProfilerImpl::Stop(std::unique_ptr *profile) { auto profileInfo = panda::DFXJSNApi::StopCpuProfilerForInfo(); if (profileInfo == nullptr) { - LOG(ERROR, DEBUGGER) << "Transfer DFXJSNApi::StopCpuProfilerImpl is failure"; + LOG_DEBUGGER(ERROR) << "Transfer DFXJSNApi::StopCpuProfilerImpl is failure"; return DispatchResponse::Fail("Stop is failure"); } *profile = Profile::FromProfileInfo(*profileInfo); @@ -206,43 +206,36 @@ DispatchResponse ProfilerImpl::SetSamplingInterval(const SetSamplingIntervalPara DispatchResponse ProfilerImpl::GetBestEffortCoverage() { - LOG(ERROR, DEBUGGER) << "GetBestEffortCoverage not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("GetBestEffortCoverage not support now"); } DispatchResponse ProfilerImpl::StopPreciseCoverage() { - LOG(ERROR, DEBUGGER) << "StopPreciseCoverage not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("StopPreciseCoverage not support now"); } DispatchResponse ProfilerImpl::TakePreciseCoverage() { - LOG(ERROR, DEBUGGER) << "TakePreciseCoverage not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("TakePreciseCoverage not support now"); } DispatchResponse ProfilerImpl::StartPreciseCoverage([[maybe_unused]] const StartPreciseCoverageParams ¶ms) { - LOG(ERROR, DEBUGGER) << "StartPreciseCoverage not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("StartPreciseCoverage not support now"); } DispatchResponse ProfilerImpl::StartTypeProfile() { - LOG(ERROR, DEBUGGER) << "StartTypeProfile not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("StartTypeProfile not support now"); } DispatchResponse ProfilerImpl::StopTypeProfile() { - LOG(ERROR, DEBUGGER) << "StopTypeProfile not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("StopTypeProfile not support now"); } DispatchResponse ProfilerImpl::TakeTypeProfile() { - LOG(ERROR, DEBUGGER) << "TakeTypeProfile not support now."; - return DispatchResponse::Ok(); + return DispatchResponse::Fail("TakeTypeProfile not support now"); } } // namespace panda::ecmascript::tooling diff --git a/ecmascript/tooling/agent/runtime_impl.cpp b/ecmascript/tooling/agent/runtime_impl.cpp index ded0e698f248d730036c1ae2c5433ce93b847791..0c03ca914c55f2e92785185b9fa6f2fc842cec2e 100644 --- a/ecmascript/tooling/agent/runtime_impl.cpp +++ b/ecmascript/tooling/agent/runtime_impl.cpp @@ -20,7 +20,6 @@ #include "ecmascript/napi/include/dfx_jsnapi.h" #include "ecmascript/tooling/base/pt_returns.h" #include "ecmascript/tooling/protocol_channel.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript::tooling { void RuntimeImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) @@ -34,13 +33,13 @@ void RuntimeImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) }; const std::string &method = request.GetMethod(); - LOG(DEBUG, DEBUGGER) << "dispatch [" << method << "] to RuntimeImpl"; + LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to RuntimeImpl"; auto entry = dispatcherTable.find(method); if (entry != dispatcherTable.end()) { (this->*(entry->second))(request); } else { - LOG(ERROR, DEBUGGER) << "unknown method: " << method; + LOG_DEBUGGER(ERROR) << "unknown method: " << method; SendResponse(request, DispatchResponse::Fail("unknown method: " + method)); } } @@ -65,8 +64,7 @@ void RuntimeImpl::DispatcherImpl::RunIfWaitingForDebugger(const DispatchRequest void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request) { - std::unique_ptr params = - GetPropertiesParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = GetPropertiesParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -79,7 +77,8 @@ void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request) DispatchResponse response = runtime_->GetProperties(*params, &outPropertyDesc, &outInternalDescs, &outPrivateProperties, &outExceptionDetails); if (outExceptionDetails) { - LOG(WARNING, DEBUGGER) << "GetProperties thrown an exception"; + ASSERT(outExceptionDetails.value() != nullptr); + LOG_DEBUGGER(WARN) << "GetProperties thrown an exception"; } GetPropertiesReturns result(std::move(outPropertyDesc), std::move(outInternalDescs), @@ -90,8 +89,7 @@ void RuntimeImpl::DispatcherImpl::GetProperties(const DispatchRequest &request) void RuntimeImpl::DispatcherImpl::CallFunctionOn(const DispatchRequest &request) { - std::unique_ptr params = - CallFunctionOnParams::Create(request.GetEcmaVM(), request.GetParamsObj()); + std::unique_ptr params = CallFunctionOnParams::Create(request.GetParams()); if (params == nullptr) { SendResponse(request, DispatchResponse::Fail("wrong params")); return; @@ -101,8 +99,14 @@ void RuntimeImpl::DispatcherImpl::CallFunctionOn(const DispatchRequest &request) std::optional> outExceptionDetails; DispatchResponse response = runtime_->CallFunctionOn(*params, &outRemoteObject, &outExceptionDetails); if (outExceptionDetails) { - LOG(WARNING, DEBUGGER) << "CallFunctionOn thrown an exception"; + ASSERT(outExceptionDetails.value() != nullptr); + LOG_DEBUGGER(WARN) << "CallFunctionOn thrown an exception"; } + if (outRemoteObject == nullptr) { + SendResponse(request, response); + return; + } + CallFunctionOnReturns result(std::move(outRemoteObject), std::move(outExceptionDetails)); SendResponse(request, response, result); } @@ -174,17 +178,27 @@ DispatchResponse RuntimeImpl::GetProperties(const GetPropertiesParams ¶ms, bool isAccessorOnly = params.GetAccessPropertiesOnly(); auto iter = properties_.find(objectId); if (iter == properties_.end()) { - LOG(ERROR, DEBUGGER) << "RuntimeImpl::GetProperties Unknown object id: " << objectId; + LOG_DEBUGGER(ERROR) << "RuntimeImpl::GetProperties Unknown object id: " << objectId; return DispatchResponse::Fail("Unknown object id"); } Local value = Local(vm_, iter->second); if (value.IsEmpty() || !value->IsObject()) { - LOG(ERROR, DEBUGGER) << "RuntimeImpl::GetProperties should a js object"; + LOG_DEBUGGER(ERROR) << "RuntimeImpl::GetProperties should a js object"; return DispatchResponse::Fail("Not a object"); } if (value->IsArrayBuffer()) { Local arrayBufferRef(value); AddTypedArrayRefs(arrayBufferRef, outPropertyDesc); + } else if (value->IsMapIterator()) { + GetMapIteratorValue(value, outPropertyDesc); + } else if (value->IsSetIterator()) { + GetSetIteratorValue(value, outPropertyDesc); + } else if (value->IsJSPrimitiveRef() && value->IsJSPrimitiveNumber()) { + GetPrimitiveNumberValue(value, outPropertyDesc); + } else if (value->IsJSPrimitiveRef() && value->IsJSPrimitiveString()) { + GetPrimitiveStringValue(value, outPropertyDesc); + } else if (value->IsJSPrimitiveRef() && value->IsJSPrimitiveBoolean()) { + GetPrimitiveBooleanValue(value, outPropertyDesc); } Local keys = Local(value)->GetOwnPropertyNames(vm_); int32_t length = keys->Length(vm_); @@ -283,7 +297,7 @@ void RuntimeImpl::CacheObjectIfNeeded(Local valRef, RemoteObject *re } } -void RuntimeImpl::GetProtoOrProtoType(const Local &value, bool isOwn, bool isAccessorOnly, +void RuntimeImpl::GetProtoOrProtoType(Local value, bool isOwn, bool isAccessorOnly, std::vector> *outPropertyDesc) { if (!isAccessorOnly && isOwn && !value->IsProxy()) { @@ -317,7 +331,7 @@ void RuntimeImpl::GetProtoOrProtoType(const Local &value, bool isOwn outPropertyDesc->emplace_back(std::move(debuggerProperty)); } -void RuntimeImpl::GetAdditionalProperties(const Local &value, +void RuntimeImpl::GetAdditionalProperties(Local value, std::vector> *outPropertyDesc) { // The length of the TypedArray have to be limited(less than or equal to lengthTypedArrayLimit) until we construct @@ -332,7 +346,7 @@ void RuntimeImpl::GetAdditionalProperties(const Local &value, Local localTypedArrayRef(value); uint32_t lengthTypedArray = localTypedArrayRef->ArrayLength(vm_); if (lengthTypedArray > lengthTypedArrayLimit) { - LOG(ERROR, DEBUGGER) << "The length of the TypedArray is non-compliant or unsupported."; + LOG_DEBUGGER(ERROR) << "The length of the TypedArray is non-compliant or unsupported."; return; } for (uint32_t i = 0; i < lengthTypedArray; i++) { @@ -355,4 +369,70 @@ void RuntimeImpl::GetAdditionalProperties(const Local &value, } } } + +void RuntimeImpl::SetKeyValue(Local &jsValueRef, + std::vector> *outPropertyDesc, const std::string &strProName) +{ + std::unique_ptr remoteObj = RemoteObject::FromTagged(vm_, jsValueRef); + remoteObj->SetObjectId(curObjectId_); + properties_[curObjectId_++] = Global(vm_, jsValueRef); + std::unique_ptr debuggerProperty = std::make_unique(); + debuggerProperty->SetName(strProName) + .SetWritable(false) + .SetConfigurable(false) + .SetEnumerable(false) + .SetIsOwn(false) + .SetValue(std::move(remoteObj)); + outPropertyDesc->emplace_back(std::move(debuggerProperty)); +} + +void RuntimeImpl::GetPrimitiveNumberValue(Local value, + std::vector> *outPropertyDesc) +{ + Local jsValueRef; + jsValueRef = value->ToNumber(vm_); + SetKeyValue(jsValueRef, outPropertyDesc, "[[PrimitiveValue]]"); +} + +void RuntimeImpl::GetPrimitiveStringValue(Local value, + std::vector> *outPropertyDesc) +{ + Local jsValueRef; + jsValueRef = value->ToString(vm_); + SetKeyValue(jsValueRef, outPropertyDesc, "[[PrimitiveValue]]"); +} + +void RuntimeImpl::GetPrimitiveBooleanValue(Local value, + std::vector> *outPropertyDesc) +{ + Local jsValueRef; + jsValueRef = value->ToBoolean(vm_); + SetKeyValue(jsValueRef, outPropertyDesc, "[[PrimitiveValue]]"); +} + +void RuntimeImpl::GetMapIteratorValue(Local value, + std::vector> *outPropertyDesc) +{ + Local jsValueRef; + Local iterRef = value->ToObject(vm_); + if (!iterRef.IsEmpty()) { + jsValueRef = NumberRef::New(vm_, iterRef->GetIndex()); + SetKeyValue(jsValueRef, outPropertyDesc, "[[IteratorIndex]]"); + jsValueRef = iterRef->GetKind(vm_); + SetKeyValue(jsValueRef, outPropertyDesc, "[[IteratorKind]]"); + } +} + +void RuntimeImpl::GetSetIteratorValue(Local value, + std::vector> *outPropertyDesc) +{ + Local jsValueRef; + Local iterRef = value->ToObject(vm_); + if (!iterRef.IsEmpty()) { + jsValueRef = NumberRef::New(vm_, iterRef->GetIndex()); + SetKeyValue(jsValueRef, outPropertyDesc, "[[IteratorIndex]]"); + jsValueRef = iterRef->GetKind(vm_); + SetKeyValue(jsValueRef, outPropertyDesc, "[[IteratorKind]]"); + } +} } // namespace panda::ecmascript::tooling \ No newline at end of file diff --git a/ecmascript/tooling/agent/runtime_impl.h b/ecmascript/tooling/agent/runtime_impl.h index 2feae617c17f2d325b144bd253242e2b0894ff4d..493f2f2d47d6907207120535faff3ae4c04f521f 100644 --- a/ecmascript/tooling/agent/runtime_impl.h +++ b/ecmascript/tooling/agent/runtime_impl.h @@ -76,9 +76,21 @@ private: const char* name, std::vector> *outPropertyDesc); void AddTypedArrayRefs(Local arrayBufferRef, std::vector> *outPropertyDesc); - void GetProtoOrProtoType(const Local &value, bool isOwn, bool isAccessorOnly, + void GetProtoOrProtoType(Local value, bool isOwn, bool isAccessorOnly, std::vector> *outPropertyDesc); - void GetAdditionalProperties(const Local &value, + void GetAdditionalProperties(Local value, + std::vector> *outPropertyDesc); + void SetKeyValue(Local &jsValueRef, + std::vector> *outPropertyDesc, const std::string &cstrProName); + void GetPrimitiveNumberValue(Local value, + std::vector> *outPropertyDesc); + void GetPrimitiveStringValue(Local value, + std::vector> *outPropertyDesc); + void GetPrimitiveBooleanValue(Local value, + std::vector> *outPropertyDesc); + void GetMapIteratorValue(Local value, + std::vector> *outPropertyDesc); + void GetSetIteratorValue(Local value, std::vector> *outPropertyDesc); class Frontend { diff --git a/ecmascript/tooling/agent/tracing_impl.cpp b/ecmascript/tooling/agent/tracing_impl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8de90cc4b110de9262fd4dfc4f8fe7da3fa9433e --- /dev/null +++ b/ecmascript/tooling/agent/tracing_impl.cpp @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ecmascript/tooling/agent/tracing_impl.h" + +#include "ecmascript/napi/include/dfx_jsnapi.h" +#include "ecmascript/tooling/base/pt_events.h" +#include "ecmascript/tooling/protocol_channel.h" + +namespace panda::ecmascript::tooling { +void TracingImpl::DispatcherImpl::Dispatch(const DispatchRequest &request) +{ + static std::unordered_map dispatcherTable { + { "end", &TracingImpl::DispatcherImpl::End }, + { "getCategories", &TracingImpl::DispatcherImpl::GetCategories }, + { "recordClockSyncMarker", &TracingImpl::DispatcherImpl::RecordClockSyncMarker }, + { "requestMemoryDump", &TracingImpl::DispatcherImpl::RequestMemoryDump }, + { "start", &TracingImpl::DispatcherImpl::Start } + }; + + const std::string &method = request.GetMethod(); + LOG_DEBUGGER(DEBUG) << "dispatch [" << method << "] to TracingImpl"; + auto entry = dispatcherTable.find(method); + if (entry != dispatcherTable.end() && entry->second != nullptr) { + (this->*(entry->second))(request); + } else { + SendResponse(request, DispatchResponse::Fail("Unknown method: " + method)); + } +} + +void TracingImpl::DispatcherImpl::End(const DispatchRequest &request) +{ + DispatchResponse response = tracing_->End(); + SendResponse(request, response); +} + +void TracingImpl::DispatcherImpl::GetCategories(const DispatchRequest &request) +{ + std::vector categories; + DispatchResponse response = tracing_->GetCategories(categories); + SendResponse(request, response); +} + +void TracingImpl::DispatcherImpl::RecordClockSyncMarker(const DispatchRequest &request) +{ + std::string syncId; + DispatchResponse response = tracing_->RecordClockSyncMarker(syncId); + SendResponse(request, response); +} + +void TracingImpl::DispatcherImpl::RequestMemoryDump(const DispatchRequest &request) +{ + std::unique_ptr params = + RequestMemoryDumpParams::Create(request.GetParams()); + std::string dumpGuid; + bool success = false; + DispatchResponse response = tracing_->RequestMemoryDump(std::move(params), dumpGuid, success); + SendResponse(request, response); +} + +void TracingImpl::DispatcherImpl::Start(const DispatchRequest &request) +{ + std::unique_ptr params = + StartParams::Create(request.GetParams()); + DispatchResponse response = tracing_->Start(std::move(params)); + SendResponse(request, response); +} + +bool TracingImpl::Frontend::AllowNotify() const +{ + return channel_ != nullptr; +} + +void TracingImpl::Frontend::BufferUsage() +{ + if (!AllowNotify()) { + return; + } + + tooling::BufferUsage bufferUsage; + channel_->SendNotification(bufferUsage); +} + +void TracingImpl::Frontend::DataCollected() +{ + if (!AllowNotify()) { + return; + } + + tooling::DataCollected dataCollected; + channel_->SendNotification(dataCollected); +} + +void TracingImpl::Frontend::TracingComplete() +{ + if (!AllowNotify()) { + return; + } + + tooling::TracingComplete tracingComplete; + channel_->SendNotification(tracingComplete); +} + +DispatchResponse TracingImpl::End() +{ + return DispatchResponse::Fail("End not support now."); +} + +DispatchResponse TracingImpl::GetCategories([[maybe_unused]] std::vector categories) +{ + return DispatchResponse::Fail("GetCategories not support now."); +} + +DispatchResponse TracingImpl::RecordClockSyncMarker([[maybe_unused]] std::string syncId) +{ + return DispatchResponse::Fail("RecordClockSyncMarker not support now."); +} + +DispatchResponse TracingImpl::RequestMemoryDump([[maybe_unused]] std::unique_ptr params, + [[maybe_unused]] std::string dumpGuid, [[maybe_unused]] bool success) +{ + return DispatchResponse::Fail("RequestMemoryDump not support now."); +} + +DispatchResponse TracingImpl::Start([[maybe_unused]] std::unique_ptr params) +{ + return DispatchResponse::Fail("Start not support now."); +} +} // namespace panda::ecmascript::tooling \ No newline at end of file diff --git a/ecmascript/tooling/agent/tracing_impl.h b/ecmascript/tooling/agent/tracing_impl.h new file mode 100644 index 0000000000000000000000000000000000000000..92eb8e53a44c92c1134aae4be8442e6fd5454319 --- /dev/null +++ b/ecmascript/tooling/agent/tracing_impl.h @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_AGENT_TRACING_IMPL_H +#define ECMASCRIPT_TOOLING_AGENT_TRACING_IMPL_H + +#include "ecmascript/dfx/cpu_profiler/samples_record.h" +#include "ecmascript/tooling/base/pt_params.h" +#include "ecmascript/tooling/base/pt_returns.h" +#include "ecmascript/tooling/dispatcher.h" +#include "libpandabase/macros.h" + +namespace panda::ecmascript::tooling { +class TracingImpl final { +public: + explicit TracingImpl(const EcmaVM *vm, ProtocolChannel *channel) : vm_(vm), frontend_(channel) {} + ~TracingImpl() = default; + + DispatchResponse End(); + DispatchResponse GetCategories(std::vector categories); + DispatchResponse RecordClockSyncMarker(std::string syncId); + DispatchResponse RequestMemoryDump(std::unique_ptr params, + std::string dumpGuid, bool success); + DispatchResponse Start(std::unique_ptr params); + + class DispatcherImpl final : public DispatcherBase { + public: + DispatcherImpl(ProtocolChannel *channel, std::unique_ptr tracing) + : DispatcherBase(channel), tracing_(std::move(tracing)) {} + ~DispatcherImpl() override = default; + void Dispatch(const DispatchRequest &request) override; + void End(const DispatchRequest &request); + void GetCategories(const DispatchRequest &request); + void RecordClockSyncMarker(const DispatchRequest &request); + void RequestMemoryDump(const DispatchRequest &request); + void Start(const DispatchRequest &request); + + private: + NO_COPY_SEMANTIC(DispatcherImpl); + NO_MOVE_SEMANTIC(DispatcherImpl); + + using AgentHandler = void (TracingImpl::DispatcherImpl::*)(const DispatchRequest &request); + std::unique_ptr tracing_ {}; + }; + + class Frontend { + public: + explicit Frontend(ProtocolChannel *channel) : channel_(channel) {} + + void BufferUsage(); + void DataCollected(); + void TracingComplete(); + + private: + bool AllowNotify() const; + ProtocolChannel *channel_ {nullptr}; + }; + +private: + NO_COPY_SEMANTIC(TracingImpl); + NO_MOVE_SEMANTIC(TracingImpl); + + [[maybe_unused]] const EcmaVM *vm_ {nullptr}; + [[maybe_unused]] Frontend frontend_; +}; +} // namespace panda::ecmascript::tooling +#endif \ No newline at end of file diff --git a/ecmascript/tooling/backend/debugger_api.cpp b/ecmascript/tooling/backend/debugger_api.cpp index 14b59f917eecfa66e1312ea0fb40b7c6148771a4..bef42e4c1a25ee1635d42098bb16aeae38411714 100644 --- a/ecmascript/tooling/backend/debugger_api.cpp +++ b/ecmascript/tooling/backend/debugger_api.cpp @@ -110,12 +110,12 @@ int32_t DebuggerApi::GetVregIndex(const FrameHandler *frameHandler, std::string_ { JSMethod *method = frameHandler->GetMethod(); if (method->IsNativeWithCallField()) { - LOG(ERROR, DEBUGGER) << "GetVregIndex: native frame not support"; + LOG_DEBUGGER(ERROR) << "GetVregIndex: native frame not support"; return -1; } JSPtExtractor *extractor = JSPandaFileManager::GetInstance()->GetJSPtExtractor(method->GetJSPandaFile()); if (extractor == nullptr) { - LOG(ERROR, DEBUGGER) << "GetVregIndex: extractor is null"; + LOG_DEBUGGER(ERROR) << "GetVregIndex: extractor is null"; return -1; } auto table = extractor->GetLocalVariableTable(method->GetMethodId()); @@ -134,19 +134,6 @@ Local DebuggerApi::GetVRegValue(const EcmaVM *ecmaVm, return JSNApiHelper::ToLocal(handledValue); } -std::string DebuggerApi::ToStdString(Local str) -{ - ecmascript::JSHandle ret = JSNApiHelper::ToJSHandle(str); - ASSERT(ret->IsString()); - EcmaString *ecmaStr = EcmaString::Cast(ret.GetTaggedValue().GetTaggedObject()); - return CstringConvertToStdString(ConvertToString(ecmaStr)); -} - -int32_t DebuggerApi::StringToInt(Local str) -{ - return std::stoi(ToStdString(str)); -} - // JSThread Local DebuggerApi::GetAndClearException(const EcmaVM *ecmaVm) { @@ -189,7 +176,7 @@ void DebuggerApi::RegisterHooks(JSDebugger *debugger, PtHooks *hooks) } bool DebuggerApi::SetBreakpoint(JSDebugger *debugger, const JSPtLocation &location, - const Local &condFuncRef) + Local condFuncRef) { return debugger->SetBreakpoint(location, condFuncRef); } @@ -337,7 +324,7 @@ Local DebuggerApi::GenerateFuncFromBuffer(const EcmaVM *ecmaVm, con return JSNApiHelper::ToLocal(JSHandle(ecmaVm->GetJSThread(), func)); } -Local DebuggerApi::EvaluateViaFuncCall(EcmaVM *ecmaVm, const Local &funcRef, +Local DebuggerApi::EvaluateViaFuncCall(EcmaVM *ecmaVm, Local funcRef, std::shared_ptr &frameHandler) { JSNApi::EnableUserUncaughtErrorHandler(ecmaVm); diff --git a/ecmascript/tooling/backend/debugger_api.h b/ecmascript/tooling/backend/debugger_api.h index 2c715439709ba96b6dc4842583ea6bec29bf1936..b2d6376f6ea48dc9fee8a385fe828b839f844cd6 100644 --- a/ecmascript/tooling/backend/debugger_api.h +++ b/ecmascript/tooling/backend/debugger_api.h @@ -68,10 +68,6 @@ public: static Local GetGlobalValue(const EcmaVM *vm, Local name); static bool SetGlobalValue(const EcmaVM *vm, Local name, Local value); - // String - static std::string ToStdString(Local str); - static int32_t StringToInt(Local str); - // JSThread static Local GetAndClearException(const EcmaVM *ecmaVm); static void SetException(const EcmaVM *ecmaVm, Local exception); @@ -85,10 +81,10 @@ public: static void DestroyJSDebugger(JSDebugger *debugger); static void RegisterHooks(JSDebugger *debugger, PtHooks *hooks); static bool SetBreakpoint(JSDebugger *debugger, const JSPtLocation &location, - const Local &condFuncRef); + Local condFuncRef); static bool RemoveBreakpoint(JSDebugger *debugger, const JSPtLocation &location); static void HandleUncaughtException(const EcmaVM *ecmaVm, std::string &message); - static Local EvaluateViaFuncCall(EcmaVM *ecmaVm, const Local &funcRef, + static Local EvaluateViaFuncCall(EcmaVM *ecmaVm, Local funcRef, std::shared_ptr &frameHandler); static Local GenerateFuncFromBuffer(const EcmaVM *ecmaVm, const void *buffer, size_t size, std::string_view entryPoint); diff --git a/ecmascript/tooling/backend/debugger_executor.cpp b/ecmascript/tooling/backend/debugger_executor.cpp index e6c4459c16e61267306675c7fb0c0f97235ecd55..81c3e71a3a9dcebd6a7d727235d50876e06efb60 100644 --- a/ecmascript/tooling/backend/debugger_executor.cpp +++ b/ecmascript/tooling/backend/debugger_executor.cpp @@ -17,7 +17,6 @@ #include "ecmascript/tooling/backend/debugger_api.h" #include "ecmascript/tooling/interface/js_debugger_manager.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript::tooling { void DebuggerExecutor::Initialize(const EcmaVM *vm) @@ -32,7 +31,7 @@ void DebuggerExecutor::Initialize(const EcmaVM *vm) Local DebuggerExecutor::DebuggerGetValue(JsiRuntimeCallInfo *runtimeCallInfo) { EcmaVM *vm = runtimeCallInfo->GetVM(); - size_t argc = runtimeCallInfo->GetArgsNumber(); + int32_t argc = runtimeCallInfo->GetArgsNumber(); if (argc != NUM_ARGS) { return JSValueRef::Undefined(vm); } @@ -63,7 +62,7 @@ Local DebuggerExecutor::DebuggerGetValue(JsiRuntimeCallInfo *runtime Local DebuggerExecutor::DebuggerSetValue(JsiRuntimeCallInfo *runtimeCallInfo) { EcmaVM *vm = runtimeCallInfo->GetVM(); - size_t argc = runtimeCallInfo->GetArgsNumber(); + int32_t argc = runtimeCallInfo->GetArgsNumber(); if (argc != NUM_ARGS) { return JSValueRef::Undefined(vm); } diff --git a/ecmascript/tooling/backend/js_debugger.cpp b/ecmascript/tooling/backend/js_debugger.cpp index 74a3da703c4671e5016b6a74e9b6601069cc10d3..ba744d026b257fba872d7644ecc1dd6e3b23017b 100644 --- a/ecmascript/tooling/backend/js_debugger.cpp +++ b/ecmascript/tooling/backend/js_debugger.cpp @@ -25,16 +25,16 @@ namespace panda::ecmascript::tooling { using panda::ecmascript::base::BuiltinsBase; -bool JSDebugger::SetBreakpoint(const JSPtLocation &location, const Local &condFuncRef) +bool JSDebugger::SetBreakpoint(const JSPtLocation &location, Local condFuncRef) { JSMethod *method = FindMethod(location); if (method == nullptr) { - LOG(ERROR, DEBUGGER) << "SetBreakpoint: Cannot find JSMethod"; + LOG_DEBUGGER(ERROR) << "SetBreakpoint: Cannot find JSMethod"; return false; } if (location.GetBytecodeOffset() >= method->GetCodeSize()) { - LOG(ERROR, DEBUGGER) << "SetBreakpoint: Invalid breakpoint location"; + LOG_DEBUGGER(ERROR) << "SetBreakpoint: Invalid breakpoint location"; return false; } @@ -42,7 +42,7 @@ bool JSDebugger::SetBreakpoint(const JSPtLocation &location, const Local(ecmaVm_, condFuncRef)); if (!success) { // also return true - LOG(WARNING, DEBUGGER) << "SetBreakpoint: Breakpoint already exists"; + LOG_DEBUGGER(WARN) << "SetBreakpoint: Breakpoint already exists"; } return true; @@ -52,12 +52,12 @@ bool JSDebugger::RemoveBreakpoint(const JSPtLocation &location) { JSMethod *method = FindMethod(location); if (method == nullptr) { - LOG(ERROR, DEBUGGER) << "RemoveBreakpoint: Cannot find JSMethod"; + LOG_DEBUGGER(ERROR) << "RemoveBreakpoint: Cannot find JSMethod"; return false; } if (!RemoveBreakpoint(method, location.GetBytecodeOffset())) { - LOG(ERROR, DEBUGGER) << "RemoveBreakpoint: Breakpoint not found"; + LOG_DEBUGGER(ERROR) << "RemoveBreakpoint: Breakpoint not found"; return false; } @@ -86,18 +86,18 @@ bool JSDebugger::HandleBreakpoint(const JSMethod *method, uint32_t bcOffset) JSThread *thread = ecmaVm_->GetJSThread(); auto condFuncRef = breakpoint.value().GetConditionFunction(); if (condFuncRef->IsFunction()) { - LOG(INFO, DEBUGGER) << "HandleBreakpoint: begin evaluate condition"; + LOG_DEBUGGER(INFO) << "HandleBreakpoint: begin evaluate condition"; auto handlerPtr = std::make_shared(ecmaVm_->GetJSThread()); auto res = DebuggerApi::EvaluateViaFuncCall(const_cast(ecmaVm_), condFuncRef.ToLocal(ecmaVm_), handlerPtr); if (thread->HasPendingException()) { - LOG(ERROR, DEBUGGER) << "HandleBreakpoint: has pending exception"; + LOG_DEBUGGER(ERROR) << "HandleBreakpoint: has pending exception"; thread->ClearException(); return false; } bool isMeet = res->ToBoolean(ecmaVm_)->Value(); if (!isMeet) { - LOG(ERROR, DEBUGGER) << "HandleBreakpoint: condition not meet"; + LOG_DEBUGGER(ERROR) << "HandleBreakpoint: condition not meet"; return false; } } diff --git a/ecmascript/tooling/backend/js_debugger.h b/ecmascript/tooling/backend/js_debugger.h index dbda46cfd2bbc78ff02817656b01e97dbb45f71d..56663a13b18959065c933c3b05f03dd9fbae1232 100644 --- a/ecmascript/tooling/backend/js_debugger.h +++ b/ecmascript/tooling/backend/js_debugger.h @@ -92,7 +92,7 @@ public: hooks_ = nullptr; } - bool SetBreakpoint(const JSPtLocation &location, const Local &condFuncRef) override; + bool SetBreakpoint(const JSPtLocation &location, Local condFuncRef) override; bool RemoveBreakpoint(const JSPtLocation &location) override; void BytecodePcChanged(JSThread *thread, JSMethod *method, uint32_t bcOffset) override; void LoadModule(std::string_view filename) override diff --git a/ecmascript/tooling/backend/js_debugger_interface.h b/ecmascript/tooling/backend/js_debugger_interface.h index 1afebdc4cdbd007a23f9394eae3eef0a55734954..08f7943d944ebe18f83d406902f4a0ba5238e99c 100644 --- a/ecmascript/tooling/backend/js_debugger_interface.h +++ b/ecmascript/tooling/backend/js_debugger_interface.h @@ -112,7 +112,7 @@ public: * @param condition Optional condition * @return Error if any errors occur */ - virtual bool SetBreakpoint(const JSPtLocation &location, const Local &condFuncRef) = 0; + virtual bool SetBreakpoint(const JSPtLocation &location, Local condFuncRef) = 0; /** * \brief Remove breakpoint from \param location diff --git a/ecmascript/tooling/backend/js_pt_hooks.cpp b/ecmascript/tooling/backend/js_pt_hooks.cpp index f3af915594be023707c8b46ae9a9ab97acc20b76..1656023e12add327ec5412bc7dd464f2e897d33c 100644 --- a/ecmascript/tooling/backend/js_pt_hooks.cpp +++ b/ecmascript/tooling/backend/js_pt_hooks.cpp @@ -13,13 +13,14 @@ * limitations under the License. */ -#include "ecmascript/tooling/agent/debugger_impl.h" #include "ecmascript/tooling/backend/js_pt_hooks.h" +#include "ecmascript/tooling/agent/debugger_impl.h" + namespace panda::ecmascript::tooling { void JSPtHooks::Breakpoint(const JSPtLocation &location) { - LOG(DEBUG, DEBUGGER) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": " + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Breakpoint => " << location.GetMethodId() << ": " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -28,7 +29,7 @@ void JSPtHooks::Breakpoint(const JSPtLocation &location) void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location) { - LOG(DEBUG, DEBUGGER) << "JSPtHooks: Exception"; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: Exception"; [[maybe_unused]] LocalScope scope(debugger_->vm_); debugger_->NotifyPaused({}, EXCEPTION); @@ -36,7 +37,7 @@ void JSPtHooks::Exception([[maybe_unused]] const JSPtLocation &location) bool JSPtHooks::SingleStep(const JSPtLocation &location) { - LOG(DEBUG, DEBUGGER) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: SingleStep => " << location.GetBytecodeOffset(); [[maybe_unused]] LocalScope scope(debugger_->vm_); if (UNLIKELY(firstTime_)) { @@ -51,12 +52,16 @@ bool JSPtHooks::SingleStep(const JSPtLocation &location) debugger_->NotifyPaused({}, OTHER); return true; } + + // temporary "safepoint" to handle possible protocol command + debugger_->NotifyHandleProtocolCommand(); + return false; } void JSPtHooks::LoadModule(std::string_view pandaFileName) { - LOG(INFO, DEBUGGER) << "JSPtHooks: LoadModule: " << pandaFileName; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: LoadModule: " << pandaFileName; [[maybe_unused]] LocalScope scope(debugger_->vm_); @@ -68,7 +73,7 @@ void JSPtHooks::LoadModule(std::string_view pandaFileName) void JSPtHooks::PendingJobEntry() { - LOG(DEBUG, DEBUGGER) << "JSPtHooks: PendingJobEntry"; + LOG_DEBUGGER(VERBOSE) << "JSPtHooks: PendingJobEntry"; [[maybe_unused]] LocalScope scope(debugger_->vm_); diff --git a/ecmascript/tooling/backend/js_pt_location.h b/ecmascript/tooling/backend/js_pt_location.h index b5e6207d902e7aea3932419eb4aa4f0b8c6d7d60..434372fa5296b3eb915cd50638487a9a42228499 100644 --- a/ecmascript/tooling/backend/js_pt_location.h +++ b/ecmascript/tooling/backend/js_pt_location.h @@ -18,7 +18,7 @@ #include -#include "libpandafile/file_items.h" +#include "libpandafile/file.h" #include "libpandabase/macros.h" namespace panda::ecmascript::tooling { diff --git a/ecmascript/tooling/base/pt_events.cpp b/ecmascript/tooling/base/pt_events.cpp index e22aa306d7fa18e5af1ace375aaf030cc38362fa..939ebdd3b6ff3388af8df8e2682235a91d690861 100644 --- a/ecmascript/tooling/base/pt_events.cpp +++ b/ecmascript/tooling/base/pt_events.cpp @@ -16,30 +16,11 @@ #include "ecmascript/tooling/base/pt_events.h" namespace panda::ecmascript::tooling { -Local BreakpointResolved::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId")), - Local(StringRef::NewFromUtf8(ecmaVm, breakpointId_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "location")), - Local(location_->ToObject(ecmaVm))); - - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); - - return object; -} - std::unique_ptr BreakpointResolved::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("breakpointId", breakpointId_.c_str()); + ASSERT(location_ != nullptr); result->Add("location", location_->ToJson()); std::unique_ptr object = PtJson::CreateObject(); @@ -49,365 +30,310 @@ std::unique_ptr BreakpointResolved::ToJson() const return object; } -Local Paused::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr Paused::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + std::unique_ptr array = PtJson::CreateArray(); size_t len = callFrames_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local callFrame = callFrames_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, callFrame); + ASSERT(callFrames_[i] != nullptr); + array->Push(callFrames_[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrames")), values); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "reason")), - Local(StringRef::NewFromUtf8(ecmaVm, reason_.c_str()))); + result->Add("callFrames", array); + result->Add("reason", reason_.c_str()); if (data_) { - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "data")), - Local(data_.value()->ToObject(ecmaVm))); + ASSERT(data_.value() != nullptr); + result->Add("data", data_.value()->ToJson()); } if (hitBreakpoints_) { + std::unique_ptr breakpoints = PtJson::CreateArray(); len = hitBreakpoints_->size(); - values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local id = StringRef::NewFromUtf8(ecmaVm, hitBreakpoints_.value()[i].c_str()); - values->Set(ecmaVm, i, id); + breakpoints->Push(hitBreakpoints_.value()[i].c_str()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "hitBreakpoints")), values); + result->Add("hitBreakpoints", breakpoints); } - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local Resumed::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr Resumed::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local ScriptFailedToParse::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ScriptFailedToParse::ToJson() const { - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "startLine")), - IntegerRef::New(ecmaVm, startLine_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "startColumn")), - IntegerRef::New(ecmaVm, startColumn_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endLine")), - IntegerRef::New(ecmaVm, endLine_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endColumn")), - IntegerRef::New(ecmaVm, endColumn_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextId")), - IntegerRef::New(ecmaVm, executionContextId_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "hash")), - Local(StringRef::NewFromUtf8(ecmaVm, hash_.c_str()))); - if (execContextAuxData_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextAuxData")), - Local(execContextAuxData_.value())); - } + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptId", std::to_string(scriptId_).c_str()); + result->Add("url", url_.c_str()); + result->Add("startLine", startLine_); + result->Add("startColumn", startColumn_); + result->Add("endLine", endLine_); + result->Add("endColumn", endColumn_); + result->Add("executionContextId", executionContextId_); + result->Add("hash", hash_.c_str()); if (sourceMapUrl_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "sourceMapURL")), - Local(StringRef::NewFromUtf8(ecmaVm, sourceMapUrl_->c_str()))); + result->Add("sourceMapURL", sourceMapUrl_->c_str()); } if (hasSourceUrl_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "hasSourceURL")), - BooleanRef::New(ecmaVm, hasSourceUrl_.value())); + result->Add("hasSourceURL", hasSourceUrl_.value()); } if (isModule_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "isModule")), - BooleanRef::New(ecmaVm, isModule_.value())); + result->Add("isModule", isModule_.value()); } if (length_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "length")), - IntegerRef::New(ecmaVm, length_.value())); + result->Add("length", length_.value()); } if (codeOffset_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "codeOffset")), - IntegerRef::New(ecmaVm, codeOffset_.value())); + result->Add("codeOffset", codeOffset_.value()); } if (scriptLanguage_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptLanguage")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptLanguage_->c_str()))); + result->Add("scriptLanguage", scriptLanguage_->c_str()); } if (embedderName_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "embedderName")), - Local(StringRef::NewFromUtf8(ecmaVm, embedderName_->c_str()))); + result->Add("embedderName", embedderName_->c_str()); } - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local ScriptParsed::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ScriptParsed::ToJson() const { - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "startLine")), - IntegerRef::New(ecmaVm, startLine_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "startColumn")), - IntegerRef::New(ecmaVm, startColumn_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endLine")), - IntegerRef::New(ecmaVm, endLine_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endColumn")), - IntegerRef::New(ecmaVm, endColumn_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextId")), - IntegerRef::New(ecmaVm, executionContextId_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "hash")), - Local(StringRef::NewFromUtf8(ecmaVm, hash_.c_str()))); - if (execContextAuxData_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextAuxData")), - Local(execContextAuxData_.value())); - } + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptId", std::to_string(scriptId_).c_str()); + result->Add("url", url_.c_str()); + result->Add("startLine", startLine_); + result->Add("startColumn", startColumn_); + result->Add("endLine", endLine_); + result->Add("endColumn", endColumn_); + result->Add("executionContextId", executionContextId_); + result->Add("hash", hash_.c_str()); if (isLiveEdit_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "isLiveEdit")), - BooleanRef::New(ecmaVm, isLiveEdit_.value())); + result->Add("isLiveEdit", isLiveEdit_.value()); } if (sourceMapUrl_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "sourceMapURL")), - Local(StringRef::NewFromUtf8(ecmaVm, sourceMapUrl_->c_str()))); + result->Add("sourceMapURL", sourceMapUrl_->c_str()); } if (hasSourceUrl_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "hasSourceURL")), - BooleanRef::New(ecmaVm, hasSourceUrl_.value())); + result->Add("hasSourceURL", hasSourceUrl_.value()); } if (isModule_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "isModule")), - BooleanRef::New(ecmaVm, isModule_.value())); + result->Add("isModule", isModule_.value()); } if (length_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "length")), - IntegerRef::New(ecmaVm, length_.value())); + result->Add("length", length_.value()); } if (codeOffset_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "codeOffset")), - IntegerRef::New(ecmaVm, codeOffset_.value())); + result->Add("codeOffset", codeOffset_.value()); } if (scriptLanguage_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptLanguage")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptLanguage_->c_str()))); + result->Add("scriptLanguage", scriptLanguage_->c_str()); } if (embedderName_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "embedderName")), - Local(StringRef::NewFromUtf8(ecmaVm, embedderName_->c_str()))); + result->Add("embedderName", embedderName_->c_str()); } - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local AddHeapSnapshotChunk::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr AddHeapSnapshotChunk::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "chunk")), - Local(StringRef::NewFromUtf8(ecmaVm, chunk_.c_str()))); + result->Add("chunk", chunk_.c_str()); - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local ConsoleProfileFinished::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ConsoleProfileFinished::ToJson() const { - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "id")), - Local(StringRef::NewFromUtf8(ecmaVm, id_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "location")), - Local(location_->ToObject(ecmaVm))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "profile")), - Local(profile_->ToObject(ecmaVm))); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("id", id_.c_str()); + ASSERT(location_ != nullptr); + result->Add("location", location_->ToJson()); + ASSERT(profile_ != nullptr); + result->Add("profile", profile_->ToJson()); if (title_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "title")), - Local(StringRef::NewFromUtf8(ecmaVm, title_->c_str()))); + result->Add("title", title_->c_str()); } - - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local ConsoleProfileStarted::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ConsoleProfileStarted::ToJson() const { - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "id")), - Local(StringRef::NewFromUtf8(ecmaVm, id_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "location")), - Local(location_->ToObject(ecmaVm))); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("id", id_.c_str()); + ASSERT(location_ != nullptr); + result->Add("location", location_->ToJson()); if (title_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "title")), - Local(StringRef::NewFromUtf8(ecmaVm, title_->c_str()))); + result->Add("title", title_->c_str()); } - - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local PreciseCoverageDeltaUpdate::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr PreciseCoverageDeltaUpdate::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timestamp")), - NumberRef::New(ecmaVm, timestamp_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "occasion")), - Local(StringRef::NewFromUtf8(ecmaVm, occasion_.c_str()))); + result->Add("timestamp", timestamp_); + result->Add("occasion", occasion_.c_str()); + std::unique_ptr array = PtJson::CreateArray(); size_t len = result_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local result = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, result); + ASSERT(result_[i] != nullptr); + std::unique_ptr res = result_[i]->ToJson(); + array->Push(res); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); - - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + result->Add("result", array); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local HeapStatsUpdate::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr HeapStatsUpdate::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + std::unique_ptr array = PtJson::CreateArray(); size_t len = statsUpdate_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local elem = IntegerRef::New(ecmaVm, statsUpdate_[i]); - values->Set(ecmaVm, i, elem); + array->Push(statsUpdate_[i]); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "statsUpdate")), values); - - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + result->Add("statsUpdate", array); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local LastSeenObjectId::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr LastSeenObjectId::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lastSeenObjectId")), - IntegerRef::New(ecmaVm, lastSeenObjectId_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timestamp")), - NumberRef::New(ecmaVm, timestamp_)); + result->Add("lastSeenObjectId", lastSeenObjectId_); + result->Add("timestamp", timestamp_); - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } -Local ReportHeapSnapshotProgress::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ReportHeapSnapshotProgress::ToJson() const { - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "done")), - IntegerRef::New(ecmaVm, done_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "total")), - IntegerRef::New(ecmaVm, total_)); + std::unique_ptr result = PtJson::CreateObject(); + result->Add("done", done_); + result->Add("total", total_); if (finished_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "finished")), - BooleanRef::New(ecmaVm, finished_.value())); + result->Add("finished", finished_.value()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + +std::unique_ptr BufferUsage::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + if (percentFull_) { + result->Add("percentFull", percentFull_.value()); + } + if (eventCount_) { + result->Add("eventCount", eventCount_.value()); + } + if (value_) { + result->Add("value", value_.value()); + } + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + +std::unique_ptr DataCollected::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); + size_t len = value_.size(); + for (size_t i = 0; i < len; i++) { + array->Push(value_[i]); + } + result->Add("value", array); + + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); + + return object; +} + +std::unique_ptr TracingComplete::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("dataLossOccurred", dataLossOccurred_); + if (traceFormat_) { + result->Add("traceFormat", traceFormat_.value()->c_str()); + } + if (streamCompression_) { + result->Add("streamCompression", streamCompression_.value()->c_str()); } - Local object = NewObject(ecmaVm); - object->Set(ecmaVm, - StringRef::NewFromUtf8(ecmaVm, "method"), - Local(StringRef::NewFromUtf8(ecmaVm, GetName().c_str()))); - object->Set(ecmaVm, StringRef::NewFromUtf8(ecmaVm, "params"), Local(params)); + std::unique_ptr object = PtJson::CreateObject(); + object->Add("method", GetName().c_str()); + object->Add("params", result); return object; } diff --git a/ecmascript/tooling/base/pt_events.h b/ecmascript/tooling/base/pt_events.h index 5044ff8759a77dae0f15b03be8d56f26c787ba29..05b140b4a1acd63feef0ad1a9cb035782905f828 100644 --- a/ecmascript/tooling/base/pt_events.h +++ b/ecmascript/tooling/base/pt_events.h @@ -29,7 +29,6 @@ class PtBaseEvents : public PtBaseTypes { public: PtBaseEvents() = default; ~PtBaseEvents() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override = 0; virtual std::string GetName() const = 0; private: @@ -41,7 +40,6 @@ class BreakpointResolved final : public PtBaseEvents { public: BreakpointResolved() = default; ~BreakpointResolved() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; std::string GetName() const override @@ -83,7 +81,7 @@ class Paused final : public PtBaseEvents { public: Paused() = default; ~Paused() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -152,7 +150,7 @@ public: return "Break on start"; } default: { - LOG(ERROR, DEBUGGER) << "Unknown paused reason: " << reason; + LOG_DEBUGGER(ERROR) << "Unknown paused reason: " << reason; } } return ""; @@ -207,7 +205,7 @@ class Resumed final : public PtBaseEvents { public: Resumed() = default; ~Resumed() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -223,7 +221,7 @@ class ScriptFailedToParse final : public PtBaseEvents { public: ScriptFailedToParse() = default; ~ScriptFailedToParse() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -323,7 +321,7 @@ public: return execContextAuxData_.value_or(Local()); } - ScriptFailedToParse &SetExecutionContextAuxData(const Local &execContextAuxData) + ScriptFailedToParse &SetExecutionContextAuxData(Local execContextAuxData) { execContextAuxData_ = execContextAuxData; return *this; @@ -453,7 +451,7 @@ private: NO_COPY_SEMANTIC(ScriptFailedToParse); NO_MOVE_SEMANTIC(ScriptFailedToParse); - ScriptId scriptId_ {}; + ScriptId scriptId_ {0}; std::string url_ {}; int32_t startLine_ {0}; int32_t startColumn_ {0}; @@ -475,7 +473,7 @@ class ScriptParsed final : public PtBaseEvents { public: ScriptParsed() = default; ~ScriptParsed() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -591,7 +589,7 @@ public: return execContextAuxData_.value_or(Local()); } - ScriptParsed &SetExecutionContextAuxData(const Local &execContextAuxData) + ScriptParsed &SetExecutionContextAuxData(Local execContextAuxData) { execContextAuxData_ = execContextAuxData; return *this; @@ -651,12 +649,12 @@ public: return isModule_.has_value(); } - uint32_t GetLength() const + int32_t GetLength() const { return length_.value_or(0); } - ScriptParsed &SetLength(uint32_t length) + ScriptParsed &SetLength(int32_t length) { length_ = length; return *this; @@ -667,12 +665,12 @@ public: return length_.has_value(); } - uint32_t GetCodeOffset() const + int32_t GetCodeOffset() const { return codeOffset_.value_or(0); } - ScriptParsed &SetCodeOffset(uint32_t codeOffset) + ScriptParsed &SetCodeOffset(int32_t codeOffset) { codeOffset_ = codeOffset; return *this; @@ -721,7 +719,7 @@ private: NO_COPY_SEMANTIC(ScriptParsed); NO_MOVE_SEMANTIC(ScriptParsed); - ScriptId scriptId_ {}; + ScriptId scriptId_ {0}; std::string url_ {}; int32_t startLine_ {0}; int32_t startColumn_ {0}; @@ -734,8 +732,8 @@ private: std::optional sourceMapUrl_ {}; std::optional hasSourceUrl_ {}; std::optional isModule_ {}; - std::optional length_ {}; - std::optional codeOffset_ {}; + std::optional length_ {}; + std::optional codeOffset_ {}; std::optional scriptLanguage_ {}; std::optional embedderName_ {}; }; @@ -744,7 +742,7 @@ class AddHeapSnapshotChunk final : public PtBaseEvents { public: AddHeapSnapshotChunk() = default; ~AddHeapSnapshotChunk() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -767,7 +765,7 @@ class ConsoleProfileFinished final : public PtBaseEvents { public: ConsoleProfileFinished() = default; ~ConsoleProfileFinished() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "Profile.ConsoleProfileFinished"; @@ -837,7 +835,7 @@ class ConsoleProfileStarted final : public PtBaseEvents { public: ConsoleProfileStarted() = default; ~ConsoleProfileStarted() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "Profile.ConsoleProfileStarted"; @@ -895,7 +893,7 @@ class PreciseCoverageDeltaUpdate final : public PtBaseEvents { public: PreciseCoverageDeltaUpdate() = default; ~PreciseCoverageDeltaUpdate() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "Profile.PreciseCoverageDeltaUpdate"; @@ -947,19 +945,19 @@ class HeapStatsUpdate final : public PtBaseEvents { public: HeapStatsUpdate() = default; ~HeapStatsUpdate() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { return "HeapProfiler.heapStatsUpdate"; } - const std::vector *GetStatsUpdate() const + const std::vector *GetStatsUpdate() const { return &statsUpdate_; } - HeapStatsUpdate &SetStatsUpdate(std::vector statsUpdate) + HeapStatsUpdate &SetStatsUpdate(std::vector statsUpdate) { statsUpdate_ = std::move(statsUpdate); return *this; @@ -969,14 +967,14 @@ private: NO_COPY_SEMANTIC(HeapStatsUpdate); NO_MOVE_SEMANTIC(HeapStatsUpdate); - std::vector statsUpdate_ {}; + std::vector statsUpdate_ {}; }; class LastSeenObjectId final : public PtBaseEvents { public: LastSeenObjectId() = default; ~LastSeenObjectId() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -988,18 +986,18 @@ public: return lastSeenObjectId_; } - LastSeenObjectId &SetLastSeenObjectId(uint32_t lastSeenObjectId) + LastSeenObjectId &SetLastSeenObjectId(int32_t lastSeenObjectId) { lastSeenObjectId_ = lastSeenObjectId; return *this; } - int64_t GetTimestamp() const + double GetTimestamp() const { return timestamp_; } - LastSeenObjectId &SetTimestamp(int64_t timestamp) + LastSeenObjectId &SetTimestamp(double timestamp) { timestamp_ = timestamp; return *this; @@ -1009,15 +1007,15 @@ private: NO_COPY_SEMANTIC(LastSeenObjectId); NO_MOVE_SEMANTIC(LastSeenObjectId); - uint32_t lastSeenObjectId_ {}; - int64_t timestamp_ {}; + int32_t lastSeenObjectId_ {}; + double timestamp_ {}; }; class ReportHeapSnapshotProgress final : public PtBaseEvents { public: ReportHeapSnapshotProgress() = default; ~ReportHeapSnapshotProgress() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; std::string GetName() const override { @@ -1065,5 +1063,174 @@ private: int32_t total_ {}; std::optional finished_ {}; }; + +class BufferUsage final : public PtBaseEvents { +public: + BufferUsage() = default; + ~BufferUsage() override = default; + std::unique_ptr ToJson() const override; + + std::string GetName() const override + { + return "Tracing.BufferUsage"; + } + + int32_t GetPercentFull() const + { + return percentFull_.value(); + } + + BufferUsage &SetPercentFull(int32_t percentFull) + { + percentFull_ = percentFull; + return *this; + } + + bool HasPercentFull() const + { + return percentFull_.has_value(); + } + + int32_t GetEventCount() const + { + return eventCount_.value(); + } + + BufferUsage &SetEventCount(int32_t eventCount) + { + eventCount_ = eventCount; + return *this; + } + + bool HasEventCount() const + { + return eventCount_.has_value(); + } + + int32_t GetValue() const + { + return value_.value(); + } + + BufferUsage &SetValue(int32_t value) + { + value_ = value; + return *this; + } + + bool HasValue() const + { + return value_.has_value(); + } + +private: + NO_COPY_SEMANTIC(BufferUsage); + NO_MOVE_SEMANTIC(BufferUsage); + + std::optional percentFull_ {0}; + std::optional eventCount_ {0}; + std::optional value_ {0}; +}; + +class DataCollected final : public PtBaseEvents { +public: + DataCollected() = default; + ~DataCollected() override = default; + std::unique_ptr ToJson() const override; + + std::string GetName() const override + { + return "Tracing.DataCollected"; + } + + const std::vector> *GetValue() const + { + return &value_; + } + + DataCollected &SetValue(std::vector> value) + { + value_ = std::move(value); + return *this; + } + +private: + NO_COPY_SEMANTIC(DataCollected); + NO_MOVE_SEMANTIC(DataCollected); + + std::vector> value_ {}; +}; + +class TracingComplete final : public PtBaseEvents { +public: + TracingComplete() = default; + ~TracingComplete() override = default; + std::unique_ptr ToJson() const override; + + std::string GetName() const override + { + return "Tracing.TracingComplete"; + } + + bool GetDataLossOccurred() const + { + return dataLossOccurred_; + } + + TracingComplete &SetDataLossOccurred(bool dataLossOccurred) + { + dataLossOccurred_ = dataLossOccurred; + return *this; + } + + StreamFormat *GetTraceFormat() const + { + if (traceFormat_) { + return traceFormat_->get(); + } + return nullptr; + } + + TracingComplete &SetTraceFormat(std::unique_ptr traceFormat) + { + traceFormat_ = std::move(traceFormat); + return *this; + } + + bool HasTraceFormat() const + { + return traceFormat_.has_value(); + } + + StreamCompression *GetStreamCompression() const + { + if (streamCompression_) { + return streamCompression_->get(); + } + return nullptr; + } + + TracingComplete &SetStreamCompression(std::unique_ptr streamCompression) + { + streamCompression_ = std::move(streamCompression); + return *this; + } + + bool HasStreamCompression() const + { + return streamCompression_.has_value(); + } + +private: + NO_COPY_SEMANTIC(TracingComplete); + NO_MOVE_SEMANTIC(TracingComplete); + + bool dataLossOccurred_ {}; + /* + * { TracingComplete.stream } IO is currently not supported; + */ + std::optional> traceFormat_ {}; + std::optional> streamCompression_ {}; +}; } // namespace panda::ecmascript::tooling #endif diff --git a/ecmascript/tooling/base/pt_json.cpp b/ecmascript/tooling/base/pt_json.cpp index 967206a927b1b5d6404279cd5b543967fcba6ba0..2943e98b2b65a797e1783f7c3c853b13fc1d9ce8 100644 --- a/ecmascript/tooling/base/pt_json.cpp +++ b/ecmascript/tooling/base/pt_json.cpp @@ -418,4 +418,15 @@ Result PtJson::GetArray(const char *key, std::unique_ptr *value) const *value = std::make_unique(item); return Result::SUCCESS; } + +Result PtJson::GetAny(const char *key, std::unique_ptr *value) const +{ + cJSON *item = cJSON_GetObjectItem(object_, key); + if (item == nullptr) { + return Result::NOT_EXIST; + } + + *value = std::make_unique(item); + return Result::SUCCESS; +} } // namespace panda::ecmascript diff --git a/ecmascript/tooling/base/pt_json.h b/ecmascript/tooling/base/pt_json.h index d38eb3cd97b7585cb8099d4836855f3b966d3b07..88f6cc15f19749e4fb7c8b7c084effa11aa964ad 100644 --- a/ecmascript/tooling/base/pt_json.h +++ b/ecmascript/tooling/base/pt_json.h @@ -99,6 +99,7 @@ public: Result GetString(const char *key, std::string *value) const; Result GetObject(const char *key, std::unique_ptr *value) const; Result GetArray(const char *key, std::unique_ptr *value) const; + Result GetAny(const char *key, std::unique_ptr *value) const; private: cJSON *object_ = nullptr; diff --git a/ecmascript/tooling/base/pt_params.cpp b/ecmascript/tooling/base/pt_params.cpp index 2118cc126e4bfc1e7b017db637f2135e26b555bd..64bda897aba7bc6489d64d41954d72975bbddbbd 100644 --- a/ecmascript/tooling/base/pt_params.cpp +++ b/ecmascript/tooling/base/pt_params.cpp @@ -16,1015 +16,929 @@ #include "ecmascript/tooling/base/pt_params.h" namespace panda::ecmascript::tooling { -std::unique_ptr EnableParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "EnableParams::Create params is nullptr"; - return nullptr; - } - std::string error; - auto paramsObject = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "maxScriptsCacheSize"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->maxScriptsCacheSize_ = Local(result)->Value(); - } else { - error += "'maxScriptsCacheSize' should be a Number;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "EnableParams::Create " << error; - return nullptr; - } - - return paramsObject; -} - std::unique_ptr EnableParams::Create(const PtJson ¶ms) { auto paramsObject = std::make_unique(); std::string error; Result ret; - double result; - ret = params.GetDouble("maxScriptsCacheSize", &result); + double maxScriptsCacheSize; + ret = params.GetDouble("maxScriptsCacheSize", &maxScriptsCacheSize); if (ret == Result::SUCCESS) { - paramsObject->maxScriptsCacheSize_ = result; + paramsObject->maxScriptsCacheSize_ = maxScriptsCacheSize; } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'maxScriptsCacheSize';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "EnableParams::Create " << error; + LOG_DEBUGGER(ERROR) << "EnableParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr EvaluateOnCallFrameParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr EvaluateOnCallFrameParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "EvaluateOnCallFrameParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->callFrameId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'callframeid' should be a String;"; - } + std::string callFrameId; + ret = params.GetString("callFrameId", &callFrameId); + if (ret == Result::SUCCESS) { + paramsObject->callFrameId_ = std::stoi(callFrameId); } else { - error += "should contain 'callframeid';"; + error += "Unknown 'callFrameId';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "expression"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->expression_ = DebuggerApi::ToStdString(result); - } else { - error += "'expression' should be a String;"; - } + std::string expression; + ret = params.GetString("expression", &expression); + if (ret == Result::SUCCESS) { + paramsObject->expression_ = std::move(expression); } else { - error += "should contain 'expression';"; + error += "Unknown 'expression';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); - if (!result.IsEmpty() && result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ToStdString(result); + std::string objectGroup; + ret = params.GetString("objectGroup", &objectGroup); + if (ret == Result::SUCCESS) { + paramsObject->objectGroup_ = std::move(objectGroup); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectGroup';"; } - - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "includeCommandLineAPI"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->includeCommandLineApi_ = result->IsTrue(); + bool includeCommandLineAPI; + ret = params.GetBool("includeCommandLineAPI", &includeCommandLineAPI); + if (ret == Result::SUCCESS) { + paramsObject->includeCommandLineAPI_ = includeCommandLineAPI; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'includeCommandLineAPI';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "silent"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->silent_ = result->IsTrue(); + bool silent; + ret = params.GetBool("silent", &silent); + if (ret == Result::SUCCESS) { + paramsObject->silent_ = silent; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'silent';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "returnByValue"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->returnByValue_ = result->IsTrue(); + bool returnByValue; + ret = params.GetBool("returnByValue", &returnByValue); + if (ret == Result::SUCCESS) { + paramsObject->returnByValue_ = returnByValue; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'returnByValue';"; } - - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "generatePreview"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->generatePreview_ = result->IsTrue(); + bool generatePreview; + ret = params.GetBool("generatePreview", &generatePreview); + if (ret == Result::SUCCESS) { + paramsObject->generatePreview_ = generatePreview; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'generatePreview';"; } - - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "throwOnSideEffect"))); - if (!result.IsEmpty() && result->IsBoolean()) { - paramsObject->throwOnSideEffect_ = result->IsTrue(); + bool throwOnSideEffect; + ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect); + if (ret == Result::SUCCESS) { + paramsObject->throwOnSideEffect_ = throwOnSideEffect; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'throwOnSideEffect';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "EvaluateOnCallFrameParams::Create " << error; + LOG_DEBUGGER(ERROR) << "EvaluateOnCallFrameParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr GetPossibleBreakpointsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetPossibleBreakpointsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "start"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'start' format error;"; - } else { - paramsObject->start_ = std::move(obj); - } + std::unique_ptr start; + ret = params.GetObject("start", &start); + if (ret == Result::SUCCESS) { + std::unique_ptr location = Location::Create(*start); + if (location == nullptr) { + error += "Unknown 'start';"; } else { - error += "'start' should be an Object;"; + paramsObject->start_ = std::move(location); } } else { - error += "should contain 'start';"; + error += "Unknown 'start';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "end"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'end' format error;"; - } else { - paramsObject->end_ = std::move(obj); - } + std::unique_ptr end; + ret = params.GetObject("start", &end); + if (ret == Result::SUCCESS) { + std::unique_ptr location = Location::Create(*end); + if (location == nullptr) { + error += "Unknown 'end';"; } else { - error += "'end' should be an Object;"; + paramsObject->end_ = std::move(location); } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'end';"; } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "restrictToFunction"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->restrictToFunction_ = result->IsTrue(); - } else { - error += "'restrictToFunction' should be a Boolean;"; - } + bool restrictToFunction; + ret = params.GetBool("restrictToFunction", &restrictToFunction); + if (ret == Result::SUCCESS) { + paramsObject->restrictToFunction_ = restrictToFunction; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'restrictToFunction';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "GetPossibleBreakpointsParams::Create " << error; + LOG_DEBUGGER(ERROR) << "GetPossibleBreakpointsParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr GetScriptSourceParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetScriptSourceParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->scriptId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'scriptId' should be a String;"; - } + std::string scriptId; + ret = params.GetString("scriptId", &scriptId); + if (ret == Result::SUCCESS) { + paramsObject->scriptId_ = std::stoi(scriptId); } else { - error += "should contain 'scriptId';"; + error += "Unknown 'scriptId';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "GetScriptSourceParams::Create " << error; + LOG_DEBUGGER(ERROR) << "GetScriptSourceParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr RemoveBreakpointParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr RemoveBreakpointParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->breakpointId_ = DebuggerApi::ToStdString(result); - } else { - error += "'breakpointId' should be a String;"; - } + std::string breakpointId; + ret = params.GetString("breakpointId", &breakpointId); + if (ret == Result::SUCCESS) { + paramsObject->breakpointId_ = std::move(breakpointId); } else { - error += "should contain 'breakpointId';"; + error += "Unknown 'breakpointId';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "RemoveBreakpointParams::Create " << error; + LOG_DEBUGGER(ERROR) << "RemoveBreakpointParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr ResumeParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr ResumeParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "terminateOnResume"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->terminateOnResume_ = result->IsTrue(); - } else { - error += "'terminateOnResume' should be a Boolean;"; - } + bool terminateOnResume; + ret = params.GetBool("terminateOnResume", &terminateOnResume); + if (ret == Result::SUCCESS) { + paramsObject->terminateOnResume_ = terminateOnResume; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'terminateOnResume';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ResumeParams::Create " << error; + LOG_DEBUGGER(ERROR) << "ResumeParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr SetAsyncCallStackDepthParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetAsyncCallStackDepthParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "maxDepth"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->maxDepth_ = static_cast(Local(result)->Value()); - } else { - error += "'maxDepth' should be a Number;"; - } + int32_t maxDepth; + ret = params.GetInt("maxDepth", &maxDepth); + if (ret == Result::SUCCESS) { + paramsObject->maxDepth_ = maxDepth; } else { - error += "should contain 'maxDepth';"; + error += "Unknown 'maxDepth';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SetAsyncCallStackDepthParams::Create " << error; + LOG_DEBUGGER(ERROR) << "SetAsyncCallStackDepthParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr SetBlackboxPatternsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetBlackboxPatternsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "patterns"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsString()) { - paramsObject->patterns_.emplace_back( - DebuggerApi::ToStdString(value)); - } else { - error += "'patterns' items should be a String;"; - } + std::unique_ptr patterns; + ret = params.GetArray("patterns", &patterns); + if (ret == Result::SUCCESS) { + int32_t len = patterns->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr item = patterns->Get(i); + if (item->IsString()) { + paramsObject->patterns_.emplace_back(item->GetString()); + } else { + error += "'patterns' items should be a String;"; } - } else { - error += "'patterns' should be an Array;"; } } else { - error += "should contain 'patterns';"; + error += "Unknown 'patterns';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SetBlackboxPatternsParams::Create " << error; + LOG_DEBUGGER(ERROR) << "SetBlackboxPatternsParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr SetBreakpointByUrlParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetBreakpointByUrlParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); + if (ret == Result::SUCCESS) { + paramsObject->lineNumber_ = lineNumber; } else { - error += "should contain 'lineNumber';"; + error += "Unknown 'lineNumber';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->url_ = DebuggerApi::ToStdString(result); - } else { - error += "'url' should be a String;"; - } + std::string url; + ret = params.GetString("url", &url); + if (ret == Result::SUCCESS) { + paramsObject->url_ = std::move(url); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'url';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "urlRegex"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->urlRegex_ = DebuggerApi::ToStdString(result); - } else { - error += "'urlRegex' should be a String;"; - } + std::string urlRegex; + ret = params.GetString("urlRegex", &urlRegex); + if (ret == Result::SUCCESS) { + paramsObject->urlRegex_ = std::move(urlRegex); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'urlRegex';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptHash"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->scriptHash_ = DebuggerApi::ToStdString(result); - } else { - error += "'scriptHash' should be a String;"; - } + std::string scriptHash; + ret = params.GetString("scriptHash", &scriptHash); + if (ret == Result::SUCCESS) { + paramsObject->scriptHash_ = std::move(scriptHash); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'scriptHash';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); + if (ret == Result::SUCCESS) { + paramsObject->columnNumber_ = columnNumber; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'columnNumber';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "condition"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->condition_ = DebuggerApi::ToStdString(result); - } else { - error += "'condition' should be a String;"; - } + std::string condition; + ret = params.GetString("condition", &condition); + if (ret == Result::SUCCESS) { + paramsObject->condition_ = std::move(condition); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'condition';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SetBreakpointByUrlParams::Create " << error; + LOG_DEBUGGER(ERROR) << "SetBreakpointByUrlParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr SetPauseOnExceptionsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SetPauseOnExceptionsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "state"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - if (!paramsObject->StoreState(DebuggerApi::ToStdString(result))) { - error += "'state' is invalid;"; - } - } else { - error += "'state' should be a String;"; - } + std::string state; + ret = params.GetString("state", &state); + if (ret == Result::SUCCESS) { + paramsObject->StoreState(state); } else { - error += "should contain 'state';"; + error += "Unknown 'state';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SetPauseOnExceptionsParams::Create " << error; + LOG_DEBUGGER(ERROR) << "SetPauseOnExceptionsParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr StepIntoParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr StepIntoParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "breakOnAsyncCall"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->breakOnAsyncCall_ = result->IsTrue(); - } else { - error += "'terminateOnResume' should be a Boolean;"; - } + bool breakOnAsyncCall; + ret = params.GetBool("breakOnAsyncCall", &breakOnAsyncCall); + if (ret == Result::SUCCESS) { + paramsObject->breakOnAsyncCall_ = breakOnAsyncCall; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'breakOnAsyncCall';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "skipList"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsObject()) { - std::unique_ptr obj = LocationRange::Create(ecmaVm, value); - if (obj != nullptr) { - paramsObject->skipList_->emplace_back(std::move(obj)); - } else { - error += "'skipList' items LocationRange is invalid;"; - } - } else { - error += "'skipList' items should be an Object;"; - } + std::unique_ptr skipList; + ret = params.GetArray("skipList", &skipList); + if (ret == Result::SUCCESS) { + int32_t len = skipList->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr obj = LocationRange::Create(*skipList->Get(i)); + if (obj == nullptr) { + error += "'skipList' items LocationRange is invalid;"; + } else { + paramsObject->skipList_->emplace_back(std::move(obj)); } - } else { - error += "'skipList' should be an Array;"; } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'skipList';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "StepIntoParams::Create " << error; + LOG_DEBUGGER(ERROR) << "StepIntoParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr StepOverParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr StepOverParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "skipList"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsObject()) { - std::unique_ptr obj = LocationRange::Create(ecmaVm, value); - if (obj != nullptr) { - paramsObject->skipList_->emplace_back(std::move(obj)); - } else { - error += "'skipList' items LocationRange is invalid;"; - } - } else { - error += "'skipList' items should be an Object;"; - } + std::unique_ptr skipList; + ret = params.GetArray("skipList", &skipList); + if (ret == Result::SUCCESS) { + int32_t len = skipList->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr obj = LocationRange::Create(*skipList->Get(i)); + if (obj == nullptr) { + error += "'skipList' items LocationRange is invalid;"; + } else { + paramsObject->skipList_->emplace_back(std::move(obj)); } - } else { - error += "'skipList' should be an Array;"; } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'skipList';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "StepOverParams::Create " << error; + LOG_DEBUGGER(ERROR) << "StepOverParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr GetPropertiesParams::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr GetPropertiesParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "GetPropertiesParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); } else { - error += "should contain 'objectId';"; + error += "Unknown 'objectId';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ownProperties"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->ownProperties_ = result->IsTrue(); - } else { - error += "'ownProperties' should be a Boolean;"; - } + bool ownProperties; + ret = params.GetBool("ownProperties", &ownProperties); + if (ret == Result::SUCCESS) { + paramsObject->ownProperties_ = ownProperties; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'ownProperties';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "accessorPropertiesOnly"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->accessorPropertiesOnly_ = result->IsTrue(); - } else { - error += "'accessorPropertiesOnly' should be a Boolean;"; - } + bool accessorPropertiesOnly; + ret = params.GetBool("accessorPropertiesOnly", &accessorPropertiesOnly); + if (ret == Result::SUCCESS) { + paramsObject->accessorPropertiesOnly_ = accessorPropertiesOnly; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'accessorPropertiesOnly';"; } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "generatePreview"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->generatePreview_ = result->IsTrue(); - } else { - error += "'generatePreview' should be a Boolean;"; - } + bool generatePreview; + ret = params.GetBool("generatePreview", &generatePreview); + if (ret == Result::SUCCESS) { + paramsObject->generatePreview_ = generatePreview; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'generatePreview';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "GetPropertiesParams::Create " << error; + LOG_DEBUGGER(ERROR) << "GetPropertiesParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr CallFunctionOnParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr CallFunctionOnParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "CallFunctionOnParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; // paramsObject->functionDeclaration_ - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionDeclaration"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->functionDeclaration_ = DebuggerApi::ToStdString(result); - } else { - error += "'functionDeclaration' should be a String;"; - } + std::string functionDeclaration; + ret = params.GetString("functionDeclaration", &functionDeclaration); + if (ret == Result::SUCCESS) { + paramsObject->functionDeclaration_ = std::move(functionDeclaration); } else { - error += "should contain 'functionDeclaration';"; + error += "Unknown 'functionDeclaration';"; } // paramsObject->objectId_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectId';"; } // paramsObject->arguments_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "arguments"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - Local array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; i++) { - key = IntegerRef::New(ecmaVm, i); - Local value = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - if (value->IsObject()) { - std::unique_ptr obj = CallArgument::Create(ecmaVm, value); - if (obj != nullptr) { - paramsObject->arguments_->emplace_back(std::move(obj)); - } else { - error += "'arguments' items CallArgument is invaild;"; - } - } else { - error += "'arguments' items should be an Object;"; - } + std::unique_ptr arguments; + ret = params.GetArray("arguments", &arguments); + if (ret == Result::SUCCESS) { + int32_t len = arguments->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr obj = CallArgument::Create(*arguments->Get(i)); + if (obj == nullptr) { + error += "'arguments' items CallArgument is invaild;"; + } else { + paramsObject->arguments_->emplace_back(std::move(obj)); } - } else { - error += "'arguments' should be an Array;"; } + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'arguments';"; } // paramsObject->silent_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "silent"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->silent_ = result->IsTrue(); - } else { - error += "'silent' should be a Boolean;"; - } + bool silent; + ret = params.GetBool("silent", &silent); + if (ret == Result::SUCCESS) { + paramsObject->silent_ = silent; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'silent';"; } // paramsObject->returnByValue_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "returnByValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->returnByValue_ = result->IsTrue(); - } else { - error += "'returnByValue' should be a Boolean;"; - } + bool returnByValue; + ret = params.GetBool("returnByValue", &returnByValue); + if (ret == Result::SUCCESS) { + paramsObject->returnByValue_ = returnByValue; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'returnByValue';"; } // paramsObject->generatePreview_ - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "generatePreview"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->generatePreview_ = result->IsTrue(); - } else { - error += "'generatePreview' should be a Boolean;"; - } + bool generatePreview; + ret = params.GetBool("generatePreview", &generatePreview); + if (ret == Result::SUCCESS) { + paramsObject->generatePreview_ = generatePreview; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'generatePreview';"; } // paramsObject->userGesture_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "userGesture"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->userGesture_ = result->IsTrue(); - } else { - error += "'userGesture' should be a Boolean;"; - } + bool userGesture; + ret = params.GetBool("userGesture", &userGesture); + if (ret == Result::SUCCESS) { + paramsObject->userGesture_ = userGesture; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'userGesture';"; } // paramsObject->awaitPromise_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "awaitPromise"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->awaitPromise_ = result->IsTrue(); - } else { - error += "'awaitPromise' should be a Boolean;"; - } + bool awaitPromise; + ret = params.GetBool("awaitPromise", &awaitPromise); + if (ret == Result::SUCCESS) { + paramsObject->awaitPromise_ = awaitPromise; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'awaitPromise';"; } // paramsObject->executionContextId_ - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->executionContextId_ = static_cast(Local(result)->Value()); - } else { - error += "'executionContextId' should be a Number;"; - } + int32_t executionContextId; + ret = params.GetInt("executionContextId", &executionContextId); + if (ret == Result::SUCCESS) { + paramsObject->executionContextId_ = executionContextId; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'executionContextId';"; } // paramsObject->objectGroup_ - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ToStdString(result); - } else { - error += "'objectGroup' should be a String;"; - } + std::string objectGroup; + ret = params.GetString("objectGroup", &objectGroup); + if (ret == Result::SUCCESS) { + paramsObject->objectGroup_ = std::move(objectGroup); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectGroup';"; } // paramsObject->throwOnSideEffect_ - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "throwOnSideEffect"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->throwOnSideEffect_ = result->IsTrue(); - } else { - error += "'throwOnSideEffect' should be a Boolean;"; - } + bool throwOnSideEffect; + ret = params.GetBool("throwOnSideEffect", &throwOnSideEffect); + if (ret == Result::SUCCESS) { + paramsObject->throwOnSideEffect_ = throwOnSideEffect; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'throwOnSideEffect';"; } + // Check whether the error is empty. if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "CallFunctionOnParams::Create " << error; + LOG_DEBUGGER(ERROR) << "CallFunctionOnParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr StartSamplingParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StartSamplingParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StartSamplingParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "samplingInterval"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->samplingInterval_ = static_cast(Local(result)->Value()); - } else { - error += "'samplingInterval' should be a Number;"; - } + int32_t samplingInterval; + ret = params.GetInt("samplingInterval", &samplingInterval); + if (ret == Result::SUCCESS) { + paramsObject->samplingInterval_ = samplingInterval; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'samplingInterval';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "StartSamplingParams::Create " << error; + LOG_DEBUGGER(ERROR) << "StartSamplingParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr StartTrackingHeapObjectsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StartTrackingHeapObjectsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StartTrackingHeapObjectsParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "trackAllocations"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->trackAllocations_ = result->IsTrue(); - } else { - error += "'trackAllocations' should be a boolean;"; - } + bool trackAllocations; + ret = params.GetBool("trackAllocations", &trackAllocations); + if (ret == Result::SUCCESS) { + paramsObject->trackAllocations_ = trackAllocations; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'trackAllocations';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "StartTrackingHeapObjectsParams::Create " << error; + LOG_DEBUGGER(ERROR) << "StartTrackingHeapObjectsParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr StopTrackingHeapObjectsParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StopTrackingHeapObjectsParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StopTrackingHeapObjectsParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "reportProgress"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->reportProgress_ = result->IsTrue(); - } else { - error += "'reportProgress' should be a boolean;"; - } + bool reportProgress; + ret = params.GetBool("reportProgress", &reportProgress); + if (ret == Result::SUCCESS) { + paramsObject->reportProgress_ = reportProgress; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'reportProgress';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "treatGlobalObjectsAsRoots"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->treatGlobalObjectsAsRoots_ = result->IsTrue(); - } else { - error += "'treatGlobalObjectsAsRoots' should be a boolean;"; - } + bool treatGlobalObjectsAsRoots; + ret = params.GetBool("treatGlobalObjectsAsRoots", &treatGlobalObjectsAsRoots); + if (ret == Result::SUCCESS) { + paramsObject->treatGlobalObjectsAsRoots_ = treatGlobalObjectsAsRoots; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'treatGlobalObjectsAsRoots';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "captureNumericValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->captureNumericValue_ = result->IsTrue(); - } else { - error += "'captureNumericValue' should be a boolean;"; - } + bool captureNumericValue; + ret = params.GetBool("captureNumericValue", &captureNumericValue); + if (ret == Result::SUCCESS) { + paramsObject->captureNumericValue_ = captureNumericValue; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'captureNumericValue';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "StopTrackingHeapObjectsParams::Create " << error; + LOG_DEBUGGER(ERROR) << "StopTrackingHeapObjectsParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr AddInspectedHeapObjectParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr AddInspectedHeapObjectParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "AddInspectedHeapObjectParams::Create params is nullptr"; - return nullptr; - } - std::string error; auto paramsObject = std::make_unique(); + std::string error; + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "heapObjectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->heapObjectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'heapObjectId' should be a String;"; - } + std::string heapObjectId; + ret = params.GetString("heapObjectId", &heapObjectId); + if (ret == Result::SUCCESS) { + paramsObject->heapObjectId_ = std::stoi(heapObjectId); } else { - error += "should contain 'heapObjectId';"; + error += "Unknown 'heapObjectId';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "AddInspectedHeapObjectParams::Create " << error; + LOG_DEBUGGER(ERROR) << "AddInspectedHeapObjectParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr GetHeapObjectIdParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr GetHeapObjectIdParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "GetHeapObjectIdParams::Create params is nullptr"; + auto paramsObject = std::make_unique(); + std::string error; + Result ret; + + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectId';"; + } + + if (!error.empty()) { + LOG_DEBUGGER(ERROR) << "GetHeapObjectIdParams::Create " << error; return nullptr; } + return paramsObject; +} + +std::unique_ptr GetObjectByHeapObjectIdParams::Create(const PtJson ¶ms) +{ + auto paramsObject = std::make_unique(); std::string error; - auto paramsObject = std::make_unique(); + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } - } else { - error += "should contain 'objectId';"; + std::string objectId; + ret = params.GetString("objectId", &objectId); + if (ret == Result::SUCCESS) { + paramsObject->objectId_ = std::stoi(objectId); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectId';"; + } + + std::string objectGroup; + ret = params.GetString("objectGroup", &objectGroup); + if (ret == Result::SUCCESS) { + paramsObject->objectGroup_ = std::move(objectGroup); + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'objectGroup';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "GetHeapObjectIdParams::Create " << error; + LOG_DEBUGGER(ERROR) << "GetObjectByHeapObjectIdParams::Create " << error; return nullptr; } return paramsObject; } -std::unique_ptr GetObjectByHeapObjectIdParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr StartPreciseCoverageParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectIdParams::Create params is nullptr"; + auto paramsObject = std::make_unique(); + std::string error; + Result ret; + + bool callCount; + ret = params.GetBool("callCount", &callCount); + if (ret == Result::SUCCESS) { + paramsObject->callCount_ = callCount; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'callCount';"; + } + + bool detailed; + ret = params.GetBool("detailed", &detailed); + if (ret == Result::SUCCESS) { + paramsObject->detailed_ = detailed; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'detailed';"; + } + + bool allowTriggeredUpdates; + ret = params.GetBool("allowTriggeredUpdates", &allowTriggeredUpdates); + if (ret == Result::SUCCESS) { + paramsObject->allowTriggeredUpdates_ = allowTriggeredUpdates; + } else if (ret == Result::TYPE_ERROR) { // optional value + error += "Unknown 'allowTriggeredUpdates';"; + } + + if (!error.empty()) { + LOG_DEBUGGER(ERROR) << "StartPreciseCoverageParams::Create " << error; return nullptr; } + return paramsObject; +} + +std::unique_ptr SetSamplingIntervalParams::Create(const PtJson ¶ms) +{ + auto paramsObject = std::make_unique(); std::string error; - auto paramsObject = std::make_unique(); + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } + int32_t interval; + ret = params.GetInt("interval", &interval); + if (ret == Result::SUCCESS) { + paramsObject->interval_ = interval; } else { - error += "should contain 'objectId';"; + error += "Unknown 'interval';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectGroup"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - paramsObject->objectGroup_ = DebuggerApi::ToStdString(result); - } else { - error += "'objectGroup' should be a String;"; - } + if (!error.empty()) { + LOG_DEBUGGER(ERROR) << "SetSamplingIntervalParams::Create " << error; + return nullptr; } + return paramsObject; +} +std::unique_ptr RecordClockSyncMarkerParams::Create(const PtJson ¶ms) +{ + std::string error; + auto recordClockSyncMarkerParams = std::make_unique(); + Result ret; + + std::string syncId; + ret = params.GetString("syncId", &syncId); + if (ret == Result::SUCCESS) { + recordClockSyncMarkerParams->syncId_ = syncId; + } else { + error += "Unknown 'syncId';"; + } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "GetObjectByHeapObjectIdParams::Create " << error; + LOG_DEBUGGER(ERROR) << "RecordClockSyncMarkerParams::Create " << error; return nullptr; } - return paramsObject; + + return recordClockSyncMarkerParams; } -std::unique_ptr StartPreciseCoverageParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr RequestMemoryDumpParams::Create(const PtJson ¶ms) { - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "StartPreciseCoverageParams::Create params is nullptr"; + std::string error; + auto requestMemoryDumpParams = std::make_unique(); + Result ret; + + bool deterministic; + ret = params.GetBool("deterministic", &deterministic); + if (ret == Result::SUCCESS) { + requestMemoryDumpParams->deterministic_ = deterministic; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'deterministic';"; + } + + std::string levelOfDetail; + ret = params.GetString("levelOfDetail", &levelOfDetail); + if (ret == Result::SUCCESS) { + if (MemoryDumpLevelOfDetailValues::Valid(levelOfDetail)) { + requestMemoryDumpParams->levelOfDetail_ = std::move(levelOfDetail); + } else { + error += "'levelOfDetail' is invalid;"; + } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'levelOfDetail';"; + } + + if (!error.empty()) { + LOG_DEBUGGER(ERROR) << "RequestMemoryDumpParams::Create " << error; return nullptr; } + + return requestMemoryDumpParams; +} + +std::unique_ptr StartParams::Create(const PtJson ¶ms) +{ std::string error; - auto paramsObject = std::make_unique(); + auto startParams = std::make_unique(); + Result ret; + + std::string categories; + ret = params.GetString("categories", &categories); + if (ret == Result::SUCCESS) { + startParams->categories_ = std::move(categories); + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'categories';"; + } - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "callCount"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->callCount_ = result->IsTrue(); + std::string options; + ret = params.GetString("options", &options); + if (ret == Result::SUCCESS) { + startParams->options_ = std::move(options); + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'options';"; + } + + int32_t bufferUsageReportingInterval; + ret = params.GetInt("bufferUsageReportingInterval", &bufferUsageReportingInterval); + if (ret == Result::SUCCESS) { + startParams->bufferUsageReportingInterval_ = bufferUsageReportingInterval; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'bufferUsageReportingInterval';"; + } + + std::string transferMode; + ret = params.GetString("transferMode", &transferMode); + if (ret == Result::SUCCESS) { + if (StartParams::TransferModeValues::Valid(transferMode)) { + startParams->transferMode_ = std::move(transferMode); } else { - error += "'callCount' should be a boolean;"; + error += "'transferMode' is invalid;"; } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'transferMode';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "detailed"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->detailed_ = result->IsTrue(); + std::string streamFormat; + ret = params.GetString("streamFormat", &streamFormat); + if (ret == Result::SUCCESS) { + if (StreamFormatValues::Valid(streamFormat)) { + startParams->streamFormat_ = std::move(streamFormat); } else { - error += "'detailed' should be a boolean;"; + error += "'streamFormat' is invalid;"; } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'streamFormat';"; } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "allowTriggeredUpdates"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - paramsObject->allowTriggeredUpdates_ = result->IsTrue(); + std::string streamCompression; + ret = params.GetString("streamCompression", &streamCompression); + if (ret == Result::SUCCESS) { + if (StreamCompressionValues::Valid(streamCompression)) { + startParams->streamCompression_ = std::move(streamCompression); } else { - error += "'allowTriggeredUpdates' should be a boolean;"; + error += "'streamCompression' is invalid;"; } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'streamCompression';"; } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "StartPreciseCoverageParams::Create " << error; - return nullptr; + std::unique_ptr traceConfig; + ret = params.GetObject("traceConfig", &traceConfig); + if (ret == Result::SUCCESS) { + std::unique_ptr pTraceConfig = TraceConfig::Create(*traceConfig); + if (pTraceConfig == nullptr) { + error += "'traceConfig' format invalid;"; + } else { + startParams->traceConfig_ = std::move(pTraceConfig); + } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'traceConfig';"; } - return paramsObject; -} -std::unique_ptr SetSamplingIntervalParams::Create(const EcmaVM *ecmaVm, - const Local ¶ms) -{ - ASSERT(ecmaVm); - if (params.IsEmpty()) { - LOG(ERROR, DEBUGGER) << "SetSamplingIntervalParams::Create params is nullptr"; - return nullptr; + std::string perfettoConfig; + ret = params.GetString("perfettoConfig", &perfettoConfig); + if (ret == Result::SUCCESS) { + startParams->perfettoConfig_ = std::move(perfettoConfig); + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'perfettoConfig';"; } - std::string error; - auto paramsObject = std::make_unique(); - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "interval"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - paramsObject->interval_ = static_cast(Local(result)->Value()); + std::string tracingBackend; + ret = params.GetString("tracingBackend", &tracingBackend); + if (ret == Result::SUCCESS) { + if (TracingBackendValues::Valid(tracingBackend)) { + startParams->tracingBackend_ = std::move(tracingBackend); } else { - error += "'interval' should be a Number;"; + error += "'tracingBackend' is invalid;"; } - } else { - error += "should contain 'interval';"; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'tracingBackend';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SetSamplingIntervalParams::Create " << error; + LOG_DEBUGGER(ERROR) << "StartParams::Create " << error; return nullptr; } - return paramsObject; + + return startParams; } } // namespace panda::ecmascript::tooling diff --git a/ecmascript/tooling/base/pt_params.h b/ecmascript/tooling/base/pt_params.h index a160040adfeb3310dfd11246c158011f482ca39b..4d47ee6c7f4797341343f5a6e3d790d6a328b791 100644 --- a/ecmascript/tooling/base/pt_params.h +++ b/ecmascript/tooling/base/pt_params.h @@ -23,10 +23,9 @@ class PtBaseParams : public PtBaseTypes { public: PtBaseParams() = default; ~PtBaseParams() override = default; - - Local ToObject([[maybe_unused]] const EcmaVM *ecmaVm) const override final + std::unique_ptr ToJson() const override { - return Local(); + UNREACHABLE(); } private: @@ -39,7 +38,6 @@ public: EnableParams() = default; ~EnableParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); double GetMaxScriptsCacheSize() const @@ -64,7 +62,7 @@ public: EvaluateOnCallFrameParams() = default; ~EvaluateOnCallFrameParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); CallFrameId GetCallFrameId() const { @@ -83,7 +81,7 @@ private: CallFrameId callFrameId_ {}; std::string expression_ {}; std::optional objectGroup_ {}; - std::optional includeCommandLineApi_ {}; + std::optional includeCommandLineAPI_ {}; std::optional silent_ {}; std::optional returnByValue_ {}; std::optional generatePreview_ {}; @@ -95,7 +93,7 @@ public: GetPossibleBreakpointsParams() = default; ~GetPossibleBreakpointsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); Location *GetStart() const { @@ -139,7 +137,7 @@ public: GetScriptSourceParams() = default; ~GetScriptSourceParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); ScriptId GetScriptId() const { @@ -150,7 +148,7 @@ private: NO_COPY_SEMANTIC(GetScriptSourceParams); NO_MOVE_SEMANTIC(GetScriptSourceParams); - ScriptId scriptId_ {}; + ScriptId scriptId_ {0}; }; class RemoveBreakpointParams : public PtBaseParams { @@ -158,7 +156,7 @@ public: RemoveBreakpointParams() = default; ~RemoveBreakpointParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); BreakpointId GetBreakpointId() const { @@ -177,7 +175,7 @@ public: ResumeParams() = default; ~ResumeParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetTerminateOnResume() const { @@ -201,9 +199,9 @@ public: SetAsyncCallStackDepthParams() = default; ~SetAsyncCallStackDepthParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); - uint32_t GetMaxDepth() const + int32_t GetMaxDepth() const { return maxDepth_; } @@ -212,14 +210,14 @@ private: NO_COPY_SEMANTIC(SetAsyncCallStackDepthParams); NO_MOVE_SEMANTIC(SetAsyncCallStackDepthParams); - uint32_t maxDepth_ {0}; + int32_t maxDepth_ {0}; }; class SetBlackboxPatternsParams : public PtBaseParams { public: SetBlackboxPatternsParams() = default; ~SetBlackboxPatternsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); std::list GetPatterns() const { @@ -238,11 +236,11 @@ public: SetBreakpointByUrlParams() = default; ~SetBreakpointByUrlParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); int32_t GetLine() const { - return line_; + return lineNumber_; } const std::string &GetUrl() const @@ -280,12 +278,12 @@ public: int32_t GetColumn() const { - return column_.value_or(0); + return columnNumber_.value_or(0); } bool HasColumn() const { - return column_.has_value(); + return columnNumber_.has_value(); } const std::string &GetCondition() const @@ -303,11 +301,11 @@ private: NO_COPY_SEMANTIC(SetBreakpointByUrlParams); NO_MOVE_SEMANTIC(SetBreakpointByUrlParams); - int32_t line_ {0}; + int32_t lineNumber_ {0}; std::optional url_ {}; std::optional urlRegex_ {}; std::optional scriptHash_ {}; - std::optional column_ {0}; + std::optional columnNumber_ {0}; std::optional condition_ {}; }; @@ -317,7 +315,7 @@ class SetPauseOnExceptionsParams : public PtBaseParams { public: SetPauseOnExceptionsParams() = default; ~SetPauseOnExceptionsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); PauseOnExceptionsState GetState() const { @@ -353,7 +351,7 @@ public: StepIntoParams() = default; ~StepIntoParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetBreakOnAsyncCall() const { @@ -391,7 +389,7 @@ public: StepOverParams() = default; ~StepOverParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); const std::list> *GetSkipList() const { @@ -418,7 +416,7 @@ public: GetPropertiesParams() = default; ~GetPropertiesParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); RemoteObjectId GetObjectId() const { @@ -470,7 +468,7 @@ public: CallFunctionOnParams() = default; ~CallFunctionOnParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); const std::string &GetFunctionDeclaration() { @@ -615,7 +613,7 @@ public: StartSamplingParams() = default; ~StartSamplingParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); int32_t GetSamplingInterval() const { @@ -626,7 +624,7 @@ private: NO_COPY_SEMANTIC(StartSamplingParams); NO_MOVE_SEMANTIC(StartSamplingParams); - std::optional samplingInterval_ {32768}; + std::optional samplingInterval_ {32768}; }; class StartTrackingHeapObjectsParams : public PtBaseParams { @@ -634,8 +632,7 @@ public: StartTrackingHeapObjectsParams() = default; ~StartTrackingHeapObjectsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, - const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetTrackAllocations() const { @@ -659,7 +656,7 @@ public: StopTrackingHeapObjectsParams() = default; ~StopTrackingHeapObjectsParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetReportProgress() const { @@ -705,7 +702,7 @@ public: AddInspectedHeapObjectParams() = default; ~AddInspectedHeapObjectParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); HeapSnapshotObjectId GetHeapObjectId() const { @@ -724,7 +721,7 @@ public: GetHeapObjectIdParams() = default; ~GetHeapObjectIdParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); RemoteObjectId GetObjectId() const { @@ -743,7 +740,7 @@ public: GetObjectByHeapObjectIdParams() = default; ~GetObjectByHeapObjectIdParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); HeapSnapshotObjectId GetObjectId() const { @@ -774,8 +771,7 @@ public: StartPreciseCoverageParams() = default; ~StartPreciseCoverageParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, - const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); bool GetCallCount() const { @@ -821,14 +817,14 @@ public: SetSamplingIntervalParams() = default; ~SetSamplingIntervalParams() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); - int GetInterval() const + int32_t GetInterval() const { return interval_; } - SetSamplingIntervalParams &SetInterval(int interval) + SetSamplingIntervalParams &SetInterval(int32_t interval) { interval_ = interval; return *this; @@ -838,7 +834,263 @@ private: NO_COPY_SEMANTIC(SetSamplingIntervalParams); NO_MOVE_SEMANTIC(SetSamplingIntervalParams); - int interval_ {0}; + int32_t interval_ {0}; +}; + +class RecordClockSyncMarkerParams : public PtBaseParams { +public: + RecordClockSyncMarkerParams() = default; + ~RecordClockSyncMarkerParams() override = default; + + static std::unique_ptr Create(const PtJson ¶ms); + + std::string GetSyncId() const + { + return syncId_; + } + + RecordClockSyncMarkerParams &SetSyncId(std::string syncId) + { + syncId_ = syncId; + return *this; + } + +private: + NO_COPY_SEMANTIC(RecordClockSyncMarkerParams); + NO_MOVE_SEMANTIC(RecordClockSyncMarkerParams); + + std::string syncId_ {}; +}; + +class RequestMemoryDumpParams : public PtBaseParams { +public: + RequestMemoryDumpParams() = default; + ~RequestMemoryDumpParams() override = default; + + static std::unique_ptr Create(const PtJson ¶ms); + + bool GetDeterministic() const + { + return deterministic_.value(); + } + + RequestMemoryDumpParams &SetDeterministic(bool deterministic) + { + deterministic_ = deterministic; + return *this; + } + + bool HasDeterministic() const + { + return deterministic_.has_value(); + } + + MemoryDumpLevelOfDetail GetLevelOfDetail() const + { + return levelOfDetail_.value(); + } + + RequestMemoryDumpParams &SetLevelOfDetail(const MemoryDumpLevelOfDetail &levelOfDetail) + { + levelOfDetail_ = levelOfDetail; + return *this; + } + + bool HasLevelOfDetail() const + { + return levelOfDetail_.has_value(); + } + +private: + NO_COPY_SEMANTIC(RequestMemoryDumpParams); + NO_MOVE_SEMANTIC(RequestMemoryDumpParams); + + std::optional deterministic_ {}; + std::optional levelOfDetail_ {}; +}; + +class StartParams : public PtBaseParams { +public: + StartParams() = default; + ~StartParams() override = default; + + static std::unique_ptr Create(const PtJson ¶ms); + + std::string GetCategories() const + { + return categories_.value(); + } + + StartParams &SetCategories(std::string categories) + { + categories_ = categories; + return *this; + } + + bool HasCategories() const + { + return categories_.has_value(); + } + + std::string GetOptions() const + { + return options_.value(); + } + + StartParams &SetOptions(std::string options) + { + options_ = options; + return *this; + } + + bool HasOptions() const + { + return options_.has_value(); + } + + int32_t GetBufferUsageReportingInterval() const + { + return bufferUsageReportingInterval_.value(); + } + + StartParams &SetBufferUsageReportingInterval(int32_t bufferUsageReportingInterval) + { + bufferUsageReportingInterval_ = bufferUsageReportingInterval; + return *this; + } + + bool HasBufferUsageReportingInterval() const + { + return bufferUsageReportingInterval_.has_value(); + } + + std::string GetTransferMode() const + { + return transferMode_.value(); + } + + StartParams &SetTransferMode(std::string transferMode) + { + transferMode_ = transferMode; + return *this; + } + + bool HasTransferMode() const + { + return transferMode_.has_value(); + } + + struct TransferModeValues { + static bool Valid(const std::string &values) + { + return values == ReportEvents() || values == ReturnAsStream(); + } + static std::string ReportEvents() + { + return "ReportEvents"; + } + static std::string ReturnAsStream() + { + return "ReturnAsStream"; + } + }; + + StreamFormat GetStreamFormat() const + { + return streamFormat_.value(); + } + + StartParams &SetStreamFormat(const StreamFormat &streamFormat) + { + streamFormat_ = streamFormat; + return *this; + } + + bool HasStreamFormat() const + { + return streamFormat_.has_value(); + } + + StreamCompression GetStreamCompression() const + { + return streamCompression_.value(); + } + + StartParams &SetStreamCompression(const StreamCompression &streamCompression) + { + streamCompression_ = streamCompression; + return *this; + } + + bool HasStreamCompression() const + { + return streamCompression_.has_value(); + } + + TraceConfig *GetTraceConfig() const + { + if (traceConfig_) { + return traceConfig_->get(); + } + return nullptr; + } + + StartParams &SetTraceConfig(std::unique_ptr &traceConfig) + { + traceConfig_ = std::move(traceConfig); + return *this; + } + + bool HasTraceConfig() const + { + return traceConfig_.has_value(); + } + + std::string GetPerfettoConfig() const + { + return perfettoConfig_.value(); + } + + StartParams &SetPerfettoConfig(std::string perfettoConfig) + { + perfettoConfig_ = perfettoConfig; + return *this; + } + + bool HasPerfettoConfig() const + { + return perfettoConfig_.has_value(); + } + + TracingBackend GetTracingBackend() const + { + return tracingBackend_.value(); + } + + StartParams &SetTracingBackend(const TracingBackend &tracingBackend) + { + tracingBackend_ = tracingBackend; + return *this; + } + + bool HasTracingBackend() const + { + return tracingBackend_.has_value(); + } + +private: + NO_COPY_SEMANTIC(StartParams); + NO_MOVE_SEMANTIC(StartParams); + + std::optional categories_ {}; + std::optional options_ {}; + std::optional bufferUsageReportingInterval_ {0}; + std::optional transferMode_ {}; + std::optional streamFormat_ {}; + std::optional streamCompression_ {}; + std::optional> traceConfig_ {}; + std::optional perfettoConfig_ {}; + std::optional tracingBackend_ {}; }; } // namespace panda::ecmascript::tooling #endif \ No newline at end of file diff --git a/ecmascript/tooling/base/pt_returns.cpp b/ecmascript/tooling/base/pt_returns.cpp index e3b36fb45ec3477ebc8bc2dd204cc16471a79fa3..1d4e576cb11bc62669ae312bbc1feed393b284c1 100644 --- a/ecmascript/tooling/base/pt_returns.cpp +++ b/ecmascript/tooling/base/pt_returns.cpp @@ -16,17 +16,6 @@ #include "ecmascript/tooling/base/pt_returns.h" namespace panda::ecmascript::tooling { -Local EnableReturns::ToObject(const EcmaVM *ecmaVm) const -{ - Local result = NewObject(ecmaVm); - - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "debuggerId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(debuggerId_).c_str()))); - - return result; -} - std::unique_ptr EnableReturns::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); @@ -36,328 +25,324 @@ std::unique_ptr EnableReturns::ToJson() const return result; } -Local SetBreakpointByUrlReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SetBreakpointByUrlReturns::ToJson() const { + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("breakpointId", id_.c_str()); + std::unique_ptr array = PtJson::CreateArray(); size_t len = locations_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local location = locations_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, location); + ASSERT(locations_[i] != nullptr); + std::unique_ptr location = locations_[i]->ToJson(); + array->Push(location); } - - Local result = NewObject(ecmaVm); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId")), - Local(StringRef::NewFromUtf8(ecmaVm, id_.c_str()))); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "locations")), values); + result->Add("locations", array); return result; } -Local EvaluateOnCallFrameReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr EvaluateOnCallFrameReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - Local location = result_->ToObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), Local(location)); + ASSERT(result_ != nullptr); + result->Add("result", result_->ToJson()); if (exceptionDetails_) { - Local exception = exceptionDetails_.value()->ToObject(ecmaVm); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "exceptionDetails")), - Local(exception)); + ASSERT(exceptionDetails_.value() != nullptr); + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); } return result; } -Local GetPossibleBreakpointsReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetPossibleBreakpointsReturns::ToJson() const { + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); size_t len = locations_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local location = locations_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, location); + ASSERT(locations_[i] != nullptr); + std::unique_ptr location = locations_[i]->ToJson(); + array->Push(location); } - - Local result = NewObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "locations")), values); + result->Add("locations", array); return result; } -Local GetScriptSourceReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetScriptSourceReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptSource")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptSource_.c_str()))); + result->Add("scriptSource", scriptSource_.c_str()); if (bytecode_) { - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "bytecode")), - Local(StringRef::NewFromUtf8(ecmaVm, bytecode_->c_str()))); + result->Add("bytecode", bytecode_->c_str()); } return result; } -Local RestartFrameReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr RestartFrameReturns::ToJson() const { + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); size_t len = callFrames_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local location = callFrames_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, location); + ASSERT(callFrames_[i] != nullptr); + std::unique_ptr location = callFrames_[i]->ToJson(); + array->Push(location); } + result->Add("callFrames", array); - Local result = NewObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrames")), values); return result; } -Local SearchInContentReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SearchInContentReturns::ToJson() const { + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr array = PtJson::CreateArray(); size_t len = result_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local location = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, location); + ASSERT(result_[i] != nullptr); + std::unique_ptr res = result_[i]->ToJson(); + array->Push(res); } - - Local result = NewObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); + result->Add("result", array); return result; } -Local SetBreakpointReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SetBreakpointReturns::ToJson() const { - Local result = NewObject(ecmaVm); - - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId")), - Local(StringRef::NewFromUtf8(ecmaVm, breakpointId_.c_str()))); + std::unique_ptr result = PtJson::CreateObject(); - Local location = location_->ToObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "actualLocation")), - Local(location)); + result->Add("breakpointId", breakpointId_.c_str()); + ASSERT(location_ != nullptr); + result->Add("actualLocation", location_->ToJson()); return result; } -Local SetInstrumentationBreakpointReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SetInstrumentationBreakpointReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "breakpointId")), - Local(StringRef::NewFromUtf8(ecmaVm, breakpointId_.c_str()))); + result->Add("breakpointId", breakpointId_.c_str()); return result; } -Local SetScriptSourceReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SetScriptSourceReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); if (callFrames_) { - const std::vector> &callFrame = callFrames_.value(); - size_t len = callFrame.size(); - Local values = ArrayRef::New(ecmaVm, len); + std::unique_ptr array = PtJson::CreateArray(); + size_t len = callFrames_->size(); for (size_t i = 0; i < len; i++) { - Local location = callFrame[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, location); + ASSERT(callFrames_.value()[i] != nullptr); + std::unique_ptr location = callFrames_.value()[i]->ToJson(); + array->Push(location); } - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrames")), values); + result->Add("callFrames", array); } - if (stackChanged_) { - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "stackChanged")), - BooleanRef::New(ecmaVm, stackChanged_.value())); + result->Add("stackChanged", stackChanged_.value()); } - if (exceptionDetails_) { - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "exceptionDetails")), - Local(exceptionDetails_.value()->ToObject(ecmaVm))); + ASSERT(exceptionDetails_.value() != nullptr); + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); } return result; } -Local GetPropertiesReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetPropertiesReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + std::unique_ptr array = PtJson::CreateArray(); size_t len = result_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local descriptor = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, descriptor); + ASSERT(result_[i] != nullptr); + std::unique_ptr location = result_[i]->ToJson(); + array->Push(location); } - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); + result->Add("result", array); if (internalPropertyDescripties_) { - auto &descripties = internalPropertyDescripties_.value(); - len = descripties.size(); - values = ArrayRef::New(ecmaVm, len); + array = PtJson::CreateArray(); + len = internalPropertyDescripties_->size(); for (size_t i = 0; i < len; i++) { - Local descriptor = descripties[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, descriptor); + ASSERT(internalPropertyDescripties_.value()[i] != nullptr); + std::unique_ptr location = internalPropertyDescripties_.value()[i]->ToJson(); + array->Push(location); } - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "internalProperties")), values); + result->Add("internalProperties", array); } if (privateProperties_) { - auto &descripties = privateProperties_.value(); - len = descripties.size(); - values = ArrayRef::New(ecmaVm, len); + array = PtJson::CreateArray(); + len = privateProperties_->size(); for (size_t i = 0; i < len; i++) { - Local descriptor = descripties[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, descriptor); + ASSERT(privateProperties_.value()[i] != nullptr); + std::unique_ptr location = privateProperties_.value()[i]->ToJson(); + array->Push(location); } - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "privateProperties")), values); + result->Add("privateProperties", array); } if (exceptionDetails_) { - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "exceptionDetails")), - Local(exceptionDetails_.value()->ToObject(ecmaVm))); + ASSERT(exceptionDetails_.value() != nullptr); + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); } return result; } -Local CallFunctionOnReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr CallFunctionOnReturns::ToJson() const { - // For this - Local returns = NewObject(ecmaVm); - - // For this.result_ - Local result = result_->ToObject(ecmaVm); - returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), - Local(result)); - // For this.exceptionDetails_ + std::unique_ptr result = PtJson::CreateObject(); + + ASSERT(result_ != nullptr); + result->Add("result", result_->ToJson()); if (exceptionDetails_) { - returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "exceptionDetails")), - Local(exceptionDetails_.value()->ToObject(ecmaVm))); + ASSERT(exceptionDetails_.value() != nullptr); + result->Add("exceptionDetails", exceptionDetails_.value()->ToJson()); } - return returns; + return result; } -Local StopSamplingReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr StopSamplingReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + + ASSERT(profile_ != nullptr); + result->Add("profile", profile_->ToJson()); - if (profile_ != nullptr) { - Local profile = profile_->ToObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "profile")), - Local(profile)); - } return result; } -Local GetHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetHeapObjectIdReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "heapSnapshotObjectId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(heapSnapshotObjectId_).c_str()))); + result->Add("heapSnapshotObjectId", std::to_string(heapSnapshotObjectId_).c_str()); return result; } -Local GetObjectByHeapObjectIdReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetObjectByHeapObjectIdReturns::ToJson() const { - Local result = NewObject(ecmaVm); - - if (remoteObjectResult_ != nullptr) { - Local remoteObjectResult = remoteObjectResult_->ToObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), - Local(remoteObjectResult)); - } + std::unique_ptr result = PtJson::CreateObject(); + + ASSERT(remoteObjectResult_ != nullptr); + result->Add("result", remoteObjectResult_->ToJson()); return result; } -Local StopReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr StopReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - Local profile = profile_->ToObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "profile")), Local(profile)); + ASSERT(profile_ != nullptr); + result->Add("profile", profile_->ToJson()); return result; } -Local GetHeapUsageReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetHeapUsageReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "usedSize")), - NumberRef::New(ecmaVm, usedSize_)); - result->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "totalSize")), - NumberRef::New(ecmaVm, totalSize_)); + result->Add("usedSize", usedSize_); + result->Add("totalSize", totalSize_); return result; } -Local GetBestEffortCoverageReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr GetBestEffortCoverageReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + std::unique_ptr array = PtJson::CreateArray(); size_t len = result_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local scriptCoverage = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, scriptCoverage); + ASSERT(result_[i] != nullptr); + std::unique_ptr scriptCoverage = result_[i]->ToJson(); + array->Push(scriptCoverage); } - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); + result->Add("result", array); return result; } -Local StartPreciseCoverageReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr StartPreciseCoverageReturns::ToJson() const { - Local result = NewObject(ecmaVm); - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timestamp")), - NumberRef::New(ecmaVm, timestamp_)); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("timestamp", timestamp_); return result; } -Local TakePreciseCoverageReturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr TakePreciseCoverageReturns::ToJson() const { - Local returns = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + std::unique_ptr array = PtJson::CreateArray(); size_t len = result_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local scriptCoverage = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, scriptCoverage); - } - returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); - if (timestamp_) { - returns->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timestamp")), - NumberRef::New(ecmaVm, timestamp_)); + ASSERT(result_[i] != nullptr); + std::unique_ptr scriptTypeProfile = result_[i]->ToJson(); + array->Push(scriptTypeProfile); } + result->Add("result", array); + result->Add("timestamp", timestamp_); - return returns; + return result; } -Local TakeTypeProfileturns::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr TakeTypeProfileReturns::ToJson() const { - Local result = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); + std::unique_ptr array = PtJson::CreateArray(); size_t len = result_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - Local scriptTypeProfile = result_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, scriptTypeProfile); + ASSERT(result_[i] != nullptr); + std::unique_ptr scriptTypeProfile = result_[i]->ToJson(); + array->Push(scriptTypeProfile); } - result->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "result")), values); + result->Add("result", array); + + return result; +} + +std::unique_ptr GetCategoriesReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + std::unique_ptr categories = PtJson::CreateArray(); + size_t len = categories_.size(); + for (size_t i = 0; i < len; i++) { + categories->Push(categories_[i].c_str()); + } + result->Add("categories", categories); + + return result; +} + +std::unique_ptr RequestMemoryDumpReturns::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("dumpGuid", dumpGuid_.c_str()); + result->Add("success", success_); + return result; } } // namespace panda::ecmascript::tooling \ No newline at end of file diff --git a/ecmascript/tooling/base/pt_returns.h b/ecmascript/tooling/base/pt_returns.h index 69231a6c1be6b5b00e4dd7be2336a37330bab71f..3a10671d23d33702d94a56d48fe62655a47f1704 100644 --- a/ecmascript/tooling/base/pt_returns.h +++ b/ecmascript/tooling/base/pt_returns.h @@ -23,11 +23,6 @@ class PtBaseReturns : public PtBaseTypes { public: PtBaseReturns() = default; ~PtBaseReturns() override = default; - - Local ToObject(const EcmaVM *ecmaVm) const override - { - return NewObject(ecmaVm); - } std::unique_ptr ToJson() const override { return PtJson::CreateObject(); @@ -43,7 +38,6 @@ public: explicit EnableReturns(UniqueDebuggerId id) : debuggerId_(id) {} ~EnableReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; private: @@ -61,7 +55,7 @@ public: {} ~SetBreakpointByUrlReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetBreakpointByUrlReturns() = default; @@ -79,7 +73,7 @@ public: : result_(std::move(result)), exceptionDetails_(std::move(exceptionDetails)) {} ~EvaluateOnCallFrameReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: EvaluateOnCallFrameReturns() = default; @@ -97,7 +91,7 @@ public: {} ~GetPossibleBreakpointsReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetPossibleBreakpointsReturns() = default; @@ -114,7 +108,7 @@ public: {} ~GetScriptSourceReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetScriptSourceReturns() = default; @@ -131,7 +125,7 @@ public: : callFrames_(std::move(callFrames)) {} ~RestartFrameReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: RestartFrameReturns() = default; @@ -146,7 +140,7 @@ public: explicit SearchInContentReturns(std::vector> result) : result_(std::move(result)) {} ~SearchInContentReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SearchInContentReturns() = default; @@ -162,7 +156,7 @@ public: : breakpointId_(id), location_(std::move(location)) {} ~SetBreakpointReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetBreakpointReturns() = default; @@ -177,7 +171,7 @@ public: explicit SetInstrumentationBreakpointReturns(const std::string &id) : breakpointId_(id) {} ~SetInstrumentationBreakpointReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetInstrumentationBreakpointReturns() = default; @@ -197,7 +191,7 @@ public: exceptionDetails_(std::move(exceptionDetails)) {} ~SetScriptSourceReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: SetScriptSourceReturns() = default; @@ -221,7 +215,7 @@ public: exceptionDetails_(std::move(exceptionDetails)) {} ~GetPropertiesReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetPropertiesReturns() = default; @@ -242,7 +236,7 @@ public: exceptionDetails_(std::move(exceptionDetails)) {} ~CallFunctionOnReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: CallFunctionOnReturns() = default; @@ -260,7 +254,7 @@ public: {} ~StopSamplingReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: StopSamplingReturns() = default; @@ -277,7 +271,7 @@ public: {} ~GetHeapObjectIdReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetHeapObjectIdReturns() = default; @@ -294,7 +288,7 @@ public: {} ~GetObjectByHeapObjectIdReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetObjectByHeapObjectIdReturns() = default; @@ -308,7 +302,7 @@ class StopReturns : public PtBaseReturns { public: explicit StopReturns(std::unique_ptr profile) : profile_(std::move(profile)) {} ~StopReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: StopReturns() = default; @@ -323,7 +317,7 @@ public: explicit GetHeapUsageReturns(double usedSize, double totalSize) : usedSize_(usedSize), totalSize_(totalSize) {} ~GetHeapUsageReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetHeapUsageReturns() = default; @@ -340,7 +334,7 @@ public: : result_(std::move(result)) {} ~GetBestEffortCoverageReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: GetBestEffortCoverageReturns() = default; @@ -354,7 +348,7 @@ class StartPreciseCoverageReturns : public PtBaseReturns { public: explicit StartPreciseCoverageReturns(int64_t tamp) : timestamp_(tamp) {} ~StartPreciseCoverageReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: StartPreciseCoverageReturns() = default; @@ -371,7 +365,7 @@ public: timestamp_(tamp) {} ~TakePreciseCoverageReturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; private: TakePreciseCoverageReturns() = default; @@ -382,20 +376,52 @@ private: int64_t timestamp_ {0}; }; -class TakeTypeProfileturns : public PtBaseReturns { +class TakeTypeProfileReturns : public PtBaseReturns { public: - explicit TakeTypeProfileturns(std::vector> result) + explicit TakeTypeProfileReturns(std::vector> result) : result_(std::move(result)) {} - ~TakeTypeProfileturns() override = default; - Local ToObject(const EcmaVM *ecmaVm) const override; + ~TakeTypeProfileReturns() override = default; + std::unique_ptr ToJson() const override; private: - TakeTypeProfileturns() = default; - NO_COPY_SEMANTIC(TakeTypeProfileturns); - NO_MOVE_SEMANTIC(TakeTypeProfileturns); + TakeTypeProfileReturns() = default; + NO_COPY_SEMANTIC(TakeTypeProfileReturns); + NO_MOVE_SEMANTIC(TakeTypeProfileReturns); std::vector> result_ {}; }; + +class GetCategoriesReturns : public PtBaseReturns { +public: + explicit GetCategoriesReturns(std::vector categories) + : categories_(std::move(categories)) + {} + ~GetCategoriesReturns() override = default; + std::unique_ptr ToJson() const override; + +private: + GetCategoriesReturns() = default; + NO_COPY_SEMANTIC(GetCategoriesReturns); + NO_MOVE_SEMANTIC(GetCategoriesReturns); + + std::vector categories_ {}; +}; + +class RequestMemoryDumpReturns : public PtBaseReturns { +public: + explicit RequestMemoryDumpReturns(std::string dumpGuid, bool success) + : dumpGuid_(dumpGuid), success_(success) {} + ~RequestMemoryDumpReturns() override = default; + std::unique_ptr ToJson() const override; + +private: + RequestMemoryDumpReturns() = default; + NO_COPY_SEMANTIC(RequestMemoryDumpReturns); + NO_MOVE_SEMANTIC(RequestMemoryDumpReturns); + + std::string dumpGuid_ {}; + bool success_ {}; +}; } // namespace panda::ecmascript::tooling #endif \ No newline at end of file diff --git a/ecmascript/tooling/base/pt_script.h b/ecmascript/tooling/base/pt_script.h index a7425bb8e5f46cd5b0e75762bdc61a7310860aaa..50f24dfa744ecbeb6c81bb7ddf89c43e799f0f14 100644 --- a/ecmascript/tooling/base/pt_script.h +++ b/ecmascript/tooling/base/pt_script.h @@ -105,7 +105,7 @@ private: NO_COPY_SEMANTIC(PtScript); NO_MOVE_SEMANTIC(PtScript); - ScriptId scriptId_ {}; // start from 0, such as "0","1","2"... + ScriptId scriptId_ {0}; // start from 0, such as "0","1","2"... std::string fileName_ {}; // binary file name, such as xx.bin std::string url_ {}; // source file name, such as xx.js std::string hash_ {}; // js source file hash code diff --git a/ecmascript/tooling/base/pt_types.cpp b/ecmascript/tooling/base/pt_types.cpp index 300957c0403163202f75f25e6c1f4a708d3b65a2..4c28077bc65df86ae6146ed3ea940788c47ddbdb 100644 --- a/ecmascript/tooling/base/pt_types.cpp +++ b/ecmascript/tooling/base/pt_types.cpp @@ -89,15 +89,16 @@ const std::string RemoteObject::SetIteratorDescription = "SetIterator"; // NOLI const std::string RemoteObject::MapIteratorDescription = "MapIterator"; // NOLINT (readability-identifier-naming) const std::string RemoteObject::WeakMapDescription = "WeakMap"; // NOLINT (readability-identifier-naming) const std::string RemoteObject::WeakSetDescription = "WeakSet"; // NOLINT (readability-identifier-naming) +const std::string RemoteObject::JSPrimitiveNumberDescription = // NOLINT (readability-identifier-naming) + "Number"; +const std::string RemoteObject::JSPrimitiveBooleanDescription = // NOLINT (readability-identifier-naming) + "Boolean"; +const std::string RemoteObject::JSPrimitiveStringDescription = // NOLINT (readability-identifier-naming) + "String"; +const std::string RemoteObject::JSPrimitiveSymbolDescription = // NOLINT (readability-identifier-naming) + "Symbol"; -static constexpr uint64_t DOUBLE_SIGN_MASK = 0x8000000000000000ULL; - -Local PtBaseTypes::NewObject(const EcmaVM *ecmaVm) -{ - return ObjectRef::New(ecmaVm); -} - -std::unique_ptr RemoteObject::FromTagged(const EcmaVM *ecmaVm, const Local &tagged) +std::unique_ptr RemoteObject::FromTagged(const EcmaVM *ecmaVm, Local tagged) { if (tagged->IsNull() || tagged->IsUndefined() || tagged->IsBoolean() || tagged->IsNumber() || @@ -105,10 +106,10 @@ std::unique_ptr RemoteObject::FromTagged(const EcmaVM *ecmaVm, con return std::make_unique(ecmaVm, tagged); } if (tagged->IsString()) { - return std::make_unique(ecmaVm, tagged); + return std::make_unique(ecmaVm, Local(tagged)); } if (tagged->IsSymbol()) { - return std::make_unique(ecmaVm, tagged); + return std::make_unique(ecmaVm, Local(tagged)); } if (tagged->IsFunction()) { return std::make_unique(ecmaVm, tagged); @@ -169,30 +170,85 @@ std::unique_ptr RemoteObject::FromTagged(const EcmaVM *ecmaVm, con return object; } -PrimitiveRemoteObject::PrimitiveRemoteObject(const EcmaVM *ecmaVm, const Local &tagged) +PrimitiveRemoteObject::PrimitiveRemoteObject(const EcmaVM *ecmaVm, Local tagged) { if (tagged->IsNull()) { - this->SetType(ObjectType::Object).SetSubType(ObjectSubType::Null).SetValue(tagged); + SetType(ObjectType::Object).SetSubType(ObjectSubType::Null); } else if (tagged->IsBoolean()) { - this->SetType(ObjectType::Boolean).SetValue(tagged); + std::string description = tagged->IsTrue() ? "true" : "false"; + SetType(ObjectType::Boolean) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); } else if (tagged->IsUndefined()) { - this->SetType(ObjectType::Undefined); + SetType(ObjectType::Undefined); } else if (tagged->IsNumber()) { - this->SetType(ObjectType::Number) - .SetDescription(DebuggerApi::ToStdString(tagged->ToString(ecmaVm))); - double val = Local(tagged)->Value(); - if (!std::isfinite(val) || (val == 0 && ((bit_cast(val) & DOUBLE_SIGN_MASK) == DOUBLE_SIGN_MASK))) { - this->SetUnserializableValue(this->GetDescription()); - } else { - this->SetValue(tagged); - } + std::string description = tagged->ToString(ecmaVm)->ToString(); + SetType(ObjectType::Number) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); } else if (tagged->IsBigInt()) { - std::string literal = tagged->ToString(ecmaVm)->ToString() + "n"; // n : BigInt literal postfix - this->SetType(ObjectType::Bigint).SetValue(StringRef::NewFromUtf8(ecmaVm, literal.data())); + std::string description = tagged->ToString(ecmaVm)->ToString() + "n"; // n : BigInt literal postfix + SetType(ObjectType::Bigint) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); } } -std::string ObjectRemoteObject::DescriptionForObject(const EcmaVM *ecmaVm, const Local &tagged) +StringRemoteObject::StringRemoteObject([[maybe_unused]] const EcmaVM *ecmaVm, Local tagged) +{ + std::string description = tagged->ToString(); + SetType(RemoteObject::TypeName::String) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); +} + +SymbolRemoteObject::SymbolRemoteObject(const EcmaVM *ecmaVm, Local tagged) +{ + std::string description = DescriptionForSymbol(ecmaVm, tagged); + SetType(RemoteObject::TypeName::Symbol) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); +} + +FunctionRemoteObject::FunctionRemoteObject(const EcmaVM *ecmaVm, Local tagged) +{ + std::string description = DescriptionForFunction(ecmaVm, tagged); + SetType(RemoteObject::TypeName::Function) + .SetClassName(RemoteObject::ClassName::Function) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); +} + +ObjectRemoteObject::ObjectRemoteObject(const EcmaVM *ecmaVm, Local tagged, + const std::string &classname) +{ + std::string description = DescriptionForObject(ecmaVm, tagged); + SetType(RemoteObject::TypeName::Object) + .SetClassName(classname) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); +} + +ObjectRemoteObject::ObjectRemoteObject(const EcmaVM *ecmaVm, Local tagged, + const std::string &classname, const std::string &subtype) +{ + std::string description = DescriptionForObject(ecmaVm, tagged); + SetType(RemoteObject::TypeName::Object) + .SetSubType(subtype) + .SetClassName(classname) + .SetValue(tagged) + .SetUnserializableValue(description) + .SetDescription(description); +} + +std::string ObjectRemoteObject::DescriptionForObject(const EcmaVM *ecmaVm, Local tagged) { if (tagged->IsArray(ecmaVm)) { return DescriptionForArray(ecmaVm, Local(tagged)); @@ -225,77 +281,131 @@ std::string ObjectRemoteObject::DescriptionForObject(const EcmaVM *ecmaVm, const return RemoteObject::PromiseDescription; } if (tagged->IsArrayIterator()) { - return RemoteObject::ArrayIteratorDescription; + return DescriptionForArrayIterator(); } if (tagged->IsStringIterator()) { return RemoteObject::StringIteratorDescription; } if (tagged->IsSetIterator()) { - return RemoteObject::SetIteratorDescription; + return DescriptionForSetIterator(); } if (tagged->IsMapIterator()) { - return RemoteObject::MapIteratorDescription; + return DescriptionForMapIterator(); } if (tagged->IsArrayBuffer()) { return DescriptionForArrayBuffer(ecmaVm, Local(tagged)); } + if (tagged->IsJSPrimitiveRef() && tagged->IsJSPrimitiveNumber()) { + return DescriptionForPrimitiveNumber(ecmaVm, tagged); + } + if (tagged->IsJSPrimitiveRef() && tagged->IsJSPrimitiveString()) { + return DescriptionForPrimitiveString(ecmaVm, tagged); + } + if (tagged->IsJSPrimitiveRef() && tagged->IsJSPrimitiveBoolean()) { + return DescriptionForPrimitiveBoolean(ecmaVm, tagged); + } return RemoteObject::ObjectDescription; } -std::string ObjectRemoteObject::DescriptionForArray(const EcmaVM *ecmaVm, const Local &tagged) +std::string ObjectRemoteObject::DescriptionForArray(const EcmaVM *ecmaVm, Local tagged) { std::string description = "Array(" + std::to_string(tagged->Length(ecmaVm)) + ")"; return description; } -std::string ObjectRemoteObject::DescriptionForRegexp(const EcmaVM *ecmaVm, const Local &tagged) +std::string ObjectRemoteObject::DescriptionForRegexp(const EcmaVM *ecmaVm, Local tagged) { - std::string regexpSource = DebuggerApi::ToStdString(tagged->GetOriginalSource(ecmaVm)); + std::string regexpSource = tagged->GetOriginalSource(ecmaVm)->ToString(); std::string description = "/" + regexpSource + "/"; return description; } -std::string ObjectRemoteObject::DescriptionForDate(const EcmaVM *ecmaVm, const Local &tagged) +std::string ObjectRemoteObject::DescriptionForDate(const EcmaVM *ecmaVm, Local tagged) { - std::string description = DebuggerApi::ToStdString(tagged->ToString(ecmaVm)); + std::string description = tagged->ToString(ecmaVm)->ToString(); return description; } -std::string ObjectRemoteObject::DescriptionForMap(const Local &tagged) +std::string ObjectRemoteObject::DescriptionForMap(Local tagged) { std::string description = ("Map(" + std::to_string(tagged->GetSize()) + ")"); return description; } -std::string ObjectRemoteObject::DescriptionForSet(const Local &tagged) +std::string ObjectRemoteObject::DescriptionForSet(Local tagged) { std::string description = ("Set(" + std::to_string(tagged->GetSize()) + ")"); return description; } -std::string ObjectRemoteObject::DescriptionForError(const EcmaVM *ecmaVm, const Local &tagged) +std::string ObjectRemoteObject::DescriptionForError(const EcmaVM *ecmaVm, Local tagged) { + // add name + Local name = StringRef::NewFromUtf8(ecmaVm, "name"); + std::string strName = Local(tagged)->Get(ecmaVm, name)->ToString(ecmaVm)->ToString(); // add message - Local stack = StringRef::NewFromUtf8(ecmaVm, "message"); - Local result = Local(tagged)->Get(ecmaVm, stack); - return DebuggerApi::ToStdString(result->ToString(ecmaVm)); + Local message = StringRef::NewFromUtf8(ecmaVm, "message"); + std::string strMessage = Local(tagged)->Get(ecmaVm, message)->ToString(ecmaVm)->ToString(); + if (strMessage.empty()) { + return strName; + } else { + return strName + ": "+ strMessage; + } +} + +std::string ObjectRemoteObject::DescriptionForArrayIterator() +{ + std::string description = RemoteObject::ArrayIteratorDescription + "{}"; + return description; +} + +std::string ObjectRemoteObject::DescriptionForSetIterator() +{ + std::string description = RemoteObject::SetIteratorDescription + "{}"; + return description; +} + +std::string ObjectRemoteObject::DescriptionForMapIterator() +{ + std::string description = RemoteObject::MapIteratorDescription + "{}"; + return description; } -std::string ObjectRemoteObject::DescriptionForArrayBuffer(const EcmaVM *ecmaVm, const Local &tagged) +std::string ObjectRemoteObject::DescriptionForArrayBuffer(const EcmaVM *ecmaVm, Local tagged) { int32_t len = tagged->ByteLength(ecmaVm); std::string description = ("ArrayBuffer(" + std::to_string(len) + ")"); return description; } -std::string SymbolRemoteObject::DescriptionForSymbol(const EcmaVM *ecmaVm, const Local &tagged) const +std::string ObjectRemoteObject::DescriptionForPrimitiveNumber(const EcmaVM *ecmaVm, const Local &tagged) +{ + std::string strValue = tagged->ToString(ecmaVm)->ToString(); + std::string description = RemoteObject::JSPrimitiveNumberDescription + "{[[PrimitiveValue]]: " + strValue + "}"; + return description; +} + +std::string ObjectRemoteObject::DescriptionForPrimitiveString(const EcmaVM *ecmaVm, const Local &tagged) +{ + std::string strValue = tagged->ToString(ecmaVm)->ToString(); + std::string description = RemoteObject::JSPrimitiveStringDescription + "{[[PrimitiveValue]]: " + strValue + "}"; + return description; +} + +std::string ObjectRemoteObject::DescriptionForPrimitiveBoolean(const EcmaVM *ecmaVm, const Local &tagged) +{ + std::string strValue = tagged->ToString(ecmaVm)->ToString(); + std::string description = RemoteObject::JSPrimitiveBooleanDescription + "{[[PrimitiveValue]]: " + strValue + "}"; + return description; +} + +std::string SymbolRemoteObject::DescriptionForSymbol(const EcmaVM *ecmaVm, Local tagged) const { - std::string description = - "Symbol(" + DebuggerApi::ToStdString(tagged->GetDescription(ecmaVm)) + ")"; + std::string description = "Symbol(" + tagged->GetDescription(ecmaVm)->ToString() + ")"; return description; } -std::string FunctionRemoteObject::DescriptionForFunction(const EcmaVM *ecmaVm, const Local &tagged) const +std::string FunctionRemoteObject::DescriptionForFunction(const EcmaVM *ecmaVm, Local tagged) const { std::string sourceCode; if (tagged->IsNative(ecmaVm)) { @@ -304,93 +414,10 @@ std::string FunctionRemoteObject::DescriptionForFunction(const EcmaVM *ecmaVm, c sourceCode = "[js code]"; } Local name = tagged->GetName(ecmaVm); - std::string description = "function " + DebuggerApi::ToStdString(name) + "( { " + sourceCode + " }"; + std::string description = "function " + name->ToString() + "( { " + sourceCode + " }"; return description; } -std::unique_ptr RemoteObject::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create params is nullptr"; - return nullptr; - } - std::string error; - auto remoteObject = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "type"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - auto type = DebuggerApi::ToStdString(result); - if (ObjectType::Valid(type)) { - remoteObject->type_ = type; - } else { - error += "'type' is invalid;"; - } - } else { - error += "'type' should be a String;"; - } - } else { - error += "should contain 'type';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "subtype"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - auto type = DebuggerApi::ToStdString(result); - if (ObjectSubType::Valid(type)) { - remoteObject->subType_ = type; - } else { - error += "'subtype' is invalid;"; - } - } else { - error += "'subtype' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "className"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - remoteObject->className_ = DebuggerApi::ToStdString(result); - } else { - error += "'className' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - remoteObject->value_ = result; - } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - remoteObject->unserializableValue_ = DebuggerApi::ToStdString(result); - } else { - error += "'unserializableValue' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "description"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - remoteObject->description_ = DebuggerApi::ToStdString(result); - } else { - error += "'description' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - remoteObject->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create " << error; - return nullptr; - } - - return remoteObject; -} - std::unique_ptr RemoteObject::Create(const PtJson ¶ms) { std::string error; @@ -454,52 +481,13 @@ std::unique_ptr RemoteObject::Create(const PtJson ¶ms) } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "RemoteObject::Create " << error; + LOG_DEBUGGER(ERROR) << "RemoteObject::Create " << error; return nullptr; } return remoteObject; } -Local RemoteObject::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "type")), - Local(StringRef::NewFromUtf8(ecmaVm, type_.c_str()))); - if (subType_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "subtype")), - Local(StringRef::NewFromUtf8(ecmaVm, subType_->c_str()))); - } - if (className_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "className")), - Local(StringRef::NewFromUtf8(ecmaVm, className_->c_str()))); - } - if (value_) { - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value")), value_.value()); - } - if (unserializableValue_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue")), - Local(StringRef::NewFromUtf8(ecmaVm, unserializableValue_->c_str()))); - } - if (description_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "description")), - Local(StringRef::NewFromUtf8(ecmaVm, description_->c_str()))); - } - if (objectId_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_.value()).c_str()))); - } - - return params; -} - std::unique_ptr RemoteObject::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); @@ -524,103 +512,6 @@ std::unique_ptr RemoteObject::ToJson() const return result; } -std::unique_ptr ExceptionDetails::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "ExceptionDetails::Create params is nullptr"; - return nullptr; - } - std::string error; - auto exceptionDetails = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "exceptionId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - exceptionDetails->exceptionId_ = static_cast(Local(result)->Value()); - } else { - error += "'exceptionId' should be a Number;"; - } - } else { - error += "should contain 'exceptionId';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "text"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - exceptionDetails->text_ = DebuggerApi::ToStdString(result); - } else { - error += "'text' should be a String;"; - } - } else { - error += "should contain 'text';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - exceptionDetails->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } - } else { - error += "should contain 'lineNumber';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - exceptionDetails->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } - } else { - error += "should contain 'columnNumber';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - exceptionDetails->scriptId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'scriptId' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - exceptionDetails->url_ = DebuggerApi::ToStdString(result); - } else { - error += "'url' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "exception"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'exception' format error;"; - } else { - exceptionDetails->exception_ = std::move(obj); - } - } else { - error += "'exception' should be an Object;"; - } - } - - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "executionContextId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - exceptionDetails->executionContextId_ = static_cast(Local(result)->Value()); - } else { - error += "'executionContextId' should be a Number;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ExceptionDetails::Create " << error; - return nullptr; - } - - return exceptionDetails; -} - std::unique_ptr ExceptionDetails::Create(const PtJson ¶ms) { std::string error; @@ -643,18 +534,18 @@ std::unique_ptr ExceptionDetails::Create(const PtJson ¶ms) error += "Unknown 'text';"; } - int32_t line; - ret = params.GetInt("lineNumber", &line); + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - exceptionDetails->line_ = line; + exceptionDetails->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } - int32_t column; - ret = params.GetInt("columnNumber", &column); + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - exceptionDetails->column_ = column; + exceptionDetails->columnNumber_ = columnNumber; } else { error += "Unknown 'columnNumber';"; } @@ -679,10 +570,10 @@ std::unique_ptr ExceptionDetails::Create(const PtJson ¶ms) ret = params.GetObject("exception", &exception); if (ret == Result::SUCCESS) { std::unique_ptr obj = RemoteObject::Create(*exception); - if (obj != nullptr) { - exceptionDetails->exception_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'exception' format error;"; + } else { + exceptionDetails->exception_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'exception';"; @@ -697,60 +588,21 @@ std::unique_ptr ExceptionDetails::Create(const PtJson ¶ms) } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ExceptionDetails::Create " << error; + LOG_DEBUGGER(ERROR) << "ExceptionDetails::Create " << error; return nullptr; } return exceptionDetails; } -Local ExceptionDetails::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "exceptionId")), - IntegerRef::New(ecmaVm, exceptionId_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "text")), - Local(StringRef::NewFromUtf8(ecmaVm, text_.c_str()))); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_)); - if (scriptId_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_.value()).c_str()))); - } - if (url_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_->c_str()))); - } - if (exception_) { - ASSERT(exception_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "exception")), - Local(exception_.value()->ToObject(ecmaVm))); - } - if (executionContextId_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "executionContextId")), - IntegerRef::New(ecmaVm, executionContextId_.value())); - } - - return params; -} - std::unique_ptr ExceptionDetails::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("exceptionId", exceptionId_); result->Add("text", text_.c_str()); - result->Add("lineNumber", line_); - result->Add("columnNumber", column_); + result->Add("lineNumber", lineNumber_); + result->Add("columnNumber", columnNumber_); if (scriptId_) { result->Add("scriptId", std::to_string(scriptId_.value()).c_str()); @@ -758,7 +610,8 @@ std::unique_ptr ExceptionDetails::ToJson() const if (url_) { result->Add("url", url_->c_str()); } - if (exception_ && exception_.value() != nullptr) { + if (exception_) { + ASSERT(exception_.value() != nullptr); result->Add("exception", exception_.value()->ToJson()); } if (executionContextId_) { @@ -768,48 +621,6 @@ std::unique_ptr ExceptionDetails::ToJson() const return result; } -std::unique_ptr InternalPropertyDescriptor::Create(const EcmaVM *ecmaVm, - const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "InternalPropertyDescriptor::Create params is nullptr"; - return nullptr; - } - std::string error; - auto internalPropertyDescriptor = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - internalPropertyDescriptor->name_ = DebuggerApi::ToStdString(result); - } else { - error += "'name' should be a String;"; - } - } else { - error += "should contain 'name';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'value' format error;"; - } else { - internalPropertyDescriptor->value_ = std::move(obj); - } - } else { - error += "'value' should be an Object;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "InternalPropertyDescriptor::Create " << error; - return nullptr; - } - - return internalPropertyDescriptor; -} - std::unique_ptr InternalPropertyDescriptor::Create(const PtJson ¶ms) { std::string error; @@ -828,120 +639,36 @@ std::unique_ptr InternalPropertyDescriptor::Create(c ret = params.GetObject("value", &value); if (ret == Result::SUCCESS) { std::unique_ptr obj = RemoteObject::Create(*value); - if (obj != nullptr) { - internalPropertyDescriptor->value_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'value' format error;"; + } else { + internalPropertyDescriptor->value_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'value';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "InternalPropertyDescriptor::Create " << error; + LOG_DEBUGGER(ERROR) << "InternalPropertyDescriptor::Create " << error; return nullptr; } return internalPropertyDescriptor; } -Local InternalPropertyDescriptor::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "name")), - Local(StringRef::NewFromUtf8(ecmaVm, name_.c_str()))); - if (value_) { - ASSERT(value_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "value")), - Local(value_.value()->ToObject(ecmaVm))); - } - - return params; -} - std::unique_ptr InternalPropertyDescriptor::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("name", name_.c_str()); - if (value_ && value_.value() != nullptr) { + if (value_) { + ASSERT(value_.value() != nullptr); result->Add("value", value_.value()->ToJson()); } return result; } -std::unique_ptr PrivatePropertyDescriptor::Create(const EcmaVM *ecmaVm, - const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "PrivatePropertyDescriptor::Create params is nullptr"; - return nullptr; - } - std::string error; - auto propertyDescriptor = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - propertyDescriptor->name_ = DebuggerApi::ToStdString(result); - } else { - error += "'name' should be a String;"; - } - } else { - error += "should contain 'name';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'value' format error;"; - } else { - propertyDescriptor->value_ = std::move(obj); - } - } else { - error += "'value' should be a Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "get"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'get' format error;"; - } else { - propertyDescriptor->get_ = std::move(obj); - } - } else { - error += "'get' should be an Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "set"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'set' format error;"; - } else { - propertyDescriptor->set_ = std::move(obj); - } - } else { - error += "'set' should be an Object;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "PrivatePropertyDescriptor::Create " << error; - return nullptr; - } - - return propertyDescriptor; -} - std::unique_ptr PrivatePropertyDescriptor::Create(const PtJson ¶ms) { std::string error; @@ -961,10 +688,10 @@ std::unique_ptr PrivatePropertyDescriptor::Create(con std::unique_ptr obj; if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*value); - if (obj != nullptr) { - privatePropertyDescriptor->value_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'value' format error;"; + } else { + privatePropertyDescriptor->value_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'value';"; @@ -974,10 +701,10 @@ std::unique_ptr PrivatePropertyDescriptor::Create(con ret = params.GetObject("get", &get); if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*get); - if (obj != nullptr) { - privatePropertyDescriptor->get_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'get' format error;"; + } else { + privatePropertyDescriptor->get_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'get';"; @@ -987,64 +714,38 @@ std::unique_ptr PrivatePropertyDescriptor::Create(con ret = params.GetObject("set", &set); if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*set); - if (obj != nullptr) { - privatePropertyDescriptor->set_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'set' format error;"; + } else { + privatePropertyDescriptor->set_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'set';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "PrivatePropertyDescriptor::Create " << error; + LOG_DEBUGGER(ERROR) << "PrivatePropertyDescriptor::Create " << error; return nullptr; } return privatePropertyDescriptor; } -Local PrivatePropertyDescriptor::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr PrivatePropertyDescriptor::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "name")), - Local(StringRef::NewFromUtf8(ecmaVm, name_.c_str()))); + result->Add("name", name_.c_str()); if (value_) { ASSERT(value_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "value")), - Local(value_.value()->ToObject(ecmaVm))); + result->Add("value", value_.value()->ToJson()); } if (get_) { ASSERT(get_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "get")), - Local(get_.value()->ToObject(ecmaVm))); + result->Add("get", get_.value()->ToJson()); } if (set_) { ASSERT(set_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "set")), - Local(set_.value()->ToObject(ecmaVm))); - } - - return params; -} - -std::unique_ptr PrivatePropertyDescriptor::ToJson() const -{ - std::unique_ptr result = PtJson::CreateObject(); - - result->Add("name", name_.c_str()); - if (value_ && value_.value() != nullptr) { - result->Add("value", value_.value()->ToJson()); - } - if (get_ && get_.value() != nullptr) { - result->Add("get", get_.value()->ToJson()); - } - if (set_ && set_.value() != nullptr) { result->Add("set", set_.value()->ToJson()); } @@ -1052,18 +753,17 @@ std::unique_ptr PrivatePropertyDescriptor::ToJson() const } std::unique_ptr PropertyDescriptor::FromProperty(const EcmaVM *ecmaVm, - const Local &name, const PropertyAttribute &property) + Local name, const PropertyAttribute &property) { std::unique_ptr debuggerProperty = std::make_unique(); std::string nameStr; if (name->IsSymbol()) { Local symbol(name); - nameStr = - "Symbol(" + DebuggerApi::ToStdString(Local(name)->GetDescription(ecmaVm)) + ")"; + nameStr = "Symbol(" + Local(name)->GetDescription(ecmaVm)->ToString() + ")"; debuggerProperty->symbol_ = RemoteObject::FromTagged(ecmaVm, name); } else { - nameStr = DebuggerApi::ToStdString(name->ToString(ecmaVm)); + nameStr = name->ToString(ecmaVm)->ToString(); } debuggerProperty->name_ = nameStr; @@ -1086,130 +786,6 @@ std::unique_ptr PropertyDescriptor::FromProperty(const EcmaV return debuggerProperty; } -std::unique_ptr PropertyDescriptor::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "PropertyDescriptor::Create params is nullptr"; - return nullptr; - } - std::string error; - auto propertyDescriptor = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - propertyDescriptor->name_ = DebuggerApi::ToStdString(result); - } else { - error += "'name' should be a String;"; - } - } else { - error += "should contain 'name';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'value' format error;"; - } else { - propertyDescriptor->value_ = std::move(obj); - } - } else { - error += "'value' should be an Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "writable"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - propertyDescriptor->writable_ = result->IsTrue(); - } else { - error += "'writable' should be a Boolean;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "get"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'get' format error;"; - } else { - propertyDescriptor->get_ = std::move(obj); - } - } else { - error += "'get' should be an Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "set"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'set' format error;"; - } else { - propertyDescriptor->set_ = std::move(obj); - } - } else { - error += "'set' should be an Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "configurable"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - propertyDescriptor->configurable_ = result->IsTrue(); - } else { - error += "'configurable' should be a Boolean;"; - } - } else { - error += "should contain 'configurable';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "enumerable"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - propertyDescriptor->enumerable_ = result->IsTrue(); - } else { - error += "'enumerable' should be a Boolean;"; - } - } else { - error += "should contain 'enumerable';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "wasThrown"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - propertyDescriptor->wasThrown_ = result->IsTrue(); - } else { - error += "'wasThrown' should be a Boolean;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "isOwn"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - propertyDescriptor->isOwn_ = result->IsTrue(); - } else { - error += "'isOwn' should be a Boolean;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "symbol"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'symbol' format error;"; - } else { - propertyDescriptor->symbol_ = std::move(obj); - } - } else { - error += "'symbol' should be an Object;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "PropertyDescriptor::Create " << error; - return nullptr; - } - - return propertyDescriptor; -} - std::unique_ptr PropertyDescriptor::Create(const PtJson ¶ms) { std::string error; @@ -1229,10 +805,10 @@ std::unique_ptr PropertyDescriptor::Create(const PtJson &par ret = params.GetObject("value", &value); if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*value); - if (obj != nullptr) { - propertyDescriptor->value_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'value' format error;"; + } else { + propertyDescriptor->value_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'value';"; @@ -1250,10 +826,10 @@ std::unique_ptr PropertyDescriptor::Create(const PtJson &par ret = params.GetObject("get", &get); if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*get); - if (obj != nullptr) { - propertyDescriptor->get_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'get' format error;"; + } else { + propertyDescriptor->get_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'get';"; @@ -1263,10 +839,10 @@ std::unique_ptr PropertyDescriptor::Create(const PtJson &par ret = params.GetObject("set", &set); if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*set); - if (obj != nullptr) { - propertyDescriptor->set_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'set' format error;"; + } else { + propertyDescriptor->set_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'set';"; @@ -1308,93 +884,41 @@ std::unique_ptr PropertyDescriptor::Create(const PtJson &par ret = params.GetObject("symbol", &symbol); if (ret == Result::SUCCESS) { obj = RemoteObject::Create(*symbol); - if (obj != nullptr) { - propertyDescriptor->symbol_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'symbol' format error;"; + } else { + propertyDescriptor->symbol_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'symbol';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "PropertyDescriptor::Create " << error; + LOG_DEBUGGER(ERROR) << "PropertyDescriptor::Create " << error; return nullptr; } return propertyDescriptor; } -Local PropertyDescriptor::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "name")), - Local(StringRef::NewFromUtf8(ecmaVm, name_.c_str()))); - if (value_) { - ASSERT(value_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "value")), - Local(value_.value()->ToObject(ecmaVm))); - } - if (writable_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "writable")), - BooleanRef::New(ecmaVm, writable_.value())); - } - if (get_) { - ASSERT(get_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "get")), - Local(get_.value()->ToObject(ecmaVm))); - } - if (set_) { - ASSERT(set_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "set")), - Local(set_.value()->ToObject(ecmaVm))); - } - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "configurable")), - BooleanRef::New(ecmaVm, configurable_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "enumerable")), - BooleanRef::New(ecmaVm, enumerable_)); - if (wasThrown_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "wasThrown")), - BooleanRef::New(ecmaVm, wasThrown_.value())); - } - if (isOwn_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "isOwn")), - BooleanRef::New(ecmaVm, isOwn_.value())); - } - if (symbol_) { - ASSERT(symbol_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "symbol")), - Local(symbol_.value()->ToObject(ecmaVm))); - } - - return params; -} - std::unique_ptr PropertyDescriptor::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("name", name_.c_str()); - if (value_ && value_.value() != nullptr) { + if (value_) { + ASSERT(value_.value() != nullptr); result->Add("value", value_.value()->ToJson()); } if (writable_) { result->Add("writable", writable_.value()); } - if (get_ && get_.value() != nullptr) { + if (get_) { + ASSERT(get_.value() != nullptr); result->Add("get", get_.value()->ToJson()); } - if (set_ && set_.value() != nullptr) { + if (set_) { + ASSERT(set_.value() != nullptr); result->Add("set", set_.value()->ToJson()); } result->Add("configurable", configurable_); @@ -1405,103 +929,43 @@ std::unique_ptr PropertyDescriptor::ToJson() const if (isOwn_) { result->Add("isOwn", isOwn_.value()); } - if (symbol_ && symbol_.value() != nullptr) { + if (symbol_) { + ASSERT(symbol_.value() != nullptr); result->Add("symbol", symbol_.value()->ToJson()); } return result; } -std::unique_ptr CallArgument::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "CallArgument::Create params is nullptr"; - return nullptr; - } - std::string error; - auto callArgument = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - callArgument->value_ = result; - } - result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callArgument->unserializableValue_ = DebuggerApi::ToStdString(result); - } else { - error += "'unserializableValue' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "objectId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callArgument->objectId_ = static_cast(DebuggerApi::StringToInt(result)); - } else { - error += "'objectId' should be a String;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "CallArgument::Create " << error; - return nullptr; - } - - return callArgument; -} - std::unique_ptr CallArgument::Create(const PtJson ¶ms) { - std::string error; auto callArgument = std::make_unique(); + std::string error; Result ret; std::string unserializableValue; ret = params.GetString("unserializableValue", &unserializableValue); if (ret == Result::SUCCESS) { callArgument->unserializableValue_ = std::move(unserializableValue); - } else if (ret == Result::TYPE_ERROR) { + } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'unserializableValue';"; } - std::string objectId; ret = params.GetString("objectId", &objectId); if (ret == Result::SUCCESS) { callArgument->objectId_ = std::stoi(objectId); - } else if (ret == Result::TYPE_ERROR) { + } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'objectId';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "CallArgument::Create " << error; + LOG_DEBUGGER(ERROR) << "CallArgument::Create " << error; return nullptr; } return callArgument; } -Local CallArgument::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - if (value_) { - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "value")), value_.value()); - } - if (unserializableValue_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "unserializableValue")), - Local(StringRef::NewFromUtf8(ecmaVm, unserializableValue_->c_str()))); - } - if (objectId_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "objectId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(objectId_.value()).c_str()))); - } - - return params; -} - std::unique_ptr CallArgument::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); @@ -1516,52 +980,6 @@ std::unique_ptr CallArgument::ToJson() const return result; } -std::unique_ptr Location::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "Location::Create params is nullptr"; - return nullptr; - } - std::string error; - auto location = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - location->scriptId_ = DebuggerApi::StringToInt(result); - } else { - error += "'scriptId' should be a String;"; - } - } else { - error += "should contain 'scriptId';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - location->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } - } else { - error += "should contain 'lineNumber';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - location->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Location::Create " << error; - return nullptr; - } - - return location; -} - std::unique_ptr Location::Create(const PtJson ¶ms) { auto location = std::make_unique(); @@ -1575,190 +993,81 @@ std::unique_ptr Location::Create(const PtJson ¶ms) } else { error += "Unknown 'scriptId';"; } - int32_t line; - ret = params.GetInt("lineNumber", &line); + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - location->line_ = line; + location->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } - int32_t column; - ret = params.GetInt("columnNumber", &column); + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - location->column_ = column; + location->columnNumber_ = columnNumber; } else if (ret == Result::TYPE_ERROR) { // optional value error += "Unknown 'columnNumber';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Location::Create " << error; + LOG_DEBUGGER(ERROR) << "Location::Create " << error; return nullptr; } return location; } -Local Location::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); - if (column_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_.value())); - } - - return params; -} - std::unique_ptr Location::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("scriptId", std::to_string(scriptId_).c_str()); - result->Add("lineNumber", line_); - if (column_) { - result->Add("columnNumber", column_.value()); + result->Add("lineNumber", lineNumber_); + if (columnNumber_) { + result->Add("columnNumber", columnNumber_.value()); } return result; } -std::unique_ptr ScriptPosition::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "ScriptPosition::Create params is nullptr"; - return nullptr; - } - std::string error; - auto scriptPosition = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - scriptPosition->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } - } else { - error += "should contain 'lineNumber';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - scriptPosition->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } - } else { - error += "should contain 'columnNumber';"; - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ScriptPosition::Create " << error; - return nullptr; - } - - return scriptPosition; -} - std::unique_ptr ScriptPosition::Create(const PtJson ¶ms) { - std::string error; auto scriptPosition = std::make_unique(); + std::string error; Result ret; - int32_t line; - ret = params.GetInt("lineNumber", &line); + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - scriptPosition->line_ = line; + scriptPosition->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } - - int32_t column; - ret = params.GetInt("columnNumber", &column); + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - scriptPosition->column_ = column; + scriptPosition->columnNumber_ = columnNumber; } else { error += "Unknown 'columnNumber';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ScriptPosition::Create " << error; + LOG_DEBUGGER(ERROR) << "ScriptPosition::Create " << error; return nullptr; } return scriptPosition; } -Local ScriptPosition::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_)); - - return params; -} - std::unique_ptr ScriptPosition::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); - result->Add("lineNumber", line_); - result->Add("columnNumber", column_); + result->Add("lineNumber", lineNumber_); + result->Add("columnNumber", columnNumber_); return result; } -std::unique_ptr SearchMatch::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "SearchMatch::Create params is nullptr"; - return nullptr; - } - std::string error; - auto locationSearch = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - locationSearch->lineNumber_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } - } else { - error += "should contain 'lineNumber';"; - } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineContent"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - locationSearch->lineContent_ = DebuggerApi::ToStdString(result); - } else { - error += "'lineContent' should be a String;"; - } - } else { - error += "should contain 'lineContent';"; - } - - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SearchMatch::Create " << error; - return nullptr; - } - - return locationSearch; -} - std::unique_ptr SearchMatch::Create(const PtJson ¶ms) { std::string error; @@ -1782,25 +1091,13 @@ std::unique_ptr SearchMatch::Create(const PtJson ¶ms) } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SearchMatch::Create " << error; + LOG_DEBUGGER(ERROR) << "SearchMatch::Create " << error; return nullptr; } return locationSearch; } -Local SearchMatch::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, lineNumber_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "lineContent")), - Local(StringRef::NewFromUtf8(ecmaVm, lineContent_.c_str()))); - return params; -} - std::unique_ptr SearchMatch::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); @@ -1811,69 +1108,11 @@ std::unique_ptr SearchMatch::ToJson() const return result; } -std::unique_ptr LocationRange::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr LocationRange::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "BreakLocation::Create params is nullptr"; - return nullptr; - } std::string error; auto locationRange = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - locationRange->scriptId_ = DebuggerApi::StringToInt(result); - } else { - error += "'scriptId' should be a String;"; - } - } else { - error += "should contain 'scriptId';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "start"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = ScriptPosition::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'start' format error;"; - } else { - locationRange->start_ = std::move(obj); - } - } else { - error += "'start' should be an Object;"; - } - } else { - error += "should contain 'start';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "end"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = ScriptPosition::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'end' format error;"; - } else { - locationRange->end_ = std::move(obj); - } - } else { - error += "'end' should be an Object;"; - } - } else { - error += "should contain 'end';"; - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "LocationRange::Create " << error; - return nullptr; - } - - return locationRange; -} - -std::unique_ptr LocationRange::Create(const PtJson ¶ms) -{ - std::string error; - auto locationRange = std::make_unique(); - Result ret; + Result ret; std::string scriptId; ret = params.GetString("scriptId", &scriptId); @@ -1888,10 +1127,10 @@ std::unique_ptr LocationRange::Create(const PtJson ¶ms) ret = params.GetObject("start", &start); if (ret == Result::SUCCESS) { obj = ScriptPosition::Create(*start); - if (obj != nullptr) { - locationRange->start_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'start' format error;"; + } else { + locationRange->start_ = std::move(obj); } } else { error += "Unknown 'start';"; @@ -1901,115 +1140,36 @@ std::unique_ptr LocationRange::Create(const PtJson ¶ms) ret = params.GetObject("end", &end); if (ret == Result::SUCCESS) { obj = ScriptPosition::Create(*end); - if (obj != nullptr) { - locationRange->end_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'end' format error;"; + } else { + locationRange->end_ = std::move(obj); } } else { error += "Unknown 'end';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "LocationRange::Create " << error; + LOG_DEBUGGER(ERROR) << "LocationRange::Create " << error; return nullptr; } return locationRange; } -Local LocationRange::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); - ASSERT(start_ != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "object")), - Local(start_->ToObject(ecmaVm))); - ASSERT(end_ != nullptr); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "object")), - Local(end_->ToObject(ecmaVm))); - - return params; -} - std::unique_ptr LocationRange::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("scriptId", std::to_string(scriptId_).c_str()); - if (start_ != nullptr) { - result->Add("start", start_->ToJson()); - } - if (end_ != nullptr) { - result->Add("end", end_->ToJson()); - } + ASSERT(start_ != nullptr); + result->Add("start", start_->ToJson()); + ASSERT(end_ != nullptr); + result->Add("end", end_->ToJson()); return result; } -std::unique_ptr BreakLocation::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "BreakLocation::Create params is nullptr"; - return nullptr; - } - std::string error; - auto breakLocation = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - breakLocation->scriptId_ = DebuggerApi::StringToInt(result); - } else { - error += "'scriptId' should be a String;"; - } - } else { - error += "should contain 'scriptId';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - breakLocation->line_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } - } else { - error += "should contain 'lineNumber';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - breakLocation->column_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "type"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - auto type = DebuggerApi::ToStdString(result); - if (BreakType::Valid(type)) { - breakLocation->type_ = type; - } else { - error += "'type' is invalid;"; - } - } else { - error += "'type' should be a String;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Location::Create " << error; - return nullptr; - } - - return breakLocation; -} - std::unique_ptr BreakLocation::Create(const PtJson ¶ms) { std::string error; @@ -2027,7 +1187,7 @@ std::unique_ptr BreakLocation::Create(const PtJson ¶ms) int32_t lineNumber; ret = params.GetInt("lineNumber", &lineNumber); if (ret == Result::SUCCESS) { - breakLocation->line_ = lineNumber; + breakLocation->lineNumber_ = lineNumber; } else { error += "Unknown 'lineNumber';"; } @@ -2035,7 +1195,7 @@ std::unique_ptr BreakLocation::Create(const PtJson ¶ms) int32_t columnNumber; ret = params.GetInt("columnNumber", &columnNumber); if (ret == Result::SUCCESS) { - breakLocation->column_ = columnNumber; + breakLocation->columnNumber_ = columnNumber; } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'columnNumber';"; } @@ -2053,44 +1213,21 @@ std::unique_ptr BreakLocation::Create(const PtJson ¶ms) } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Location::Create " << error; + LOG_DEBUGGER(ERROR) << "Location::Create " << error; return nullptr; } return breakLocation; } -Local BreakLocation::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(scriptId_).c_str()))); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, line_)); - if (column_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, column_.value())); - } - if (type_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "type")), - Local(StringRef::NewFromUtf8(ecmaVm, type_->c_str()))); - } - - return params; -} - std::unique_ptr BreakLocation::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("scriptId", std::to_string(scriptId_).c_str()); - result->Add("lineNumber", line_); - if (column_) { - result->Add("columnNumber", column_.value()); + result->Add("lineNumber", lineNumber_); + if (columnNumber_) { + result->Add("columnNumber", columnNumber_.value()); } if (type_) { result->Add("type", type_->c_str()); @@ -2099,88 +1236,6 @@ std::unique_ptr BreakLocation::ToJson() const return result; } -std::unique_ptr Scope::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "Scope::Create params is nullptr"; - return nullptr; - } - std::string error; - auto scope = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "type"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - auto type = DebuggerApi::ToStdString(result); - if (Scope::Type::Valid(type)) { - scope->type_ = type; - } else { - error += "'type' is invalid;"; - } - } else { - error += "'type' should be a String;"; - } - } else { - error += "should contain 'type';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "object"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'object' format error;"; - } else { - scope->object_ = std::move(obj); - } - } else { - error += "'object' should be an Object;"; - } - } else { - error += "should contain 'object';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - scope->name_ = DebuggerApi::ToStdString(result); - } else { - error += "'name' should be a String;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "startLocation"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'startLocation' format error;"; - } else { - scope->startLocation_ = std::move(obj); - } - } else { - error += "'startLocation' should be an Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endLocation"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'endLocation' format error;"; - } else { - scope->endLocation_ = std::move(obj); - } - } else { - error += "'endLocation' should be an Object;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Location::Create " << error; - return nullptr; - } - - return scope; -} - std::unique_ptr Scope::Create(const PtJson ¶ms) { std::string error; @@ -2204,10 +1259,10 @@ std::unique_ptr Scope::Create(const PtJson ¶ms) ret = params.GetObject("object", &object); if (ret == Result::SUCCESS) { remoteObject = RemoteObject::Create(*object); - if (remoteObject != nullptr) { - scope->object_ = std::move(remoteObject); - } else { + if (remoteObject == nullptr) { error += "'object' format error;"; + } else { + scope->object_ = std::move(remoteObject); } } else { error += "Unknown 'object';"; @@ -2226,10 +1281,10 @@ std::unique_ptr Scope::Create(const PtJson ¶ms) ret = params.GetObject("startLocation", &startLocation); if (ret == Result::SUCCESS) { obj = Location::Create(*startLocation); - if (obj != nullptr) { - scope->startLocation_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'startLocation' format error;"; + } else { + scope->startLocation_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'startLocation';"; @@ -2239,202 +1294,45 @@ std::unique_ptr Scope::Create(const PtJson ¶ms) ret = params.GetObject("endLocation", &endLocation); if (ret == Result::SUCCESS) { obj = Location::Create(*endLocation); - if (obj != nullptr) { - scope->endLocation_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'endLocation' format error;"; + } else { + scope->endLocation_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'endLocation';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Location::Create " << error; + LOG_DEBUGGER(ERROR) << "Location::Create " << error; return nullptr; } return scope; } -Local Scope::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "type")), - Local(StringRef::NewFromUtf8(ecmaVm, type_.c_str()))); - ASSERT(object_ != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "object")), - Local(object_->ToObject(ecmaVm))); - if (name_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "name")), - Local(StringRef::NewFromUtf8(ecmaVm, name_->c_str()))); - } - if (startLocation_) { - ASSERT(startLocation_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "startLocation")), - Local(startLocation_.value()->ToObject(ecmaVm))); - } - if (endLocation_) { - ASSERT(endLocation_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "endLocation")), - Local(endLocation_.value()->ToObject(ecmaVm))); - } - - return params; -} - std::unique_ptr Scope::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); result->Add("type", type_.c_str()); - if (object_ != nullptr) { - result->Add("object", object_->ToJson()); - } + ASSERT(object_ != nullptr); + result->Add("object", object_->ToJson()); if (name_) { result->Add("name", name_->c_str()); } - if (startLocation_ && startLocation_.value() != nullptr) { + if (startLocation_) { + ASSERT(startLocation_.value() != nullptr); result->Add("startLocation", startLocation_.value()->ToJson()); } - if (endLocation_ && endLocation_.value() != nullptr) { + if (endLocation_) { + ASSERT(endLocation_.value() != nullptr); result->Add("endLocation", endLocation_.value()->ToJson()); } return result; } -std::unique_ptr CallFrame::Create(const EcmaVM *ecmaVm, const Local ¶ms) -{ - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "CallFrame::Create params is nullptr"; - return nullptr; - } - std::string error; - auto callFrame = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callFrame->callFrameId_ = DebuggerApi::StringToInt(result); - } else { - error += "'callFrameId' should be a String;"; - } - } else { - error += "should contain 'callFrameId';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functionName"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callFrame->functionName_ = DebuggerApi::ToStdString(result); - } else { - error += "'functionName' should be a String;"; - } - } else { - error += "should contain 'functionName';"; - } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functionLocation"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'functionLocation' format error;"; - } else { - callFrame->functionLocation_ = std::move(obj); - } - } else { - error += "'functionLocation' should be an Object;"; - } - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "location"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = Location::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'location' format error;"; - } else { - callFrame->location_ = std::move(obj); - } - } else { - error += "'location' should be an Object;"; - } - } else { - error += "should contain 'location';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - callFrame->url_ = DebuggerApi::ToStdString(result); - } else { - error += "'url' should be a String;"; - } - } else { - error += "should contain 'url';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scopeChain"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr scope = Scope::Create(ecmaVm, resultValue); - if (resultValue.IsEmpty() || scope == nullptr) { - error += "'scopeChain' format invalid;"; - } - callFrame->scopeChain_.emplace_back(std::move(scope)); - } - } else { - error += "'scopeChain' should be an Array;"; - } - } else { - error += "should contain 'scopeChain';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "this"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'this' format error;"; - } else { - callFrame->this_ = std::move(obj); - } - } else { - error += "'this' should be an Object;"; - } - } else { - error += "should contain 'this';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "returnValue"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RemoteObject::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'returnValue' format error;"; - } else { - callFrame->returnValue_ = std::move(obj); - } - } else { - error += "'returnValue' should be an Object;"; - } - } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "CallFrame::Create " << error; - return nullptr; - } - - return callFrame; -} - std::unique_ptr CallFrame::Create(const PtJson ¶ms) { std::string error; @@ -2462,10 +1360,10 @@ std::unique_ptr CallFrame::Create(const PtJson ¶ms) ret = params.GetObject("functionLocation", &functionLocation); if (ret == Result::SUCCESS) { obj = Location::Create(*functionLocation); - if (obj != nullptr) { - callFrame->functionLocation_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'functionLocation' format error;"; + } else { + callFrame->functionLocation_ = std::move(obj); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'functionLocation';"; @@ -2475,10 +1373,10 @@ std::unique_ptr CallFrame::Create(const PtJson ¶ms) ret = params.GetObject("location", &location); if (ret == Result::SUCCESS) { obj = Location::Create(*location); - if (obj != nullptr) { - callFrame->location_ = std::move(obj); - } else { + if (obj == nullptr) { error += "'location' format error;"; + } else { + callFrame->location_ = std::move(obj); } } else { error += "Unknown 'location';"; @@ -2498,15 +1396,12 @@ std::unique_ptr CallFrame::Create(const PtJson ¶ms) int32_t len = scopeChain->GetSize(); for (int32_t i = 0; i < len; ++i) { std::unique_ptr arrayEle = scopeChain->Get(i); - if (arrayEle != nullptr) { - std::unique_ptr scope = Scope::Create(*arrayEle); - if (scope != nullptr) { - callFrame->scopeChain_.emplace_back(std::move(scope)); - } else { - error += "'scopeChain' format error;"; - } + ASSERT(arrayEle != nullptr); + std::unique_ptr scope = Scope::Create(*arrayEle); + if (scope == nullptr) { + error += "'scopeChain' format error;"; } else { - error += "Unknown 'scopeChain';"; + callFrame->scopeChain_.emplace_back(std::move(scope)); } } } else { @@ -2518,10 +1413,10 @@ std::unique_ptr CallFrame::Create(const PtJson ¶ms) ret = params.GetObject("this", &thisObj); if (ret == Result::SUCCESS) { remoteObject = RemoteObject::Create(*thisObj); - if (remoteObject != nullptr) { - callFrame->this_ = std::move(remoteObject); - } else { + if (remoteObject == nullptr) { error += "'this' format error;"; + } else { + callFrame->this_ = std::move(remoteObject); } } else { error += "Unknown 'this';"; @@ -2531,66 +1426,23 @@ std::unique_ptr CallFrame::Create(const PtJson ¶ms) ret = params.GetObject("returnValue", &returnValue); if (ret == Result::SUCCESS) { remoteObject = RemoteObject::Create(*returnValue); - if (remoteObject != nullptr) { - callFrame->returnValue_ = std::move(remoteObject); - } else { + if (remoteObject == nullptr) { error += "'returnValue' format error;"; + } else { + callFrame->returnValue_ = std::move(remoteObject); } } else if (ret == Result::TYPE_ERROR) { error += "Unknown 'returnValue';"; } if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "CallFrame::Create " << error; + LOG_DEBUGGER(ERROR) << "CallFrame::Create " << error; return nullptr; } return callFrame; } -Local CallFrame::ToObject(const EcmaVM *ecmaVm) const -{ - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "callFrameId")), - Local(StringRef::NewFromUtf8(ecmaVm, std::to_string(callFrameId_).c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionName")), - Local(StringRef::NewFromUtf8(ecmaVm, functionName_.c_str()))); - if (functionLocation_) { - ASSERT(functionLocation_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionLocation")), - Local(functionLocation_.value()->ToObject(ecmaVm))); - } - ASSERT(location_ != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "location")), - Local(location_->ToObject(ecmaVm))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); - size_t len = scopeChain_.size(); - Local values = ArrayRef::New(ecmaVm, len); - for (size_t i = 0; i < len; i++) { - Local scope = scopeChain_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, scope); - } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scopeChain")), values); - ASSERT(this_ != nullptr); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "this")), - Local(this_->ToObject(ecmaVm))); - if (returnValue_) { - ASSERT(returnValue_.value() != nullptr); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "returnValue")), - Local(returnValue_.value()->ToObject(ecmaVm))); - } - - return params; -} - std::unique_ptr CallFrame::ToJson() const { std::unique_ptr result = PtJson::CreateObject(); @@ -2598,165 +1450,126 @@ std::unique_ptr CallFrame::ToJson() const result->Add("callFrameId", std::to_string(callFrameId_).c_str()); result->Add("functionName", functionName_.c_str()); - if (functionLocation_ && functionLocation_.value() != nullptr) { + if (functionLocation_) { + ASSERT(functionLocation_.value() != nullptr); result->Add("functionLocation", functionLocation_.value()->ToJson()); } - if (location_ != nullptr) { - result->Add("location", location_->ToJson()); - } + ASSERT(location_ != nullptr); + result->Add("location", location_->ToJson()); result->Add("url", url_.c_str()); size_t len = scopeChain_.size(); std::unique_ptr values = PtJson::CreateArray(); for (size_t i = 0; i < len; i++) { + ASSERT(scopeChain_[i] != nullptr); std::unique_ptr scope = scopeChain_[i]->ToJson(); values->Push(scope); } result->Add("scopeChain", values); - if (this_ != nullptr) { - result->Add("this", this_->ToJson()); - } - if (returnValue_ && returnValue_.value() != nullptr) { + ASSERT(this_ != nullptr); + result->Add("this", this_->ToJson()); + if (returnValue_) { + ASSERT(returnValue_.value() != nullptr); result->Add("returnValue", returnValue_.value()->ToJson()); } return result; } -std::unique_ptr SamplingHeapProfileSample::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SamplingHeapProfileSample::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "SamplingHeapProfileSample::Create params is nullptr"; - return nullptr; - } std::string error; auto samplingHeapProfileSample = std::make_unique(); + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "size"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - samplingHeapProfileSample->size_ = static_cast(Local(result)->Value()); - } else { - error += "'size' should be a Number;"; - } + int32_t size; + ret = params.GetInt("size", &size); + if (ret == Result::SUCCESS) { + samplingHeapProfileSample->size_ = size; } else { - error += "should contain 'size';"; + error += "Unknown 'size';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ordinal"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - samplingHeapProfileSample->ordinal_ = static_cast(Local(result)->Value()); - } else { - error += "'ordinal' should be a Number;"; - } + int32_t nodeId; + ret = params.GetInt("nodeId", &nodeId); + if (ret == Result::SUCCESS) { + samplingHeapProfileSample->nodeId_ = nodeId; } else { - error += "should contain 'ordinal';"; + error += "Unknown 'nodeId';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "nodeId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - samplingHeapProfileSample->nodeId_ = static_cast(Local(result)->Value()); - } else { - error += "'nodeId' should be a Number;"; - } + int32_t ordinal; + ret = params.GetInt("ordinal", &ordinal); + if (ret == Result::SUCCESS) { + samplingHeapProfileSample->ordinal_ = ordinal; } else { - error += "should contain 'nodeId';"; + error += "Unknown 'ordinal';"; } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SamplingHeapProfileSample::Create " << error; + LOG_DEBUGGER(ERROR) << "SamplingHeapProfileSample::Create " << error; return nullptr; } return samplingHeapProfileSample; } -Local SamplingHeapProfileSample::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SamplingHeapProfileSample::ToJson() const { - Local params = NewObject(ecmaVm); + std::unique_ptr result = PtJson::CreateObject(); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "size")), - IntegerRef::New(ecmaVm, size_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ordinal")), - IntegerRef::New(ecmaVm, ordinal_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "nodeId")), - IntegerRef::New(ecmaVm, nodeId_)); + result->Add("size", size_); + result->Add("nodeId", nodeId_); + result->Add("ordinal", ordinal_); - return params; + return result; } -std::unique_ptr RuntimeCallFrame::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr RuntimeCallFrame::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "RuntimeCallFrame::Create params is nullptr"; - return nullptr; - } std::string error; auto runtimeCallFrame = std::make_unique(); - - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionName"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - runtimeCallFrame->functionName_ = DebuggerApi::ToStdString(result); - } else { - error += "'functionName' should be a String;"; - } + Result ret; + + std::string functionName; + ret = params.GetString("functionName", &functionName); + if (ret == Result::SUCCESS) { + runtimeCallFrame->functionName_ = std::move(functionName); } else { - error += "should contain 'functionName';"; + error += "Unknown 'functionName';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - runtimeCallFrame->scriptId_ = DebuggerApi::ToStdString(result); - } else { - error += "'scriptId' should be a String;"; - } + std::string scriptId; + ret = params.GetString("scriptId", &scriptId); + if (ret == Result::SUCCESS) { + runtimeCallFrame->scriptId_ = std::move(scriptId); } else { - error += "should contain 'scriptId';"; + error += "Unknown 'scriptId';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - runtimeCallFrame->url_ = DebuggerApi::ToStdString(result); - } else { - error += "'url' should be a String;"; - } + std::string url; + ret = params.GetString("url", &url); + if (ret == Result::SUCCESS) { + runtimeCallFrame->url_ = std::move(url); } else { - error += "should contain 'url';"; + error += "Unknown 'url';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - runtimeCallFrame->lineNumber_ = static_cast(Local(result)->Value()); - } else { - error += "'lineNumber' should be a Number;"; - } + + int32_t lineNumber; + ret = params.GetInt("lineNumber", &lineNumber); + if (ret == Result::SUCCESS) { + runtimeCallFrame->lineNumber_ = lineNumber; } else { - error += "should contain 'lineNumber';"; + error += "Unknown 'lineNumber';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - runtimeCallFrame->columnNumber_ = static_cast(Local(result)->Value()); - } else { - error += "'columnNumber' should be a Number;"; - } + int32_t columnNumber; + ret = params.GetInt("columnNumber", &columnNumber); + if (ret == Result::SUCCESS) { + runtimeCallFrame->columnNumber_ = columnNumber; } else { - error += "should contain 'columnNumber';"; + error += "Unknown 'columnNumber';"; } - if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "RuntimeCallFrame::Create " << error; + LOG_DEBUGGER(ERROR) << "RuntimeCallFrame::Create " << error; return nullptr; } @@ -2774,362 +1587,279 @@ std::unique_ptr RuntimeCallFrame::FromFrameInfo(const FrameInf return runtimeCallFrame; } -Local RuntimeCallFrame::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr RuntimeCallFrame::ToJson() const { - Local params = NewObject(ecmaVm); - - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionName")), - Local(StringRef::NewFromUtf8(ecmaVm, functionName_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); + std::unique_ptr result = PtJson::CreateObject(); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "lineNumber")), - IntegerRef::New(ecmaVm, lineNumber_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "columnNumber")), - IntegerRef::New(ecmaVm, columnNumber_)); + result->Add("functionName", functionName_.c_str()); + result->Add("scriptId", scriptId_.c_str()); + result->Add("url", url_.c_str()); + result->Add("lineNumber", lineNumber_); + result->Add("columnNumber", columnNumber_); - return params; + return result; } -std::unique_ptr SamplingHeapProfileNode::Create(const EcmaVM *ecmaVm, - const Local ¶ms) +std::unique_ptr SamplingHeapProfileNode::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "SamplingHeapProfileNode::Create params is nullptr"; - return nullptr; - } - std::string error; auto samplingHeapProfileNode = std::make_unique(); + Result ret; - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "callFrame"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RuntimeCallFrame::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'callFrame' format error;"; - } else { - samplingHeapProfileNode->callFrame_ = std::move(obj); - } + std::unique_ptr callFrame; + ret = params.GetObject("callFrame", &callFrame); + if (ret == Result::SUCCESS) { + std::unique_ptr runtimeCallFrame = RuntimeCallFrame::Create(*callFrame); + if (runtimeCallFrame == nullptr) { + error += "'callFrame' format invalid;"; } else { - error += "'callFrame' should be an Object;"; + samplingHeapProfileNode->callFrame_ = std::move(runtimeCallFrame); } } else { - error += "should contain 'callFrame';"; + error += "Unknown 'callFrame';"; } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "selfSize"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - samplingHeapProfileNode->selfSize_ = static_cast(Local(result)->Value()); - } else { - error += "'selfSize' should be a Number;"; - } + + int32_t selfSize; + ret = params.GetInt("selfSize", &selfSize); + if (ret == Result::SUCCESS) { + samplingHeapProfileNode->selfSize_ = selfSize; } else { - error += "should contain 'selfSize';"; + error += "Unknown 'selfSize';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "id"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - samplingHeapProfileNode->id_ = static_cast(Local(result)->Value()); - } else { - error += "'id' should be a Number;"; - } + int32_t id; + ret = params.GetInt("id", &id); + if (ret == Result::SUCCESS) { + samplingHeapProfileNode->id_ = id; } else { - error += "should contain 'id';"; - } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "children"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr node = SamplingHeapProfileNode::Create(ecmaVm, resultValue); - if (resultValue.IsEmpty() || node == nullptr) { - error += "'children' format invalid;"; - } + error += "Unknown 'id';"; + } + + std::unique_ptr children; + ret = params.GetArray("children", &children); + if (ret == Result::SUCCESS) { + int32_t len = children->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr arrayEle = children->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr node = SamplingHeapProfileNode::Create(*arrayEle); + if (node == nullptr) { + error += "'children' format invalid;"; + } else { samplingHeapProfileNode->children_.emplace_back(std::move(node)); } - } else { - error += "'children' should be an Array;"; } } else { - error += "should contain 'children';"; + error += "Unknown 'children';"; } - + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SamplingHeapProfileNode::Create " << error; + LOG_DEBUGGER(ERROR) << "SamplingHeapProfileNode::Create " << error; return nullptr; } return samplingHeapProfileNode; } -Local SamplingHeapProfileNode::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SamplingHeapProfileNode::ToJson() const { - Local params = NewObject(ecmaVm); - - if (callFrame_ != nullptr) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "callFrame")), - Local(callFrame_->ToObject(ecmaVm))); - } - - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "selfSize")), - IntegerRef::New(ecmaVm, selfSize_)); - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "id")), - IntegerRef::New(ecmaVm, id_)); + std::unique_ptr result = PtJson::CreateObject(); + ASSERT(callFrame_ != nullptr); + result->Add("callFrame", callFrame_->ToJson()); + result->Add("selfSize", selfSize_); + result->Add("id", id_); + std::unique_ptr childrens = PtJson::CreateArray(); size_t len = children_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - if (children_[i] != nullptr) { - Local node = children_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, node); - } + ASSERT(children_[i] != nullptr); + childrens->Push(children_[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "children")), values); + result->Add("children", childrens); - return params; + return result; } -std::unique_ptr SamplingHeapProfile::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr SamplingHeapProfile::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "SamplingHeapProfile::Create params is nullptr"; - return nullptr; - } std::string error; auto samplingHeapProfile = std::make_unique(); - - Local result = Local(params)->Get(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "head"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = SamplingHeapProfileNode::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'head' format error;"; - } else { - samplingHeapProfile->head_ = std::move(obj); - } + Result ret; + + std::unique_ptr head; + ret = params.GetObject("head", &head); + if (ret == Result::SUCCESS) { + std::unique_ptr pHead = SamplingHeapProfileNode::Create(*head); + if (pHead == nullptr) { + error += "'sample' format invalid;"; } else { - error += "'head' should be an Object;"; + samplingHeapProfile->head_ = std::move(pHead); } } else { - error += "should contain 'head';"; - } - - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "samples"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t len = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < len; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr node = SamplingHeapProfileSample::Create(ecmaVm, - resultValue); - if (resultValue.IsEmpty() || node == nullptr) { - error += "'samples' format invalid;"; - } - samplingHeapProfile->samples_.emplace_back(std::move(node)); + error += "Unknown 'head';"; + } + + std::unique_ptr samples; + ret = params.GetArray("samples", &samples); + if (ret == Result::SUCCESS) { + int32_t len = samples->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr arrayEle = samples->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr pSample = SamplingHeapProfileSample::Create(*arrayEle); + if (pSample == nullptr) { + error += "'sample' format invalid;"; + } else { + samplingHeapProfile->samples_.emplace_back(std::move(pSample)); } - } else { - error += "'samples' should be an Array;"; } } else { - error += "should contain 'samples';"; + error += "Unknown 'samples';"; } - + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "SamplingHeapProfile::Create " << error; + LOG_DEBUGGER(ERROR) << "SamplingHeapProfile::Create " << error; return nullptr; } return samplingHeapProfile; } -Local SamplingHeapProfile::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr SamplingHeapProfile::ToJson() const { - Local params = NewObject(ecmaVm); - - if (head_ != nullptr) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "head")), - Local(head_->ToObject(ecmaVm))); - } + std::unique_ptr result = PtJson::CreateObject(); + ASSERT(head_ != nullptr); + result->Add("head", head_->ToJson()); + + std::unique_ptr samples = PtJson::CreateArray(); size_t len = samples_.size(); - Local values = ArrayRef::New(ecmaVm, len); for (size_t i = 0; i < len; i++) { - if (samples_[i] != nullptr) { - Local node = samples_[i]->ToObject(ecmaVm); - values->Set(ecmaVm, i, node); - } + ASSERT(samples_[i] != nullptr); + samples->Push(samples_[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "samples")), values); - - return params; + result->Add("samples", samples); + return result; } -std::unique_ptr PositionTickInfo::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr PositionTickInfo::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "PositionTickInfo::Create params is nullptr"; - return nullptr; - } std::string error; - auto positionTicks = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "line"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - positionTicks->line_ = static_cast(Local(result)->Value()); - } else { - error += "'line' should be a Number;"; - } + auto positionTickInfo = std::make_unique(); + Result ret; + + int32_t line; + ret = params.GetInt("line", &line); + if (ret == Result::SUCCESS) { + positionTickInfo->line_ = line; } else { - error += "should contain 'line';"; + error += "Unknown 'line';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ticks"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - positionTicks->ticks_ = static_cast(Local(result)->Value()); - } else { - error += "'ticks' should be a Number;"; - } + + int32_t ticks; + ret = params.GetInt("ticks", &ticks); + if (ret == Result::SUCCESS) { + positionTickInfo->ticks_ = ticks; } else { - error += "should contain 'ticks';"; + error += "Unknown 'ticks';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "PositionTickInfo::Create " << error; + LOG_DEBUGGER(ERROR) << "PositionTickInfo::Create " << error; return nullptr; } - return positionTicks; + + return positionTickInfo; } -Local PositionTickInfo::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr PositionTickInfo::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "line")), - IntegerRef::New(ecmaVm, line_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "ticks")), - IntegerRef::New(ecmaVm, ticks_)); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("line", line_); + result->Add("ticks", ticks_); - return params; + return result; } -std::unique_ptr ProfileNode::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr ProfileNode::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "ProfileNode::Create params is nullptr"; - return nullptr; - } std::string error; auto profileNode = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "id"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - profileNode->id_ = static_cast(Local(result)->Value()); - } else { - error += "'id' should be a Number;"; - } + Result ret; + + int32_t id; + ret = params.GetInt("id", &id); + if (ret == Result::SUCCESS) { + profileNode->id_ = id; } else { - error += "should contain 'id';"; + error += "Unknown 'id';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "callFrame"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsObject()) { - std::unique_ptr obj = RuntimeCallFrame::Create(ecmaVm, result); - if (obj == nullptr) { - error += "'callFrame' format error;"; - } else { - profileNode->callFrame_ = std::move(obj); - } + + std::unique_ptr callFrame; + ret = params.GetObject("callFrame", &callFrame); + if (ret == Result::SUCCESS) { + std::unique_ptr runtimeCallFrame = RuntimeCallFrame::Create(*callFrame); + if (runtimeCallFrame == nullptr) { + error += "'callFrame' format invalid;"; } else { - error += "'callFrame' should be an Object;"; + profileNode->callFrame_ = std::move(runtimeCallFrame); } } else { - error += "should contain 'callFrame';"; + error += "Unknown 'callFrame';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "hitCount"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - profileNode->hitCount_ = static_cast(Local(result)->Value()); - } else { - error += "'hitCount' should be a Number;"; - } - } else { - error += "should contain 'hitCount';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "children"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t childrenLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < childrenLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - int32_t pChildren; - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - pChildren = resultValue->Int32Value(ecmaVm); - profileNode->children_.value()[i] = pChildren; - } - } else { - error += "'children' should be an Array;"; + + int32_t hitCount; + ret = params.GetInt("hitCount", &hitCount); + if (ret == Result::SUCCESS) { + profileNode->hitCount_ = hitCount; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'hitCount';"; + } + + std::unique_ptr children; + ret = params.GetArray("children", &children); + if (ret == Result::SUCCESS) { + int32_t childrenLen = children->GetSize(); + for (int32_t i = 0; i < childrenLen; ++i) { + int32_t pChildren = children->Get(i)->GetInt(); + profileNode->children_.value().emplace_back(pChildren); } - } else { - error += "should contain 'children';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "positionTicks"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t positionTickLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < positionTickLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr positionTick = PositionTickInfo::Create(ecmaVm, resultValue); - profileNode->positionTicks_->emplace_back(std::move(positionTick)); + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'children';"; + } + + std::unique_ptr positionTicks; + ret = params.GetArray("positionTicks", &positionTicks); + if (ret == Result::SUCCESS) { + int32_t positionTicksLen = positionTicks->GetSize(); + for (int32_t i = 0; i < positionTicksLen; ++i) { + std::unique_ptr arrayEle = positionTicks->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr tmpPositionTicks = PositionTickInfo::Create(*arrayEle); + if (tmpPositionTicks == nullptr) { + error += "'positionTicks' format invalid;"; + } else { + profileNode->positionTicks_.value().emplace_back(std::move(tmpPositionTicks)); } - } else { - error += "'positionTicks' should be an Array;"; } - } else { - error += "should contain 'positionTicks';"; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'positionTicks';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "deoptReason"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - profileNode->deoptReason_ = DebuggerApi::ToStdString(result); - } else { - error += "'deoptReason' should be a String;"; - } - } else { - error += "should contain 'deoptReason_';"; + + std::string deoptReason; + ret = params.GetString("deoptReason", &deoptReason); + if (ret == Result::SUCCESS) { + profileNode->deoptReason_ = std::move(deoptReason); + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'deoptReason';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ProfileNode::Create " << error; + LOG_DEBUGGER(ERROR) << "ProfileNode::Create " << error; return nullptr; } + return profileNode; } @@ -3142,7 +1872,7 @@ std::unique_ptr ProfileNode::FromCpuProfileNode(const CpuProfileNod size_t childrenLen = cpuProfileNode.children.size(); std::vector tmpChildren; tmpChildren.reserve(childrenLen); - for (uint32_t i = 0; i < childrenLen; ++i) { + for (size_t i = 0; i < childrenLen; ++i) { tmpChildren.push_back(cpuProfileNode.children[i]); } profileNode->SetChildren(tmpChildren); @@ -3150,141 +1880,110 @@ std::unique_ptr ProfileNode::FromCpuProfileNode(const CpuProfileNod return profileNode; } -Local ProfileNode::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ProfileNode::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "id")), - IntegerRef::New(ecmaVm, id_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "callFrame")), - Local(callFrame_->ToObject(ecmaVm))); - + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("id", id_); + ASSERT(callFrame_ != nullptr); + result->Add("callFrame", callFrame_->ToJson()); if (hitCount_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "hitCount")), - IntegerRef::New(ecmaVm, hitCount_.value())); + result->Add("hitCount", hitCount_.value()); } - if (children_) { - size_t childrenLen = children_->size(); - Local childrenValues = ArrayRef::New(ecmaVm, childrenLen); - for (size_t i = 0; i < childrenLen; i++) { - Local elem = IntegerRef::New(ecmaVm, children_.value()[i]); - childrenValues->Set(ecmaVm, i, elem); + std::unique_ptr childrens = PtJson::CreateArray(); + size_t len = children_->size(); + for (size_t i = 0; i < len; i++) { + childrens->Push(children_.value()[i]); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "children")), childrenValues); + result->Add("children", childrens); } - if (positionTicks_) { - size_t positionTickLen = positionTicks_->size(); - Local positionValues = ArrayRef::New(ecmaVm, positionTickLen); - for (size_t i = 0; i < positionTickLen; i++) { - Local positionTick = positionTicks_.value()[i]->ToObject(ecmaVm); - positionValues->Set(ecmaVm, i, positionTick); + std::unique_ptr positionTicks = PtJson::CreateArray(); + size_t len = positionTicks_->size(); + for (size_t i = 0; i < len; i++) { + ASSERT(positionTicks_.value()[i] != nullptr); + positionTicks->Push(positionTicks_.value()[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "positionTicks")), positionValues); + result->Add("positionTicks", positionTicks); } - + if (deoptReason_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "deoptReason")), - Local(StringRef::NewFromUtf8(ecmaVm, deoptReason_->c_str()))); + result->Add("deoptReason", deoptReason_.value().c_str()); } - return params; + return result; } -std::unique_ptr Profile::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr Profile::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "Profile::Create params is nullptr"; - return nullptr; - } std::string error; auto profile = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "nodes"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t nodesLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < nodesLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr node = ProfileNode::Create(ecmaVm, resultValue); - profile->nodes_.emplace_back(std::move(node)); + Result ret; + + std::unique_ptr nodes; + ret = params.GetArray("nodes", &nodes); + if (ret == Result::SUCCESS) { + int32_t nodesLen = nodes->GetSize(); + for (int32_t i = 0; i < nodesLen; ++i) { + std::unique_ptr arrayEle = nodes->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr profileNode = ProfileNode::Create(*arrayEle); + if (profileNode == nullptr) { + error += "'nodes' format invalid;"; + } else { + profile->nodes_.emplace_back(std::move(profileNode)); } - } else { - error += "'nodes' should be an Array;"; } } else { - error += "should contain 'nodes';"; + error += "Unknown 'nodes';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "startTime"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - profile->startTime_ = static_cast(Local(result)->Value()); - } else { - error += "'startTime' should be a Number;"; - } + + int64_t startTime; + ret = params.GetInt64("startTime", &startTime); + if (ret == Result::SUCCESS) { + profile->startTime_ = startTime; } else { - error += "should contain 'startTime';"; + error += "Unknown 'startTime';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endTime"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - profile->endTime_ = static_cast(Local(result)->Value()); - } else { - error += "'endTime' should be a Number;"; - } + + int64_t endTime; + ret = params.GetInt64("endTime", &endTime); + if (ret == Result::SUCCESS) { + profile->endTime_ = endTime; } else { - error += "should contain 'endTime';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "samples"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t samplesLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < samplesLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - int32_t pSamples; - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - pSamples = resultValue->Int32Value(ecmaVm); - profile->samples_.value()[i] = pSamples; - } - } else { - error += "'samples' should be an Array;"; + error += "Unknown 'endTime';"; + } + + std::unique_ptr samples; + ret = params.GetArray("samples", &samples); + if (ret == Result::SUCCESS) { + int32_t samplesLen = samples->GetSize(); + for (int32_t i = 0; i < samplesLen; ++i) { + int32_t pSamples = samples->Get(i)->GetInt(); + profile->samples_.value().emplace_back(pSamples); } - } else { - error += "should contain 'samples';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timeDeltas"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t timeDeltasLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < timeDeltasLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - int32_t pTime; - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - pTime = resultValue->Int32Value(ecmaVm); - profile->timeDeltas_.value()[i] = pTime; - } - } else { - error += "'timeDeltas' should be an Array;"; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'samples';"; + } + + std::unique_ptr timeDeltas; + ret = params.GetArray("timeDeltas", &timeDeltas); + if (ret == Result::SUCCESS) { + int32_t timeDeltasLen = timeDeltas->GetSize(); + for (int32_t i = 0; i < timeDeltasLen; ++i) { + int32_t pTimeDeltas = timeDeltas->Get(i)->GetInt(); + profile->timeDeltas_.value().emplace_back(pTimeDeltas); } - } else { - error += "should contain 'timeDeltas';"; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'timeDeltas';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Profile::Create " << error; + LOG_DEBUGGER(ERROR) << "Profile::Create " << error; return nullptr; } + return profile; } @@ -3296,7 +1995,7 @@ std::unique_ptr Profile::FromProfileInfo(const ProfileInfo &profileInfo size_t samplesLen = profileInfo.samples.size(); std::vector tmpSamples; tmpSamples.reserve(samplesLen); - for (uint32_t i = 0; i < samplesLen; ++i) { + for (size_t i = 0; i < samplesLen; ++i) { tmpSamples.push_back(profileInfo.samples[i]); } profile->SetSamples(tmpSamples); @@ -3304,14 +2003,14 @@ std::unique_ptr Profile::FromProfileInfo(const ProfileInfo &profileInfo size_t timeDeltasLen = profileInfo.timeDeltas.size(); std::vector tmpTimeDeltas; tmpTimeDeltas.reserve(timeDeltasLen); - for (uint32_t i = 0; i < timeDeltasLen; ++i) { + for (size_t i = 0; i < timeDeltasLen; ++i) { tmpTimeDeltas.push_back(profileInfo.timeDeltas[i]); } profile->SetTimeDeltas(tmpTimeDeltas); std::vector> profileNode; size_t nodesLen = profileInfo.nodes.size(); - for (uint32_t i = 0; i < nodesLen; ++i) { + for (size_t i = 0; i < nodesLen; ++i) { const auto &cpuProfileNode = profileInfo.nodes[i]; profileNode.push_back(ProfileNode::FromCpuProfileNode(cpuProfileNode)); } @@ -3319,425 +2018,528 @@ std::unique_ptr Profile::FromProfileInfo(const ProfileInfo &profileInfo return profile; } -Local Profile::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr Profile::ToJson() const { - Local params = NewObject(ecmaVm); - size_t nodeLen = nodes_.size(); - Local nodeValues = ArrayRef::New(ecmaVm, nodeLen); - for (size_t i = 0; i < nodeLen; i++) { - Local profileNode = nodes_[i]->ToObject(ecmaVm); - nodeValues->Set(ecmaVm, i, profileNode); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("startTime", startTime_); + result->Add("endTime", endTime_); + + std::unique_ptr nodes = PtJson::CreateArray(); + size_t nodesLen = nodes_.size(); + for (size_t i = 0; i < nodesLen; i++) { + ASSERT(nodes_[i] != nullptr); + nodes->Push(nodes_[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "nodes")), nodeValues); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "startTime")), - NumberRef::New(ecmaVm, startTime_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "endTime")), - NumberRef::New(ecmaVm, endTime_)); - + result->Add("nodes", nodes); + if (samples_) { + std::unique_ptr samples = PtJson::CreateArray(); size_t samplesLen = samples_->size(); - Local sampleValues = ArrayRef::New(ecmaVm, samplesLen); for (size_t i = 0; i < samplesLen; i++) { - Local elem = IntegerRef::New(ecmaVm, samples_.value()[i]); - sampleValues->Set(ecmaVm, i, elem); + samples->Push(samples_.value()[i]); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "samples")), sampleValues); + result->Add("samples", samples); } - + if (timeDeltas_) { - size_t tdLen = timeDeltas_->size(); - Local timeValues = ArrayRef::New(ecmaVm, tdLen); - for (size_t i = 0; i < tdLen; i++) { - Local elem = IntegerRef::New(ecmaVm, timeDeltas_.value()[i]); - timeValues->Set(ecmaVm, i, elem); + std::unique_ptr timeDeltas = PtJson::CreateArray(); + size_t timeDeltasLen = timeDeltas_->size(); + for (size_t i = 0; i < timeDeltasLen; i++) { + timeDeltas->Push(timeDeltas_.value()[i]); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "timeDeltas")), timeValues); + result->Add("timeDeltas", timeDeltas); } - return params; + return result; } -std::unique_ptr Coverage::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr Coverage::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "Coverage::Create params is nullptr"; - return nullptr; - } std::string error; auto coverage = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "startOffset"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - coverage->startOffset_ = static_cast(Local(result)->Value()); - } else { - error += "'startOffset' should be a Number;"; - } + Result ret; + + int32_t startOffset; + ret = params.GetInt("startOffset", &startOffset); + if (ret == Result::SUCCESS) { + coverage->startOffset_ = startOffset; } else { - error += "should contain 'startOffset';"; + error += "Unknown 'startOffset';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "endOffset"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - coverage->endOffset_ = static_cast(Local(result)->Value()); - } else { - error += "'endOffset' should be a Number;"; - } + + int32_t endOffset; + ret = params.GetInt("endOffset", &endOffset); + if (ret == Result::SUCCESS) { + coverage->endOffset_ = endOffset; } else { - error += "should contain 'endOffset';"; + error += "Unknown 'endOffset';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "count"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - coverage->count_ = static_cast(Local(result)->Value()); - } else { - error += "'count' should be a Number;"; - } + + int32_t count; + ret = params.GetInt("count", &count); + if (ret == Result::SUCCESS) { + coverage->count_ = count; } else { - error += "should contain 'count';"; + error += "Unknown 'count';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "Coverage::Create " << error; + LOG_DEBUGGER(ERROR) << "Coverage::Create " << error; return nullptr; } + return coverage; } -Local Coverage::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr Coverage::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "startOffset")), IntegerRef::New(ecmaVm, startOffset_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "endOffset")), IntegerRef::New(ecmaVm, endOffset_)); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "count")), IntegerRef::New(ecmaVm, count_)); - return params; + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("startOffset", startOffset_); + result->Add("endOffset", endOffset_); + result->Add("count", count_); + + return result; } -std::unique_ptr FunctionCoverage::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr FunctionCoverage::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "FunctionCoverage::Create params is nullptr"; - return nullptr; - } std::string error; auto functionCoverage = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functionName"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - functionCoverage->functionName_ = DebuggerApi::ToStdString(result); - } else { - error += "'functionName' should be a String;"; - } + Result ret; + + std::string functionName; + ret = params.GetString("functionName", &functionName); + if (ret == Result::SUCCESS) { + functionCoverage->functionName_ = std::move(functionName); } else { - error += "should contain 'functionName';"; + error += "Unknown 'functionName';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ranges"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t rangesLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < rangesLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr range = Coverage::Create(ecmaVm, resultValue); - functionCoverage->ranges_.emplace_back(std::move(range)); + std::unique_ptr ranges; + ret = params.GetArray("ranges", &ranges); + if (ret == Result::SUCCESS) { + int32_t len = ranges->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr arrayEle = ranges->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr pRanges = Coverage::Create(*arrayEle); + if (pRanges == nullptr) { + error += "'ranges' format invalid;"; + } else { + functionCoverage->ranges_.emplace_back(std::move(pRanges)); } - } else { - error += "'ranges' should be an Array;"; } } else { - error += "should contain 'ranges';"; + error += "Unknown 'ranges';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, - "isBlockCoverage"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsBoolean()) { - functionCoverage->isBlockCoverage_ = result->IsTrue(); - } else { - error += "'isBlockCoverage' should be a Boolean;"; - } + bool isBlockCoverage; + ret = params.GetBool("isBlockCoverage", &isBlockCoverage); + if (ret == Result::SUCCESS) { + functionCoverage->isBlockCoverage_ = isBlockCoverage; + } else { + error += "Unknown 'isBlockCoverage';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "FunctionCoverage::Create " << error; + LOG_DEBUGGER(ERROR) << "FunctionCoverage::Create " << error; return nullptr; } + return functionCoverage; } -Local FunctionCoverage::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr FunctionCoverage::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "functionName")), - Local(StringRef::NewFromUtf8(ecmaVm, functionName_.c_str()))); - - size_t rangesLen = ranges_.size(); - Local rangesValues = ArrayRef::New(ecmaVm, rangesLen); - for (size_t i = 0; i < rangesLen; i++) { - Local coverage = ranges_[i]->ToObject(ecmaVm); - rangesValues->Set(ecmaVm, i, coverage); - } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "ranges")), rangesValues); - if (isBlockCoverage_) { - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "isBlockCoverage")), - BooleanRef::New(ecmaVm, isBlockCoverage_)); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("functionName", functionName_.c_str()); + + std::unique_ptr ranges = PtJson::CreateArray(); + size_t len = ranges_.size(); + for (size_t i = 0; i < len; i++) { + ASSERT(ranges_[i] != nullptr); + ranges->Push(ranges_[i]->ToJson()); } - return params; + result->Add("ranges", ranges); + + result->Add("isBlockCoverage", isBlockCoverage_); + + return result; } -std::unique_ptr ScriptCoverage::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr ScriptCoverage::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "ScriptCoverage::Create params is nullptr"; - return nullptr; - } std::string error; auto scriptCoverage = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - scriptCoverage->scriptId_ = DebuggerApi::ToStdString(result); - } else { - error += "'scriptId' should be a String;"; - } + Result ret; + + std::string scriptId; + ret = params.GetString("scriptId", &scriptId); + if (ret == Result::SUCCESS) { + scriptCoverage->scriptId_ = std::move(scriptId); } else { - error += "should contain 'scriptId';"; + error += "Unknown 'scriptId';"; } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - scriptCoverage->url_ = DebuggerApi::ToStdString(result); - } else { - error += "'url' should be a String;"; - } + + std::string url; + ret = params.GetString("url", &url); + if (ret == Result::SUCCESS) { + scriptCoverage->url_ = std::move(url); } else { - error += "should contain 'url';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functions"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t functionsLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < functionsLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr function = FunctionCoverage::Create(ecmaVm, resultValue); - scriptCoverage->functions_.emplace_back(std::move(function)); + error += "Unknown 'url';"; + } + + std::unique_ptr functions; + ret = params.GetArray("functions", &functions); + if (ret == Result::SUCCESS) { + int32_t len = functions->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr arrayEle = functions->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr pFunctions = FunctionCoverage::Create(*arrayEle); + if (pFunctions == nullptr) { + error += "'functions' format invalid;"; + } else { + scriptCoverage->functions_.emplace_back(std::move(pFunctions)); } - } else { - error += "'functions' should be an Array;"; } } else { - error += "should contain 'functions';"; + error += "Unknown 'functions';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ScriptCoverage::Create " << error; + LOG_DEBUGGER(ERROR) << "ScriptCoverage::Create " << error; return nullptr; } + return scriptCoverage; } -Local ScriptCoverage::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr ScriptCoverage::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); - size_t functionsLen = functions_.size(); - Local rangesValues = ArrayRef::New(ecmaVm, functionsLen); - for (size_t i = 0; i < functionsLen; i++) { - Local functionCoverage = functions_[i]->ToObject(ecmaVm); - rangesValues->Set(ecmaVm, i, functionCoverage); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptId", scriptId_.c_str()); + result->Add("url", url_.c_str()); + + std::unique_ptr functions = PtJson::CreateArray(); + size_t len = functions_.size(); + for (size_t i = 0; i < len; i++) { + ASSERT(functions_[i] != nullptr); + functions->Push(functions_[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "functions")), rangesValues); - return params; + result->Add("functions", functions); + + return result; } -std::unique_ptr TypeObject::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr TypeObject::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "TypeObject::Create params is nullptr"; - return nullptr; - } std::string error; auto typeObject = std::make_unique(); - - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "name"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - typeObject->name_ = DebuggerApi::ToStdString(result); - } else { - error += "'name' should be a String;"; - } + Result ret; + + std::string name; + ret = params.GetString("name", &name); + if (ret == Result::SUCCESS) { + typeObject->name_ = std::move(name); } else { - error += "should contain 'name';"; + error += "Unknown 'name';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "TypeObject::Create " << error; + LOG_DEBUGGER(ERROR) << "TypeObject::Create " << error; return nullptr; } + return typeObject; } -Local TypeObject::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr TypeObject::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "name")), - Local(StringRef::NewFromUtf8(ecmaVm, name_.c_str()))); - return params; + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("name", name_.c_str()); + + return result; } -std::unique_ptr TypeProfileEntry::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr TypeProfileEntry::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "TypeProfileEntry::Create params is nullptr"; - return nullptr; - } std::string error; auto typeProfileEntry = std::make_unique(); - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "offset"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsNumber()) { - typeProfileEntry->offset_ = static_cast(Local(result)->Value()); - } else { - error += "'offset' should be a Number;"; - } + Result ret; + + int32_t offset; + ret = params.GetInt("offset", &offset); + if (ret == Result::SUCCESS) { + typeProfileEntry->offset_ = offset; } else { - error += "should contain 'offset';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "types"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t typesLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < typesLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local resultValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr type = TypeObject::Create(ecmaVm, resultValue); - typeProfileEntry->types_.emplace_back(std::move(type)); + error += "Unknown 'offset';"; + } + + std::unique_ptr types; + ret = params.GetArray("types", &types); + if (ret == Result::SUCCESS) { + int32_t len = types->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr arrayEle = types->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr pTypes = TypeObject::Create(*arrayEle); + if (pTypes == nullptr) { + error += "'types' format invalid;"; + } else { + typeProfileEntry->types_.emplace_back(std::move(pTypes)); } - } else { - error += "'types' should be an Array;"; } } else { - error += "should contain 'types';"; + error += "Unknown 'types';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "TypeProfileEntry::Create " << error; + LOG_DEBUGGER(ERROR) << "TypeProfileEntry::Create " << error; return nullptr; } + return typeProfileEntry; } -Local TypeProfileEntry::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr TypeProfileEntry::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "offset")), - IntegerRef::New(ecmaVm, offset_)); - size_t typeLen = types_.size(); - Local typeValues = ArrayRef::New(ecmaVm, typeLen); - for (size_t i = 0; i < typeLen; i++) { - Local typeObject = types_[i]->ToObject(ecmaVm); - typeValues->Set(ecmaVm, i, typeObject); + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("offset", offset_); + + std::unique_ptr types = PtJson::CreateArray(); + size_t len = types_.size(); + for (size_t i = 0; i < len; i++) { + ASSERT(types_[i] != nullptr); + types->Push(types_[i]->ToJson()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "types")), typeValues); - return params; + result->Add("types", types); + + return result; } -std::unique_ptr ScriptTypeProfile::Create(const EcmaVM *ecmaVm, const Local ¶ms) +std::unique_ptr ScriptTypeProfile::Create(const PtJson ¶ms) { - if (params.IsEmpty() || !params->IsObject()) { - LOG(ERROR, DEBUGGER) << "ScriptTypeProfile::Create params is nullptr"; - return nullptr; - } std::string error; auto scriptTypeProfile = std::make_unique(); + Result ret; + + std::string scriptId; + ret = params.GetString("scriptId", &scriptId); + if (ret == Result::SUCCESS) { + scriptTypeProfile->scriptId_ = std::move(scriptId); + } else { + error += "Unknown 'scriptId';"; + } - Local result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "scriptId"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - scriptTypeProfile->scriptId_ = DebuggerApi::ToStdString(result); - } else { - error += "'scriptId' should be a String;"; + std::string url; + ret = params.GetString("url", &url); + if (ret == Result::SUCCESS) { + scriptTypeProfile->url_ = std::move(url); + } else { + error += "Unknown 'url';"; + } + + std::unique_ptr entries; + ret = params.GetArray("entries", &entries); + if (ret == Result::SUCCESS) { + int32_t len = entries->GetSize(); + for (int32_t i = 0; i < len; ++i) { + std::unique_ptr arrayEle = entries->Get(i); + ASSERT(arrayEle != nullptr); + std::unique_ptr pEntries = TypeProfileEntry::Create(*arrayEle); + if (pEntries == nullptr) { + error += "'entries' format invalid;"; + } else { + scriptTypeProfile->entries_.emplace_back(std::move(pEntries)); + } } } else { - error += "should contain 'scriptId';"; + error += "Unknown 'entries';"; } - result = - Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "url"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsString()) { - scriptTypeProfile->url_ = DebuggerApi::ToStdString(result); + + if (!error.empty()) { + LOG_DEBUGGER(ERROR) << "ScriptTypeProfile::Create " << error; + return nullptr; + } + + return scriptTypeProfile; +} + +std::unique_ptr ScriptTypeProfile::ToJson() const +{ + std::unique_ptr result = PtJson::CreateObject(); + + result->Add("scriptId", scriptId_.c_str()); + result->Add("url", url_.c_str()); + + std::unique_ptr entries = PtJson::CreateArray(); + size_t len = entries_.size(); + for (size_t i = 0; i < len; i++) { + ASSERT(entries_[i] != nullptr); + entries->Push(entries_[i]->ToJson()); + } + result->Add("entries", entries); + + return result; +} + +std::unique_ptr TraceConfig::Create(const PtJson ¶ms) +{ + std::string error; + auto traceConfig = std::make_unique(); + Result ret; + + std::string recordMode; + ret = params.GetString("recordMode", &recordMode); + if (ret == Result::SUCCESS) { + if (TraceConfig::RecordModeValues::Valid(recordMode)) { + traceConfig->recordMode_ = std::move(recordMode); } else { - error += "'url' should be a String;"; + error += "'recordMode' is invalid;"; } - } else { - error += "should contain 'url';"; - } - result = Local(params)->Get(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "entries"))); - if (!result.IsEmpty() && !result->IsUndefined()) { - if (result->IsArray(ecmaVm)) { - auto array = Local(result); - int32_t entriesLen = array->Length(ecmaVm); - Local key = JSValueRef::Undefined(ecmaVm); - for (int32_t i = 0; i < entriesLen; ++i) { - key = IntegerRef::New(ecmaVm, i); - Local entriesValue = Local(array)->Get(ecmaVm, key->ToString(ecmaVm)); - std::unique_ptr entries = TypeProfileEntry::Create(ecmaVm, entriesValue); - scriptTypeProfile->entries_.emplace_back(std::move(entries)); - } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'recordMode';"; + } + + bool enableSampling; + ret = params.GetBool("enableSampling", &enableSampling); + if (ret == Result::SUCCESS) { + traceConfig->enableSampling_ = enableSampling; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'enableSampling';"; + } + + bool enableSystrace; + ret = params.GetBool("enableSystrace", &enableSystrace); + if (ret == Result::SUCCESS) { + traceConfig->enableSystrace_ = enableSystrace; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'enableSystrace';"; + } + + bool enableArgumentFilter; + ret = params.GetBool("enableArgumentFilter", &enableArgumentFilter); + if (ret == Result::SUCCESS) { + traceConfig->enableArgumentFilter_ = enableArgumentFilter; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'enableArgumentFilter';"; + } + + std::unique_ptr includedCategories; + ret = params.GetArray("includedCategories", &includedCategories); + if (ret == Result::SUCCESS) { + int32_t includedCategoriesLen = includedCategories->GetSize(); + for (int32_t i = 0; i < includedCategoriesLen; ++i) { + std::string pIncludedCategories = includedCategories->Get(i)->GetString(); + traceConfig->includedCategories_.value().emplace_back(pIncludedCategories); + } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'includedCategories';"; + } + + std::unique_ptr excludedCategories; + ret = params.GetArray("excludedCategories", &excludedCategories); + if (ret == Result::SUCCESS) { + int32_t excludedCategoriesLen = excludedCategories->GetSize(); + for (int32_t i = 0; i < excludedCategoriesLen; ++i) { + std::string pExcludedCategories = excludedCategories->Get(i)->GetString(); + traceConfig->excludedCategories_.value().emplace_back(pExcludedCategories); + } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'excludedCategories';"; + } + + std::unique_ptr syntheticDelays; + ret = params.GetArray("syntheticDelays", &syntheticDelays); + if (ret == Result::SUCCESS) { + int32_t syntheticDelaysLen = includedCategories->GetSize(); + for (int32_t i = 0; i < syntheticDelaysLen; ++i) { + std::string pSyntheticDelays = syntheticDelays->Get(i)->GetString(); + traceConfig->syntheticDelays_.value().emplace_back(pSyntheticDelays); + } + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'syntheticDelays';"; + } + + std::unique_ptr memoryDumpConfig; + ret = params.GetObject("memoryDumpConfig", &memoryDumpConfig); + if (ret == Result::SUCCESS) { + std::unique_ptr tmpMemory = std::move(memoryDumpConfig); + if (tmpMemory == nullptr) { + error += "'memoryDumpConfig' format error;"; } else { - error += "'entries' should be an Array;"; + traceConfig->memoryDumpConfig_ = std::move(tmpMemory); } - } else { - error += "should contain 'entries';"; + } else if (ret == Result::TYPE_ERROR) { + error += "Unknown 'memoryDumpConfig';"; } + if (!error.empty()) { - LOG(ERROR, DEBUGGER) << "ScriptTypeProfile::Create " << error; - return scriptTypeProfile; + LOG_DEBUGGER(ERROR) << "TraceConfig::Create " << error; + return nullptr; } - return scriptTypeProfile; + + return traceConfig; } -Local ScriptTypeProfile::ToObject(const EcmaVM *ecmaVm) const +std::unique_ptr TraceConfig::ToJson() const { - Local params = NewObject(ecmaVm); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "scriptId")), - Local(StringRef::NewFromUtf8(ecmaVm, scriptId_.c_str()))); - params->Set(ecmaVm, - Local(StringRef::NewFromUtf8(ecmaVm, "url")), - Local(StringRef::NewFromUtf8(ecmaVm, url_.c_str()))); - size_t entriesLen = entries_.size(); - Local entriesValues = ArrayRef::New(ecmaVm, entriesLen); - for (size_t i = 0; i < entriesLen; i++) { - Local typeProfileEntryObject = entries_[i]->ToObject(ecmaVm); - entriesValues->Set(ecmaVm, i, typeProfileEntryObject); + std::unique_ptr result = PtJson::CreateObject(); + + if (recordMode_) { + result->Add("recordMode", recordMode_.value().c_str()); + } + + if (enableSampling_) { + result->Add("enableSampling", enableSampling_.value()); + } + + if (enableSystrace_) { + result->Add("enableSystrace", enableSystrace_.value()); + } + + if (enableArgumentFilter_) { + result->Add("enableArgumentFilter", enableArgumentFilter_.value()); } - params->Set(ecmaVm, Local(StringRef::NewFromUtf8(ecmaVm, "entries")), entriesValues); - return params; + + if (includedCategories_) { + std::unique_ptr includedCategories = PtJson::CreateArray(); + size_t includedCategoriesLen = includedCategories_->size(); + for (size_t i = 0; i < includedCategoriesLen; i++) { + includedCategories->Push(includedCategories_.value()[i].c_str()); + } + result->Add("includedCategories", includedCategories); + } + + if (excludedCategories_) { + std::unique_ptr excludedCategories = PtJson::CreateArray(); + size_t excludedCategoriesLen = excludedCategories_->size(); + for (size_t i = 0; i < excludedCategoriesLen; i++) { + excludedCategories->Push(excludedCategories_.value()[i].c_str()); + } + result->Add("excludedCategories", excludedCategories); + } + + if (syntheticDelays_) { + std::unique_ptr syntheticDelays = PtJson::CreateArray(); + size_t syntheticDelaysLen = syntheticDelays_->size(); + for (size_t i = 0; i < syntheticDelaysLen; i++) { + syntheticDelays->Push(syntheticDelays_.value()[i].c_str()); + } + result->Add("syntheticDelays", syntheticDelays); + } + + if (memoryDumpConfig_) { + result->Add("functionLocation", memoryDumpConfig_.value()); + } + + return result; } } // namespace panda::ecmascript::tooling diff --git a/ecmascript/tooling/base/pt_types.h b/ecmascript/tooling/base/pt_types.h index 7bba8af4b1742aca5ddc148af005d1c074a308c6..e2c37c94f5a7a75b07cd7d6e8c583c9f7f2caa1b 100644 --- a/ecmascript/tooling/base/pt_types.h +++ b/ecmascript/tooling/base/pt_types.h @@ -30,14 +30,7 @@ class PtBaseTypes { public: PtBaseTypes() = default; virtual ~PtBaseTypes() = default; - virtual Local ToObject(const EcmaVM *ecmaVm) const = 0; - virtual std::unique_ptr ToJson() const - { - return PtJson::CreateObject(); - } - -protected: - static Local NewObject(const EcmaVM *ecmaVm); + virtual std::unique_ptr ToJson() const = 0; private: NO_COPY_SEMANTIC(PtBaseTypes); @@ -112,10 +105,8 @@ public: RemoteObject() = default; ~RemoteObject() override = default; - static std::unique_ptr FromTagged(const EcmaVM *ecmaVm, const Local &tagged); - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr FromTagged(const EcmaVM *ecmaVm, Local tagged); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; /* @@ -173,7 +164,7 @@ public: return value_.value_or(Local()); } - RemoteObject &SetValue(const Local &value) + RemoteObject &SetValue(Local value) { value_ = value; return *this; @@ -322,6 +313,11 @@ public: static const std::string MapIteratorDescription; // NOLINT (readability-identifier-naming) static const std::string WeakMapDescription; // NOLINT (readability-identifier-naming) static const std::string WeakSetDescription; // NOLINT (readability-identifier-naming) + static const std::string JSPrimitiveRefDescription; // NOLINT (readability-identifier-naming) + static const std::string JSPrimitiveNumberDescription; // NOLINT (readability-identifier-naming) + static const std::string JSPrimitiveBooleanDescription; // NOLINT (readability-identifier-naming) + static const std::string JSPrimitiveStringDescription; // NOLINT (readability-identifier-naming) + static const std::string JSPrimitiveSymbolDescription; // NOLINT (readability-identifier-naming) private: NO_COPY_SEMANTIC(RemoteObject); @@ -338,72 +334,56 @@ private: class PrimitiveRemoteObject final : public RemoteObject { public: - explicit PrimitiveRemoteObject(const EcmaVM *ecmaVm, const Local &tagged); + PrimitiveRemoteObject(const EcmaVM *ecmaVm, Local tagged); ~PrimitiveRemoteObject() override = default; }; class StringRemoteObject final : public RemoteObject { public: - explicit StringRemoteObject([[maybe_unused]] const EcmaVM *ecmaVm, const Local &tagged) - { - SetType(RemoteObject::TypeName::String).SetValue(tagged); - } + StringRemoteObject(const EcmaVM *ecmaVm, Local tagged); virtual ~StringRemoteObject() = default; }; class SymbolRemoteObject final : public RemoteObject { public: - explicit SymbolRemoteObject(const EcmaVM *ecmaVm, const Local &tagged) - { - SetType(RemoteObject::TypeName::Symbol).SetDescription(DescriptionForSymbol(ecmaVm, Local(tagged))); - } + SymbolRemoteObject(const EcmaVM *ecmaVm, Local tagged); ~SymbolRemoteObject() override = default; private: - std::string DescriptionForSymbol(const EcmaVM *ecmaVm, const Local &tagged) const; + std::string DescriptionForSymbol(const EcmaVM *ecmaVm, Local tagged) const; }; class FunctionRemoteObject final : public RemoteObject { public: - FunctionRemoteObject(const EcmaVM *ecmaVm, const Local &tagged) - { - SetType(RemoteObject::TypeName::Function) - .SetClassName(RemoteObject::ClassName::Function) - .SetDescription(DescriptionForFunction(ecmaVm, tagged)); - } + FunctionRemoteObject(const EcmaVM *ecmaVm, Local tagged); ~FunctionRemoteObject() override = default; private: - std::string DescriptionForFunction(const EcmaVM *ecmaVm, const Local &tagged) const; + std::string DescriptionForFunction(const EcmaVM *ecmaVm, Local tagged) const; }; class ObjectRemoteObject final : public RemoteObject { public: - explicit ObjectRemoteObject(const EcmaVM *ecmaVm, const Local &tagged, const std::string &classname) - { - SetType(RemoteObject::TypeName::Object) - .SetClassName(classname) - .SetDescription(DescriptionForObject(ecmaVm, tagged)); - } - explicit ObjectRemoteObject(const EcmaVM *ecmaVm, const Local &tagged, const std::string &classname, - const std::string &subtype) - { - SetType(RemoteObject::TypeName::Object) - .SetSubType(subtype) - .SetClassName(classname) - .SetDescription(DescriptionForObject(ecmaVm, tagged)); - } + ObjectRemoteObject(const EcmaVM *ecmaVm, Local tagged, const std::string &classname); + ObjectRemoteObject(const EcmaVM *ecmaVm, Local tagged, const std::string &classname, + const std::string &subtype); ~ObjectRemoteObject() override = default; - static std::string DescriptionForObject(const EcmaVM *ecmaVm, const Local &tagged); + static std::string DescriptionForObject(const EcmaVM *ecmaVm, Local tagged); private: - static std::string DescriptionForArray(const EcmaVM *ecmaVm, const Local &tagged); - static std::string DescriptionForRegexp(const EcmaVM *ecmaVm, const Local &tagged); - static std::string DescriptionForDate(const EcmaVM *ecmaVm, const Local &tagged); - static std::string DescriptionForMap(const Local &tagged); - static std::string DescriptionForSet(const Local &tagged); - static std::string DescriptionForError(const EcmaVM *ecmaVm, const Local &tagged); - static std::string DescriptionForArrayBuffer(const EcmaVM *ecmaVm, const Local &tagged); + static std::string DescriptionForArray(const EcmaVM *ecmaVm, Local tagged); + static std::string DescriptionForRegexp(const EcmaVM *ecmaVm, Local tagged); + static std::string DescriptionForDate(const EcmaVM *ecmaVm, Local tagged); + static std::string DescriptionForMap(Local tagged); + static std::string DescriptionForSet(Local tagged); + static std::string DescriptionForError(const EcmaVM *ecmaVm, Local tagged); + static std::string DescriptionForArrayIterator(); + static std::string DescriptionForMapIterator(); + static std::string DescriptionForSetIterator(); + static std::string DescriptionForArrayBuffer(const EcmaVM *ecmaVm, Local tagged); + static std::string DescriptionForPrimitiveNumber(const EcmaVM *ecmaVm, const Local &tagged); + static std::string DescriptionForPrimitiveString(const EcmaVM *ecmaVm, const Local &tagged); + static std::string DescriptionForPrimitiveBoolean(const EcmaVM *ecmaVm, const Local &tagged); }; // Runtime.ExceptionDetails @@ -411,9 +391,7 @@ class ExceptionDetails final : public PtBaseTypes { public: ExceptionDetails() = default; ~ExceptionDetails() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; int32_t GetExceptionId() const @@ -440,23 +418,23 @@ public: int32_t GetLine() const { - return line_; + return lineNumber_; } - ExceptionDetails &SetLine(int32_t line) + ExceptionDetails &SetLine(int32_t lineNumber) { - line_ = line; + lineNumber_ = lineNumber; return *this; } int32_t GetColumn() const { - return column_; + return columnNumber_; } - ExceptionDetails &SetColumn(int32_t column) + ExceptionDetails &SetColumn(int32_t columnNumber) { - column_ = column; + columnNumber_ = columnNumber; return *this; } @@ -534,8 +512,8 @@ private: int32_t exceptionId_ {0}; std::string text_ {}; - int32_t line_ {0}; - int32_t column_ {0}; + int32_t lineNumber_ {0}; + int32_t columnNumber_ {0}; std::optional scriptId_ {}; std::optional url_ {}; std::optional> exception_ {}; @@ -548,9 +526,7 @@ public: InternalPropertyDescriptor() = default; ~InternalPropertyDescriptor() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; std::string GetName() const @@ -597,9 +573,7 @@ public: PrivatePropertyDescriptor() = default; ~PrivatePropertyDescriptor() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; std::string GetName() const @@ -686,11 +660,9 @@ public: PropertyDescriptor() = default; ~PropertyDescriptor() override = default; - static std::unique_ptr FromProperty(const EcmaVM *ecmaVm, const Local &name, + static std::unique_ptr FromProperty(const EcmaVM *ecmaVm, Local name, const PropertyAttribute &property); - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; std::string GetName() const @@ -872,9 +844,7 @@ public: CallArgument() = default; ~CallArgument() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; Local GetValue() const @@ -882,7 +852,7 @@ public: return value_.value_or(Local()); } - CallArgument &SetValue(const Local &value) + CallArgument &SetValue(Local value) { value_ = value; return *this; @@ -958,9 +928,7 @@ public: Location() = default; ~Location() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; ScriptId GetScriptId() const @@ -976,38 +944,38 @@ public: int32_t GetLine() const { - return line_; + return lineNumber_; } Location &SetLine(int32_t line) { - line_ = line; + lineNumber_ = line; return *this; } int32_t GetColumn() const { - return column_.value_or(-1); + return columnNumber_.value_or(-1); } Location &SetColumn(int32_t column) { - column_ = column; + columnNumber_ = column; return *this; } bool HasColumn() const { - return column_.has_value(); + return columnNumber_.has_value(); } private: NO_COPY_SEMANTIC(Location); NO_MOVE_SEMANTIC(Location); - ScriptId scriptId_ {}; - int32_t line_ {0}; - std::optional column_ {}; + ScriptId scriptId_ {0}; + int32_t lineNumber_ {0}; + std::optional columnNumber_ {}; }; // Debugger.ScriptPosition @@ -1016,30 +984,28 @@ public: ScriptPosition() = default; ~ScriptPosition() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; int32_t GetLine() const { - return line_; + return lineNumber_; } ScriptPosition &SetLine(int32_t line) { - line_ = line; + lineNumber_ = line; return *this; } int32_t GetColumn() const { - return column_; + return columnNumber_; } ScriptPosition &SetColumn(int32_t column) { - column_ = column; + columnNumber_ = column; return *this; } @@ -1047,8 +1013,8 @@ private: NO_COPY_SEMANTIC(ScriptPosition); NO_MOVE_SEMANTIC(ScriptPosition); - int32_t line_ {0}; - int32_t column_ {0}; + int32_t lineNumber_ {0}; + int32_t columnNumber_ {0}; }; // Debugger.SearchMatch @@ -1056,9 +1022,7 @@ class SearchMatch : public PtBaseTypes { public: SearchMatch() = default; ~SearchMatch() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; private: @@ -1075,9 +1039,7 @@ public: LocationRange() = default; ~LocationRange() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; ScriptId GetScriptId() const @@ -1117,7 +1079,7 @@ private: NO_COPY_SEMANTIC(LocationRange); NO_MOVE_SEMANTIC(LocationRange); - ScriptId scriptId_ {}; + ScriptId scriptId_ {0}; std::unique_ptr start_ {nullptr}; std::unique_ptr end_ {nullptr}; }; @@ -1128,9 +1090,7 @@ public: BreakLocation() = default; ~BreakLocation() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; ScriptId GetScriptId() const @@ -1146,29 +1106,29 @@ public: int32_t GetLine() const { - return line_; + return lineNumber_; } - BreakLocation &SetLine(int32_t line) + BreakLocation &SetLine(int32_t lineNumber) { - line_ = line; + lineNumber_ = lineNumber; return *this; } int32_t GetColumn() const { - return column_.value_or(-1); + return columnNumber_.value_or(-1); } - BreakLocation &SetColumn(int32_t column) + BreakLocation &SetColumn(int32_t columnNumber) { - column_ = column; + columnNumber_ = columnNumber; return *this; } bool HasColumn() const { - return column_.has_value(); + return columnNumber_.has_value(); } /* @@ -1214,9 +1174,9 @@ private: NO_COPY_SEMANTIC(BreakLocation); NO_MOVE_SEMANTIC(BreakLocation); - ScriptId scriptId_ {}; - int32_t line_ {0}; - std::optional column_ {}; + ScriptId scriptId_ {0}; + int32_t lineNumber_ {0}; + std::optional columnNumber_ {}; std::optional type_ {}; }; using BreakType = BreakLocation::Type; @@ -1240,9 +1200,7 @@ public: Scope() = default; ~Scope() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; /* @@ -1391,9 +1349,7 @@ public: CallFrame() = default; ~CallFrame() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); static std::unique_ptr Create(const PtJson ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; std::unique_ptr ToJson() const override; CallFrameId GetCallFrameId() const @@ -1515,16 +1471,16 @@ private: // ========== Heapprofiler types begin -using HeapSnapshotObjectId = uint32_t; +using HeapSnapshotObjectId = int32_t; class SamplingHeapProfileSample final : public PtBaseTypes { public: SamplingHeapProfileSample() = default; ~SamplingHeapProfileSample() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; - SamplingHeapProfileSample &SetSize(size_t size) + SamplingHeapProfileSample &SetSize(int32_t size) { size_ = size; return *this; @@ -1546,7 +1502,7 @@ public: return nodeId_; } - SamplingHeapProfileSample &SetOrdinal(size_t ordinal) + SamplingHeapProfileSample &SetOrdinal(int32_t ordinal) { ordinal_ = ordinal; return *this; @@ -1561,18 +1517,18 @@ private: NO_COPY_SEMANTIC(SamplingHeapProfileSample); NO_MOVE_SEMANTIC(SamplingHeapProfileSample); - size_t size_ {}; - int32_t nodeId_ {}; - size_t ordinal_ {}; + int32_t size_ {0}; + int32_t nodeId_ {0}; + int32_t ordinal_ {0}; }; class RuntimeCallFrame final : public PtBaseTypes { public: RuntimeCallFrame() = default; ~RuntimeCallFrame() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); static std::unique_ptr FromFrameInfo(const FrameInfo &cpuFrameInfo); - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; RuntimeCallFrame &SetFunctionName(const std::string &functionName) { @@ -1636,16 +1592,16 @@ private: std::string functionName_ {}; std::string scriptId_ {}; std::string url_ {}; - int32_t lineNumber_ {}; - int32_t columnNumber_ {}; + int32_t lineNumber_ {0}; + int32_t columnNumber_ {0}; }; class SamplingHeapProfileNode final : public PtBaseTypes { public: SamplingHeapProfileNode() = default; ~SamplingHeapProfileNode() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; SamplingHeapProfileNode &SetCallFrame(std::unique_ptr callFrame) { @@ -1658,7 +1614,7 @@ public: return callFrame_.get(); } - SamplingHeapProfileNode &SetSelfSize(size_t selfSize) + SamplingHeapProfileNode &SetSelfSize(int32_t selfSize) { selfSize_ = selfSize; return *this; @@ -1696,8 +1652,8 @@ private: NO_MOVE_SEMANTIC(SamplingHeapProfileNode); std::unique_ptr callFrame_ {nullptr}; - size_t selfSize_ {}; - int32_t id_ {}; + int32_t selfSize_ {0}; + int32_t id_ {0}; std::vector> children_ {}; }; @@ -1705,8 +1661,8 @@ class SamplingHeapProfile final : public PtBaseTypes { public: SamplingHeapProfile() = default; ~SamplingHeapProfile() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; SamplingHeapProfile &SetHead(std::unique_ptr head) { @@ -1745,14 +1701,15 @@ public: PositionTickInfo() = default; ~PositionTickInfo() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; + int32_t GetLine() const { return line_; } - PositionTickInfo &SetLine(size_t line) + PositionTickInfo &SetLine(int32_t line) { line_ = line; return *this; @@ -1763,7 +1720,7 @@ public: return ticks_; } - PositionTickInfo &SetTicks(size_t ticks) + PositionTickInfo &SetTicks(int32_t ticks) { ticks_ = ticks; return *this; @@ -1772,8 +1729,8 @@ public: private: NO_COPY_SEMANTIC(PositionTickInfo); NO_MOVE_SEMANTIC(PositionTickInfo); - size_t line_ {0}; - size_t ticks_ {0}; + int32_t line_ {0}; + int32_t ticks_ {0}; }; // Profiler.ProfileNode @@ -1782,9 +1739,9 @@ public: ProfileNode() = default; ~ProfileNode() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); static std::unique_ptr FromCpuProfileNode(const CpuProfileNode &cpuProfileNode); - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; int32_t GetId() const { @@ -1897,9 +1854,9 @@ public: Profile() = default; ~Profile() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); + static std::unique_ptr Create(const PtJson ¶ms); static std::unique_ptr FromProfileInfo(const ProfileInfo &profileInfo); - Local ToObject(const EcmaVM *ecmaVm) const override; + std::unique_ptr ToJson() const override; int64_t GetStartTime() const { @@ -1989,15 +1946,15 @@ public: Coverage() = default; ~Coverage() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; int32_t GetStartOffset() const { return startOffset_; } - Coverage &SetStartOffset(size_t startOffset) + Coverage &SetStartOffset(int32_t startOffset) { startOffset_ = startOffset; return *this; @@ -2008,7 +1965,7 @@ public: return endOffset_; } - Coverage &SetEndOffset(size_t endOffset) + Coverage &SetEndOffset(int32_t endOffset) { endOffset_ = endOffset; return *this; @@ -2019,7 +1976,7 @@ public: return count_; } - Coverage &SetCount(size_t count) + Coverage &SetCount(int32_t count) { count_ = count; return *this; @@ -2029,9 +1986,9 @@ private: NO_COPY_SEMANTIC(Coverage); NO_MOVE_SEMANTIC(Coverage); - size_t startOffset_ {0}; - size_t endOffset_ {0}; - size_t count_ {0}; + int32_t startOffset_ {0}; + int32_t endOffset_ {0}; + int32_t count_ {0}; }; // Profiler.FunctionCoverage @@ -2040,8 +1997,8 @@ public: FunctionCoverage() = default; ~FunctionCoverage() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; const std::string &GetFunctionName() const { @@ -2092,8 +2049,8 @@ public: ScriptCoverage() = default; ~ScriptCoverage() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; const std::string &GetScriptId() const { @@ -2143,8 +2100,9 @@ public: TypeObject() = default; ~TypeObject() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; + const std::string &GetName() const { return name_; @@ -2169,14 +2127,15 @@ public: TypeProfileEntry() = default; ~TypeProfileEntry() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; + int32_t GetOffset() const { return offset_; } - TypeProfileEntry &SetOffset(size_t offset) + TypeProfileEntry &SetOffset(int32_t offset) { offset_ = offset; return *this; @@ -2197,7 +2156,7 @@ private: NO_COPY_SEMANTIC(TypeProfileEntry); NO_MOVE_SEMANTIC(TypeProfileEntry); - size_t offset_ {0}; + int32_t offset_ {0}; std::vector> types_ {}; }; @@ -2207,8 +2166,9 @@ public: ScriptTypeProfile() = default; ~ScriptTypeProfile() override = default; - static std::unique_ptr Create(const EcmaVM *ecmaVm, const Local ¶ms); - Local ToObject(const EcmaVM *ecmaVm) const override; + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; + const std::string &GetScriptId() const { return scriptId_; @@ -2250,5 +2210,253 @@ private: std::string url_ {}; std::vector> entries_ {}; }; + +// ========== Tracing types begin +// Tracing.MemoryDumpConfig +using MemoryDumpConfig = PtJson; + +// Tracing.MemoryDumpLevelOfDetail +using MemoryDumpLevelOfDetail = std::string; +struct MemoryDumpLevelOfDetailValues { + static bool Valid(const std::string &values) + { + return values == Background() || values == Light() || values == Detailed(); + } + static std::string Background() + { + return "background"; + } + static std::string Light() + { + return "light"; + } + static std::string Detailed() + { + return "detailed"; + } +}; + +// Tracing.StreamCompression +using StreamCompression = std::string; +struct StreamCompressionValues { + static bool Valid(const std::string &values) + { + return values == None() || values == Gzip(); + } + static std::string None() + { + return "none"; + } + static std::string Gzip() + { + return "gzip"; + } +}; + +// Tracing.StreamFormat +using StreamFormat = std::string; +struct StreamFormatValues { + static bool Valid(const std::string &values) + { + return values == Json() || values == Proto(); + } + static std::string Json() + { + return "json"; + } + static std::string Proto() + { + return "proto"; + } +}; + +// Tracing.TraceConfig +class TraceConfig final : public PtBaseTypes { +public: + TraceConfig() = default; + ~TraceConfig() override = default; + + static std::unique_ptr Create(const PtJson ¶ms); + std::unique_ptr ToJson() const override; + + std::string GetRecordMode() const + { + return recordMode_.value(); + } + + TraceConfig &SetRecordMode(std::string recordMode) + { + recordMode_ = recordMode; + return *this; + } + + bool HasRecordMode() const + { + return recordMode_.has_value(); + } + + struct RecordModeValues { + static bool Valid(const std::string &values) + { + return values == RecordUntilFull() || values == RecordContinuously() || + values == RecordAsMuchAsPossible() || values == EchoToConsole(); + } + static std::string RecordUntilFull() + { + return "recordUntilFull"; + } + static std::string RecordContinuously() + { + return "recordContinuously"; + } + static std::string RecordAsMuchAsPossible() + { + return "recordAsMuchAsPossible"; + } + static std::string EchoToConsole() + { + return "echoToConsole"; + } + }; + + bool GetEnableSampling() const + { + return enableSampling_.value(); + } + + TraceConfig &SetEnableSampling(bool enableSampling) + { + enableSampling_ = enableSampling; + return *this; + } + + bool HasEnableSampling() const + { + return enableSampling_.has_value(); + } + + bool GetEnableSystrace() const + { + return enableSystrace_.value(); + } + + TraceConfig &SetEnableSystrace(bool enableSystrace) + { + enableSystrace_ = enableSystrace; + return *this; + } + + bool HasEnableSystrace() const + { + return enableSystrace_.has_value(); + } + + bool GetEnableArgumentFilter() const + { + return enableArgumentFilter_.value(); + } + + TraceConfig &SetEnableArgumentFilter(bool enableArgumentFilter) + { + enableArgumentFilter_ = enableArgumentFilter; + return *this; + } + + bool HasEnableArgumentFilter() const + { + return enableArgumentFilter_.has_value(); + } + + const std::vector *GetIncludedCategories() const + { + if (includedCategories_) { + return &includedCategories_.value(); + } + return nullptr; + } + + TraceConfig &SetIncludedCategories(std::vector includedCategories) + { + includedCategories_ = includedCategories; + return *this; + } + + bool HasIncludedCategories() const + { + return includedCategories_.has_value(); + } + + const std::vector *GetExcludedCategories() const + { + if (excludedCategories_) { + return &excludedCategories_.value(); + } + return nullptr; + } + + TraceConfig &SetExcludedCategories(std::vector excludedCategories) + { + excludedCategories_ = excludedCategories; + return *this; + } + + bool HasExcludedCategories() const + { + return excludedCategories_.has_value(); + } + + const std::vector *GetSyntheticDelays() const + { + if (syntheticDelays_) { + return &syntheticDelays_.value(); + } + return nullptr; + } + + TraceConfig &SetSyntheticDelays(std::vector syntheticDelays) + { + syntheticDelays_ = syntheticDelays; + return *this; + } + + bool HasSyntheticDelays() const + { + return syntheticDelays_.has_value(); + } + +private: + NO_COPY_SEMANTIC(TraceConfig); + NO_MOVE_SEMANTIC(TraceConfig); + + std::optional recordMode_ {}; + std::optional enableSampling_ {}; + std::optional enableSystrace_ {}; + std::optional enableArgumentFilter_ {}; + std::optional> includedCategories_ {}; + std::optional> excludedCategories_ {}; + std::optional> syntheticDelays_ {}; + std::optional> memoryDumpConfig_ {}; +}; + +// Tracing.TracingBackend +using TracingBackend = std::string; +struct TracingBackendValues { + static bool Valid(const std::string &values) + { + return values == Auto() || values == Chrome() || values == System(); + } + static std::string Auto() + { + return "auto"; + } + static std::string Chrome() + { + return "chrome"; + } + static std::string System() + { + return "system"; + } +}; } // namespace panda::ecmascript::tooling #endif diff --git a/ecmascript/tooling/debugger_service.cpp b/ecmascript/tooling/debugger_service.cpp index 1e91a31d301abaf190e3a4a1a0ca0c3dd3a0031c..1564f439b5736a202507b3a66ee18df1151da319 100644 --- a/ecmascript/tooling/debugger_service.cpp +++ b/ecmascript/tooling/debugger_service.cpp @@ -14,16 +14,18 @@ */ #include "ecmascript/tooling/debugger_service.h" + #include "ecmascript/ecma_vm.h" #include "ecmascript/tooling/protocol_handler.h" #include "ecmascript/tooling/interface/js_debugger_manager.h" namespace panda::ecmascript::tooling { -void InitializeDebugger(const std::function &onResponse, ::panda::ecmascript::EcmaVM *vm) +void InitializeDebugger(::panda::ecmascript::EcmaVM *vm, + const std::function &onResponse) { ProtocolHandler *handler = vm->GetJsDebuggerManager()->GetDebuggerHandler(); if (handler != nullptr) { - LOG(ERROR, DEBUGGER) << "JS debugger was initialized"; + LOG_DEBUGGER(ERROR) << "JS debugger was initialized"; return; } vm->GetJsDebuggerManager()->SetDebuggerHandler(new ProtocolHandler(onResponse, vm)); @@ -36,11 +38,36 @@ void UninitializeDebugger(::panda::ecmascript::EcmaVM *vm) vm->GetJsDebuggerManager()->SetDebuggerHandler(nullptr); } -void DispatchProtocolMessage(const ::panda::ecmascript::EcmaVM *vm, const std::string &message) +void WaitForDebugger(const ::panda::ecmascript::EcmaVM *vm) { ProtocolHandler *handler = vm->GetJsDebuggerManager()->GetDebuggerHandler(); - if (handler != nullptr) { - handler->ProcessCommand(message); + if (LIKELY(handler != nullptr)) { + handler->WaitForDebugger(); + } +} + +void DispatchMessage(const ::panda::ecmascript::EcmaVM *vm, std::string &&message) +{ + ProtocolHandler *handler = vm->GetJsDebuggerManager()->GetDebuggerHandler(); + if (LIKELY(handler != nullptr)) { + handler->DispatchCommand(std::move(message)); + } +} + +void ProcessMessage(const ::panda::ecmascript::EcmaVM *vm) +{ + ProtocolHandler *handler = vm->GetJsDebuggerManager()->GetDebuggerHandler(); + if (LIKELY(handler != nullptr)) { + handler->ProcessCommand(); + } +} + +int32_t GetDispatchStatus(const ::panda::ecmascript::EcmaVM *vm) +{ + ProtocolHandler *handler = vm->GetJsDebuggerManager()->GetDebuggerHandler(); + if (LIKELY(handler != nullptr)) { + return handler->GetDispatchStatus(); } + return ProtocolHandler::DispatchStatus::UNKNOWN; } } // namespace panda::ecmascript::tooling \ No newline at end of file diff --git a/ecmascript/tooling/debugger_service.h b/ecmascript/tooling/debugger_service.h index 598614fb0b5b9f26d536d7c4c6a484a3df4dd5f1..9c7d5c0dcaeb03cd8503699622ea4a94e72f7635 100644 --- a/ecmascript/tooling/debugger_service.h +++ b/ecmascript/tooling/debugger_service.h @@ -32,12 +32,18 @@ extern "C" { #endif #endif /* End of #ifdef __cplusplus */ -PUBLIC_API void InitializeDebugger(const std::function &on_response, - ::panda::ecmascript::EcmaVM *vm); +PUBLIC_API void InitializeDebugger(::panda::ecmascript::EcmaVM *vm, + const std::function &onResponse); PUBLIC_API void UninitializeDebugger(::panda::ecmascript::EcmaVM *vm); -PUBLIC_API void DispatchProtocolMessage(const ::panda::ecmascript::EcmaVM *vm, const std::string &message); +PUBLIC_API void DispatchMessage(const ::panda::ecmascript::EcmaVM *vm, std::string &&message); + +PUBLIC_API void WaitForDebugger(const ::panda::ecmascript::EcmaVM *vm); + +PUBLIC_API void ProcessMessage(const ::panda::ecmascript::EcmaVM *vm); + +PUBLIC_API int32_t GetDispatchStatus(const ::panda::ecmascript::EcmaVM *vm); #ifdef __cplusplus #if __cplusplus diff --git a/ecmascript/tooling/dispatcher.cpp b/ecmascript/tooling/dispatcher.cpp index 2542c62caa05f943e8407e6714fb75ef3744bd24..958564075b8b61dd2c6ab4935c36aa360e92135b 100644 --- a/ecmascript/tooling/dispatcher.cpp +++ b/ecmascript/tooling/dispatcher.cpp @@ -15,21 +15,20 @@ #include "ecmascript/tooling/dispatcher.h" -#include "libpandabase/utils/logger.h" - #include "ecmascript/tooling/agent/debugger_impl.h" #include "ecmascript/tooling/agent/runtime_impl.h" #include "ecmascript/tooling/agent/heapprofiler_impl.h" #include "ecmascript/tooling/agent/profiler_impl.h" +#include "ecmascript/tooling/agent/tracing_impl.h" #include "ecmascript/tooling/protocol_channel.h" namespace panda::ecmascript::tooling { -DispatchRequest::DispatchRequest(const EcmaVM *ecmaVm, const std::string &message) : ecmaVm_(ecmaVm) +DispatchRequest::DispatchRequest(const std::string &message) { std::unique_ptr json = PtJson::Parse(message); if (json == nullptr || !json->IsObject()) { code_ = RequestCode::JSON_PARSE_ERROR; - LOG(ERROR, DEBUGGER) << "json parse error"; + LOG_DEBUGGER(ERROR) << "json parse error"; return; } @@ -38,7 +37,7 @@ DispatchRequest::DispatchRequest(const EcmaVM *ecmaVm, const std::string &messag ret = json->GetInt("id", &callId); if (ret != Result::SUCCESS) { code_ = RequestCode::PARSE_ID_ERROR; - LOG(ERROR, DEBUGGER) << "parse id error"; + LOG_DEBUGGER(ERROR) << "parse id error"; return; } callId_ = callId; @@ -47,7 +46,7 @@ DispatchRequest::DispatchRequest(const EcmaVM *ecmaVm, const std::string &messag ret = json->GetString("method", &wholeMethod); if (ret != Result::SUCCESS) { code_ = RequestCode::PARSE_METHOD_ERROR; - LOG(ERROR, DEBUGGER) << "parse method error"; + LOG_DEBUGGER(ERROR) << "parse method error"; return; } std::string::size_type length = wholeMethod.length(); @@ -55,15 +54,15 @@ DispatchRequest::DispatchRequest(const EcmaVM *ecmaVm, const std::string &messag indexPoint = wholeMethod.find_first_of('.', 0); if (indexPoint == std::string::npos || indexPoint == 0 || indexPoint == length - 1) { code_ = RequestCode::METHOD_FORMAT_ERROR; - LOG(ERROR, DEBUGGER) << "method format error: " << wholeMethod; + LOG_DEBUGGER(ERROR) << "method format error: " << wholeMethod; return; } domain_ = wholeMethod.substr(0, indexPoint); method_ = wholeMethod.substr(indexPoint + 1, length); - LOG(DEBUG, DEBUGGER) << "id: " << callId_; - LOG(DEBUG, DEBUGGER) << "domain: " << domain_; - LOG(DEBUG, DEBUGGER) << "method: " << method_; + LOG_DEBUGGER(DEBUG) << "id: " << callId_; + LOG_DEBUGGER(DEBUG) << "domain: " << domain_; + LOG_DEBUGGER(DEBUG) << "method: " << method_; std::unique_ptr params; ret = json->GetObject("params", ¶ms); @@ -72,35 +71,10 @@ DispatchRequest::DispatchRequest(const EcmaVM *ecmaVm, const std::string &messag } if (ret == Result::TYPE_ERROR) { code_ = RequestCode::PARAMS_FORMAT_ERROR; - LOG(ERROR, DEBUGGER) << "params format error"; + LOG_DEBUGGER(ERROR) << "params format error"; return; } params_ = std::move(params); - - // below code will delete soon - Local msgValue = JSON::Parse(ecmaVm, StringRef::NewFromUtf8(ecmaVm, message.c_str())); - if (msgValue->IsException()) { - DebuggerApi::ClearException(ecmaVm); - LOG(ERROR, DEBUGGER) << "json parse throw exception"; - return; - } - if (!msgValue->IsObject()) { - code_ = RequestCode::JSON_PARSE_ERROR; - LOG(ERROR, DEBUGGER) << "json parse error"; - return; - } - Local paramsStr = StringRef::NewFromUtf8(ecmaVm, "params"); - ObjectRef *msgObj = ObjectRef::Cast(*msgValue); - Local paramsValue = msgObj->Get(ecmaVm, paramsStr); - if (paramsValue.IsEmpty()) { - return; - } - if (!paramsValue->IsObject()) { - code_ = RequestCode::PARAMS_FORMAT_ERROR; - LOG(ERROR, DEBUGGER) << "params format error"; - return; - } - paramsObj_ = paramsValue; } DispatchRequest::~DispatchRequest() @@ -152,10 +126,13 @@ Dispatcher::Dispatcher(const EcmaVM *vm, ProtocolChannel *channel) // profiler auto profiler = std::make_unique(vm, channel); auto heapProfiler = std::make_unique(vm, channel); + auto tracing = std::make_unique(vm, channel); dispatchers_["Profiler"] = std::make_unique(channel, std::move(profiler)); dispatchers_["HeapProfiler"] = std::make_unique(channel, std::move(heapProfiler)); + dispatchers_["Tracing"] = + std::make_unique(channel, std::move(tracing)); // debugger auto runtime = std::make_unique(vm, channel); @@ -169,7 +146,7 @@ Dispatcher::Dispatcher(const EcmaVM *vm, ProtocolChannel *channel) void Dispatcher::Dispatch(const DispatchRequest &request) { if (!request.IsValid()) { - LOG(ERROR, DEBUGGER) << "Unknown request"; + LOG_DEBUGGER(ERROR) << "Unknown request"; return; } const std::string &domain = request.GetDomain(); @@ -177,7 +154,7 @@ void Dispatcher::Dispatch(const DispatchRequest &request) if (dispatcher != dispatchers_.end()) { dispatcher->second->Dispatch(request); } else { - LOG(ERROR, DEBUGGER) << "unknown domain: " << domain; + LOG_DEBUGGER(ERROR) << "unknown domain: " << domain; } } } // namespace panda::ecmascript::tooling diff --git a/ecmascript/tooling/dispatcher.h b/ecmascript/tooling/dispatcher.h index 9a679c1e49882d585ceb3795c4aba93794eee69e..b247ba8bf6ed47147f8fc0f19243413690e6740c 100644 --- a/ecmascript/tooling/dispatcher.h +++ b/ecmascript/tooling/dispatcher.h @@ -47,7 +47,7 @@ enum class ResponseCode : uint8_t { OK, NOK }; class DispatchRequest { public: - explicit DispatchRequest(const EcmaVM *ecmaVm, const std::string &message); + explicit DispatchRequest(const std::string &message); ~DispatchRequest(); bool IsValid() const @@ -58,10 +58,6 @@ public: { return callId_; } - Local GetParamsObj() const - { - return paramsObj_; - } const PtJson &GetParams() const { return *params_; @@ -74,17 +70,11 @@ public: { return method_; } - const EcmaVM *GetEcmaVM() const - { - return ecmaVm_; - } private: - const EcmaVM *ecmaVm_ {nullptr}; int32_t callId_ = -1; std::string domain_ {}; std::string method_ {}; - Local paramsObj_ {}; std::unique_ptr params_ = std::make_unique(); RequestCode code_ {RequestCode::OK}; std::string errorMsg_ {}; diff --git a/ecmascript/tooling/interface/file_stream.cpp b/ecmascript/tooling/interface/file_stream.cpp index 6c02144bdbfd6bd2de1edd5af49e72ad4582397c..7332a55c80e75bf434bb386564458bf1e6ac6d82 100644 --- a/ecmascript/tooling/interface/file_stream.cpp +++ b/ecmascript/tooling/interface/file_stream.cpp @@ -15,11 +15,11 @@ #include "ecmascript/tooling/interface/file_stream.h" -#include #include +#include +#include #include "ecmascript/ecma_macros.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript { FileStream::FileStream(const std::string &fileName) @@ -69,7 +69,7 @@ std::pair FileStream::FilePathValid(const std::string &fileNa } // Writes the chunk of data into the stream -bool FileStream::WriteChunk(char *data, int size) +bool FileStream::WriteChunk(char *data, int32_t size) { if (fileStream_.fail()) { return false; @@ -77,7 +77,7 @@ bool FileStream::WriteChunk(char *data, int size) std::string str; str.resize(size); - for (int i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { str[i] = data[i]; } @@ -99,7 +99,7 @@ bool FileDescriptorStream::Good() } // Writes the chunk of data into the stream -bool FileDescriptorStream::WriteChunk(char *data, int size) +bool FileDescriptorStream::WriteChunk(char *data, int32_t size) { if (fd_ < 0) { return false; @@ -107,7 +107,7 @@ bool FileDescriptorStream::WriteChunk(char *data, int size) std::string str; str.resize(size); - for (int i = 0; i < size; ++i) { + for (int32_t i = 0; i < size; ++i) { str[i] = data[i]; } int ret = dprintf(fd_, "%s", str.c_str()); @@ -122,4 +122,4 @@ bool FileDescriptorStream::WriteChunk(char *data, int size) } return true; } -} \ No newline at end of file +} diff --git a/ecmascript/tooling/interface/file_stream.h b/ecmascript/tooling/interface/file_stream.h index 0f57f8f07d0f35d51ae5f26c88624065a230d7a7..eba3c3e8e23ef9662e519f38074dda1af83e4c2f 100644 --- a/ecmascript/tooling/interface/file_stream.h +++ b/ecmascript/tooling/interface/file_stream.h @@ -36,12 +36,12 @@ public: } // Writes the chunk of data into the stream - bool WriteChunk(char* data, int size) override; + bool WriteChunk(char* data, int32_t size) override; bool Good() override; - void UpdateHeapStats([[maybe_unused]]HeapStat* data, [[maybe_unused]]int count) override + void UpdateHeapStats([[maybe_unused]] HeapStat* data, [[maybe_unused]] int32_t count) override { } - void UpdateLastSeenObjectId([[maybe_unused]]uint32_t lastSeenObjectId) override + void UpdateLastSeenObjectId([[maybe_unused]] int32_t lastSeenObjectId) override { } @@ -67,12 +67,12 @@ public: } // Writes the chunk of data into the stream - bool WriteChunk(char *data, int size) override; + bool WriteChunk(char *data, int32_t size) override; bool Good() override; - void UpdateHeapStats([[maybe_unused]]HeapStat* data, [[maybe_unused]]int count) override + void UpdateHeapStats([[maybe_unused]] HeapStat* data, [[maybe_unused]] int32_t count) override { } - void UpdateLastSeenObjectId([[maybe_unused]]uint32_t lastSeenObjectId) override + void UpdateLastSeenObjectId([[maybe_unused]] int32_t lastSeenObjectId) override { } diff --git a/ecmascript/tooling/interface/js_debugger_manager.h b/ecmascript/tooling/interface/js_debugger_manager.h index 50f7baceba461c998ab20617ff9f4f2258c4837c..f036c8fb207e1189cbe7c6b74d2a5678c2613fdd 100644 --- a/ecmascript/tooling/interface/js_debugger_manager.h +++ b/ecmascript/tooling/interface/js_debugger_manager.h @@ -28,7 +28,7 @@ class JsDebuggerManager { public: using LibraryHandle = os::library_loader::LibraryHandle; using ObjectUpdaterFunc = - std::function &)>; + std::function)>; JsDebuggerManager() = default; ~JsDebuggerManager() @@ -94,7 +94,7 @@ public: updaterFunc_ = updaterFunc; } - void NotifyLocalScopeUpdated(std::string_view varName, const Local &value) + void NotifyLocalScopeUpdated(std::string_view varName, Local value) { if (updaterFunc_ != nullptr) { (*updaterFunc_)(frameHandler_.get(), varName, value); diff --git a/ecmascript/tooling/interface/stream.h b/ecmascript/tooling/interface/stream.h index 771895c3e5963db3d8f1640dde5a59161b032172..cd7285b65d31f1ab93e041b5aee9a7de66883bf2 100644 --- a/ecmascript/tooling/interface/stream.h +++ b/ecmascript/tooling/interface/stream.h @@ -19,12 +19,12 @@ namespace panda::ecmascript { class HeapStat { public: - HeapStat(uint32_t index, uint32_t count, uint32_t size) + HeapStat(int32_t index, int32_t count, int32_t size) : index_(index), count_(count), size_(size) {} - uint32_t index_; - uint32_t count_; - uint32_t size_; + int32_t index_; + int32_t count_; + int32_t size_; }; class Stream { @@ -37,10 +37,10 @@ public: virtual int GetSize() = 0; // Writes the chunk of data into the stream - virtual bool WriteChunk(char *data, int size) = 0; + virtual bool WriteChunk(char *data, int32_t size) = 0; virtual bool Good() = 0; - virtual void UpdateHeapStats(HeapStat* data, int count) = 0; - virtual void UpdateLastSeenObjectId(uint32_t lastSeenObjectId) = 0; + virtual void UpdateHeapStats(HeapStat* data, int32_t count) = 0; + virtual void UpdateLastSeenObjectId(int32_t lastSeenObjectId) = 0; }; } // namespace panda::ecmascript diff --git a/ecmascript/tooling/protocol_handler.cpp b/ecmascript/tooling/protocol_handler.cpp index 48e18a060f99c5ea9d9deca3d423e6ed26fa162f..281e055f226a32080d4b6c97737ea2943306271f 100644 --- a/ecmascript/tooling/protocol_handler.cpp +++ b/ecmascript/tooling/protocol_handler.cpp @@ -15,18 +15,13 @@ #include "ecmascript/tooling/protocol_handler.h" -#include "ecmascript/base/string_helper.h" #include "ecmascript/tooling/agent/debugger_impl.h" -#include "utils/logger.h" namespace panda::ecmascript::tooling { void ProtocolHandler::WaitForDebugger() { waitingForDebugger_ = true; - static constexpr int DEBUGGER_WAIT_SLEEP_TIME = 100; - while (waitingForDebugger_) { - usleep(DEBUGGER_WAIT_SLEEP_TIME); - } + ProcessCommand(); } void ProtocolHandler::RunIfWaitingForDebugger() @@ -34,66 +29,98 @@ void ProtocolHandler::RunIfWaitingForDebugger() waitingForDebugger_ = false; } -void ProtocolHandler::ProcessCommand(const std::string &msg) +void ProtocolHandler::DispatchCommand(std::string &&msg) { - LOG(DEBUG, DEBUGGER) << "ProtocolHandler::ProcessCommand: " << msg; - [[maybe_unused]] LocalScope scope(vm_); - Local exception = DebuggerApi::GetAndClearException(vm_); - dispatcher_.Dispatch(DispatchRequest(vm_, msg)); - DebuggerApi::SetException(vm_, exception); + LOG_DEBUGGER(DEBUG) << "ProtocolHandler::DispatchCommand: " << msg; + std::unique_lock queueLock(requestLock_); + requestQueue_.push(std::move(msg)); + requestQueueCond_.notify_one(); +} + +// called after DispatchCommand +int32_t ProtocolHandler::GetDispatchStatus() +{ + if (isDispatchingMessage_ || waitingForDebugger_) { + return DispatchStatus::DISPATCHING; + } + std::unique_lock queueLock(requestLock_); + if (requestQueue_.empty()) { + return DispatchStatus::DISPATCHED; + } + return DispatchStatus::UNKNOWN; +} + +void ProtocolHandler::ProcessCommand() +{ + std::queue dispatchingQueue; + do { + { + std::unique_lock queueLock(requestLock_); + if (requestQueue_.empty()) { + if (!waitingForDebugger_) { + return; + } + requestQueueCond_.wait(queueLock); + } + requestQueue_.swap(dispatchingQueue); + } + + isDispatchingMessage_ = true; + while (!dispatchingQueue.empty()) { + std::string msg = std::move(dispatchingQueue.front()); + dispatchingQueue.pop(); + + [[maybe_unused]] LocalScope scope(vm_); + auto exception = DebuggerApi::GetAndClearException(vm_); + dispatcher_.Dispatch(DispatchRequest(msg)); + DebuggerApi::SetException(vm_, exception); + } + isDispatchingMessage_ = false; + } while (true); } void ProtocolHandler::SendResponse(const DispatchRequest &request, const DispatchResponse &response, const PtBaseReturns &result) { - LOG(INFO, DEBUGGER) << "ProtocolHandler::SendResponse: " + LOG_DEBUGGER(INFO) << "ProtocolHandler::SendResponse: " << (response.IsOk() ? "success" : "failed: " + response.GetMessage()); - Local reply = PtBaseTypes::NewObject(vm_); - reply->Set(vm_, StringRef::NewFromUtf8(vm_, "id"), IntegerRef::New(vm_, request.GetCallId())); - Local resultObj; + std::unique_ptr reply = PtJson::CreateObject(); + reply->Add("id", request.GetCallId()); + std::unique_ptr resultObj; if (response.IsOk()) { - resultObj = result.ToObject(vm_); + resultObj = result.ToJson(); } else { resultObj = CreateErrorReply(response); } - reply->Set(vm_, StringRef::NewFromUtf8(vm_, "result"), Local(resultObj)); - SendReply(reply); + reply->Add("result", resultObj); + SendReply(*reply); } void ProtocolHandler::SendNotification(const PtBaseEvents &events) { - LOG(DEBUG, DEBUGGER) << "ProtocolHandler::SendNotification: " << events.GetName(); - SendReply(events.ToObject(vm_)); + LOG_DEBUGGER(DEBUG) << "ProtocolHandler::SendNotification: " << events.GetName(); + SendReply(*events.ToJson()); } -void ProtocolHandler::SendReply(Local reply) +void ProtocolHandler::SendReply(const PtJson &reply) { - Local str = JSON::Stringify(vm_, reply); - if (str->IsException()) { - DebuggerApi::ClearException(vm_); - LOG(ERROR, DEBUGGER) << "json stringifier throw exception"; - return; - } - if (!str->IsString()) { - LOG(ERROR, DEBUGGER) << "ProtocolHandler::SendReply: json stringify error"; + std::string str = reply.Stringify(); + if (str.empty()) { + LOG_DEBUGGER(ERROR) << "ProtocolHandler::SendReply: json stringify error"; return; } - callback_(StringRef::Cast(*str)->ToString()); + callback_(reinterpret_cast(vm_), str); } -Local ProtocolHandler::CreateErrorReply(const DispatchResponse &response) +std::unique_ptr ProtocolHandler::CreateErrorReply(const DispatchResponse &response) { - Local result = PtBaseTypes::NewObject(vm_); + std::unique_ptr result = PtJson::CreateObject(); if (!response.IsOk()) { - result->Set(vm_, - Local(StringRef::NewFromUtf8(vm_, "code")), - IntegerRef::New(vm_, static_cast(response.GetError()))); - result->Set(vm_, - Local(StringRef::NewFromUtf8(vm_, "message")), - Local(StringRef::NewFromUtf8(vm_, response.GetMessage().c_str()))); + result->Add("code", static_cast(response.GetError())); + result->Add("message", response.GetMessage().c_str()); } return result; diff --git a/ecmascript/tooling/protocol_handler.h b/ecmascript/tooling/protocol_handler.h index cffaf53efeb6d99852b6e662c22be9022740ebc2..1a0cb129a7f0d294c22a08432e0de33c2c7726a2 100644 --- a/ecmascript/tooling/protocol_handler.h +++ b/ecmascript/tooling/protocol_handler.h @@ -16,6 +16,7 @@ #ifndef ECMASCRIPT_TOOLING_PROTOCOL_HANDLER_H #define ECMASCRIPT_TOOLING_PROTOCOL_HANDLER_H +#include #include #include #include @@ -25,13 +26,22 @@ namespace panda::ecmascript::tooling { class ProtocolHandler final : public ProtocolChannel { public: - ProtocolHandler(std::function callback, const EcmaVM *vm) + enum DispatchStatus : int32_t { + UNKNOWN = 0, + DISPATCHING, + DISPATCHED + }; + + ProtocolHandler(std::function callback, const EcmaVM *vm) : callback_(std::move(callback)), dispatcher_(vm, this), vm_(vm) {} ~ProtocolHandler() override = default; void WaitForDebugger() override; void RunIfWaitingForDebugger() override; - void ProcessCommand(const std::string &msg); + void ProcessCommand(); + void DispatchCommand(std::string &&msg); + int32_t GetDispatchStatus(); + void SendResponse(const DispatchRequest &request, const DispatchResponse &response, const PtBaseReturns &result) override; void SendNotification(const PtBaseEvents &events) override; @@ -39,14 +49,19 @@ public: private: NO_MOVE_SEMANTIC(ProtocolHandler); NO_COPY_SEMANTIC(ProtocolHandler); - Local CreateErrorReply(const DispatchResponse &response); - void SendReply(Local reply); + std::unique_ptr CreateErrorReply(const DispatchResponse &response); + void SendReply(const PtJson &reply); - std::function callback_; + std::function callback_; Dispatcher dispatcher_; bool waitingForDebugger_ {false}; const EcmaVM *vm_ {nullptr}; + + std::condition_variable requestQueueCond_; + std::queue requestQueue_; + std::mutex requestLock_; + std::atomic isDispatchingMessage_ {false}; }; } // namespace panda::ecmascript::tooling diff --git a/ecmascript/tooling/test/BUILD.gn b/ecmascript/tooling/test/BUILD.gn index 356de4942c820ed7ac8b783264ed62692ccb856f..7dc773358d7e204315b5b74a23dac01ff077ba1c 100644 --- a/ecmascript/tooling/test/BUILD.gn +++ b/ecmascript/tooling/test/BUILD.gn @@ -80,6 +80,55 @@ ts2abc_gen_abc("ark_exception_abc") { out_puts = [ test_abc_path ] } +ts2abc_gen_abc("ark_range_error_abc") { + test_js_path = "//ark/js_runtime/ecmascript/tooling/test/js/RangeError.js" + test_abc_path = "$target_out_dir/RangeError.abc" + extra_visibility = [ ":*" ] # Only targets in this file can depend on this. + src_js = rebase_path(test_js_path) + dst_file = rebase_path(test_abc_path) + extra_args = [ "--debug" ] + + in_puts = [ test_js_path ] + out_puts = [ test_abc_path ] +} + +ts2abc_gen_abc("ark_syntaxException_abc") { + test_js_path = + "//ark/js_runtime/ecmascript/tooling/test/js/syntaxException.js" + test_abc_path = "$target_out_dir/syntaxException.abc" + extra_visibility = [ ":*" ] # Only targets in this file can depend on this. + src_js = rebase_path(test_js_path) + dst_file = rebase_path(test_abc_path) + extra_args = [ "--debug" ] + + in_puts = [ test_js_path ] + out_puts = [ test_abc_path ] +} + +ts2abc_gen_abc("ark_throwException_abc") { + test_js_path = "//ark/js_runtime/ecmascript/tooling/test/js/throwException.js" + test_abc_path = "$target_out_dir/throwException.abc" + extra_visibility = [ ":*" ] # Only targets in this file can depend on this. + src_js = rebase_path(test_js_path) + dst_file = rebase_path(test_abc_path) + extra_args = [ "--debug" ] + + in_puts = [ test_js_path ] + out_puts = [ test_abc_path ] +} + +ts2abc_gen_abc("ark_stepInto_abc") { + test_js_path = "//ark/js_runtime/ecmascript/tooling/test/js/StepInto.js" + test_abc_path = "$target_out_dir/StepInto.abc" + extra_visibility = [ ":*" ] # Only targets in this file can depend on this. + src_js = rebase_path(test_js_path) + dst_file = rebase_path(test_abc_path) + extra_args = [ "--debug" ] + + in_puts = [ test_js_path ] + out_puts = [ test_abc_path ] +} + source_set("debugger_entry_set") { sources = [ "entry/test_debugger_entry.cpp" ] @@ -89,7 +138,11 @@ source_set("debugger_entry_set") { ":ark_arrowfunc_abc", ":ark_asyncfunc_abc", ":ark_exception_abc", + ":ark_range_error_abc", ":ark_sample_abc", + ":ark_stepInto_abc", + ":ark_syntaxException_abc", + ":ark_throwException_abc", ":jsdebugtest", "$ark_root/libpandabase:libarkbase", "$ark_root/libpandafile:libarkfile", @@ -113,7 +166,10 @@ source_set("jsdebugtest_set") { "utils/testcases/test_list.cpp", ] - public_configs = [ ":debug_api_test" ] + public_configs = [ + ":debug_api_test", + "//ark/js_runtime/ecmascript/tooling:ark_ecma_debugger_config", + ] test_abc_dir = "/data/test/" target_label = get_label_info(":${target_name}", "label_with_toolchain") @@ -124,11 +180,19 @@ source_set("jsdebugtest_set") { defines = [ "DEBUGGER_ABC_DIR=\"${test_abc_dir}/\"" ] + if (is_ohos && is_standard_system) { + if (enable_hilog) { + defines += [ "ENABLE_HILOG" ] + include_dirs = + [ "//base/hiviewdfx/hilog/interfaces/native/innerkits/include" ] + } + } + deps = [ "$ark_root/libpandabase:libarkbase", "$ark_root/libpandafile:libarkfile", - "//ark/js_runtime:libark_jsruntime_test_set", - "//ark/js_runtime/ecmascript/tooling:libark_ecma_debugger_test_set", + "//ark/js_runtime:libark_jsruntime_test", + "//ark/js_runtime/ecmascript/tooling:libark_ecma_debugger_test", ] } @@ -136,8 +200,8 @@ ohos_shared_library("jsdebugtest") { deps = [ ":jsdebugtest_set" ] if (is_ohos && is_standard_system) { - if (build_public_version) { - external_deps = [ "hitrace_native:hitrace_meter" ] + if (enable_hilog) { + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } } @@ -166,6 +230,8 @@ host_unittest_action("DebuggerEntryTest") { ":jsdebugtest", "$ark_root/libpandabase:libarkbase", "$ark_root/libpandafile:libarkfile", + "//ark/js_runtime:libark_jsruntime_test", + "//ark/js_runtime/ecmascript/tooling:libark_ecma_debugger_test", ] } @@ -188,6 +254,7 @@ host_unittest_action("DebuggerTest") { deps = [ "$ark_root/libpandabase:libarkbase", + "//ark/js_runtime:libark_jsruntime_test", "//ark/js_runtime/ecmascript/tooling:libark_ecma_debugger_test", sdk_libc_secshared_dep, ] diff --git a/ecmascript/tooling/test/debugger_events_test.cpp b/ecmascript/tooling/test/debugger_events_test.cpp index 175420a9942356bea31cc7378116a882a66257b2..b78e20cec956b22a20e46e1dd99a766b8ce93cb1 100644 --- a/ecmascript/tooling/test/debugger_events_test.cpp +++ b/ecmascript/tooling/test/debugger_events_test.cpp @@ -60,33 +60,6 @@ protected: JSThread *thread {nullptr}; }; -HWTEST_F_L0(DebuggerEventsTest, BreakpointResolvedToObjectTest) -{ - BreakpointResolved breakpointResolved; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - - auto location = std::make_unique(); - location->SetScriptId(2).SetLine(99); - breakpointResolved.SetBreakpointId("00").SetLocation(std::move(location)); - Local object1 = breakpointResolved.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "breakpointId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("00", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "location"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); -} - HWTEST_F_L0(DebuggerEventsTest, BreakpointResolvedToJsonTest) { BreakpointResolved breakpointResolved; @@ -111,58 +84,39 @@ HWTEST_F_L0(DebuggerEventsTest, BreakpointResolvedToJsonTest) EXPECT_EQ(lineNumber, 99); } -HWTEST_F_L0(DebuggerEventsTest, PausedToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, PausedToJsonTest) { Paused paused; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - std::vector> v; paused.SetCallFrames(std::move(v)) .SetReason(PauseReason::EXCEPTION); - Local object1 = paused.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "reason"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("exception", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrames"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + + std::unique_ptr json = paused.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + std::string reason; + ASSERT_EQ(params->GetString("reason", &reason), Result::SUCCESS); + EXPECT_EQ("exception", reason); + std::unique_ptr callFrames; + ASSERT_EQ(params->GetArray("callFrames", &callFrames), Result::SUCCESS); } -HWTEST_F_L0(DebuggerEventsTest, ResumedToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, ResumedToJsonTest) { Resumed resumed; - Local tmpStr; - - Local object = resumed.ToObject(ecmaVm); + std::unique_ptr json = resumed.ToJson(); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "method"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(resumed.GetName(), DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); + std::string method; + ASSERT_EQ(json->GetString("method", &method), Result::SUCCESS); + EXPECT_EQ(resumed.GetName(), method); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); } -HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToJsonTest) { ScriptFailedToParse parsed; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - parsed.SetScriptId(100) .SetUrl("use/test.js") .SetStartLine(0) @@ -178,111 +132,63 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptFailedToParseToObjectTest) .SetCodeOffset(432) .SetScriptLanguage("JavaScript") .SetEmbedderName("hh"); - Local object1 = parsed.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("100", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("use/test.js", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startLine"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 0); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startColumn"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 4); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endLine"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endColumn"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 2); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "hash"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hash0001", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextAuxData"); - ASSERT_FALSE(object->Has(ecmaVm, tmpStr)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "sourceMapURL"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("usr/", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "hasSourceURL"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "isModule"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "length"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 34); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "codeOffset"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 432); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptLanguage"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("JavaScript", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "embedderName"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hh", DebuggerApi::ToStdString(result)); + + std::unique_ptr json = parsed.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + std::string tmpStr; + ASSERT_EQ(params->GetString("scriptId", &tmpStr), Result::SUCCESS); + EXPECT_EQ("100", tmpStr); + + ASSERT_EQ(params->GetString("url", &tmpStr), Result::SUCCESS); + EXPECT_EQ("use/test.js", tmpStr); + + int tmpInt; + ASSERT_EQ(params->GetInt("startLine", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 0); + + ASSERT_EQ(params->GetInt("startColumn", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 4); + + ASSERT_EQ(params->GetInt("endLine", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ASSERT_EQ(params->GetInt("endColumn", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ASSERT_EQ(params->GetInt("executionContextId", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 2); + + ASSERT_EQ(params->GetString("hash", &tmpStr), Result::SUCCESS); + EXPECT_EQ("hash0001", tmpStr); + + ASSERT_EQ(params->GetString("sourceMapURL", &tmpStr), Result::SUCCESS); + EXPECT_EQ("usr/", tmpStr); + + bool tmpBool; + ASSERT_EQ(params->GetBool("hasSourceURL", &tmpBool), Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ASSERT_EQ(params->GetBool("isModule", &tmpBool), Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ASSERT_EQ(params->GetInt("length", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 34); + + ASSERT_EQ(params->GetInt("codeOffset", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 432); + + ASSERT_EQ(params->GetString("scriptLanguage", &tmpStr), Result::SUCCESS); + EXPECT_EQ("JavaScript", tmpStr); + + ASSERT_EQ(params->GetString("embedderName", &tmpStr), Result::SUCCESS); + EXPECT_EQ("hh", tmpStr); } -HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToJsonTest) { ScriptParsed parsed; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - parsed.SetScriptId(10) .SetUrl("use/test.js") .SetStartLine(0) @@ -299,116 +205,66 @@ HWTEST_F_L0(DebuggerEventsTest, ScriptParsedToObjectTest) .SetCodeOffset(432) .SetScriptLanguage("JavaScript") .SetEmbedderName("hh"); - Local object1 = parsed.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("10", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("use/test.js", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startLine"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 0); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startColumn"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 4); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endLine"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endColumn"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 2); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "hash"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hash0001", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextAuxData"); - ASSERT_FALSE(object->Has(ecmaVm, tmpStr)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "isLiveEdit"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "sourceMapURL"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("usr/", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "hasSourceURL"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "isModule"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "length"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 34); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "codeOffset"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 432); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptLanguage"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("JavaScript", DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "embedderName"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("hh", DebuggerApi::ToStdString(result)); + + std::unique_ptr json = parsed.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + std::string tmpStr; + ASSERT_EQ(params->GetString("scriptId", &tmpStr), Result::SUCCESS); + EXPECT_EQ("10", tmpStr); + + ASSERT_EQ(params->GetString("url", &tmpStr), Result::SUCCESS); + EXPECT_EQ("use/test.js", tmpStr); + + int tmpInt; + ASSERT_EQ(params->GetInt("startLine", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 0); + + ASSERT_EQ(params->GetInt("startColumn", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 4); + + ASSERT_EQ(params->GetInt("endLine", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ASSERT_EQ(params->GetInt("endColumn", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ASSERT_EQ(params->GetInt("executionContextId", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 2); + + ASSERT_EQ(params->GetString("hash", &tmpStr), Result::SUCCESS); + EXPECT_EQ("hash0001", tmpStr); + + bool tmpBool; + ASSERT_EQ(params->GetBool("isLiveEdit", &tmpBool), Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ASSERT_EQ(params->GetString("sourceMapURL", &tmpStr), Result::SUCCESS); + EXPECT_EQ("usr/", tmpStr); + + ASSERT_EQ(params->GetBool("hasSourceURL", &tmpBool), Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ASSERT_EQ(params->GetBool("isModule", &tmpBool), Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ASSERT_EQ(params->GetInt("length", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 34); + + ASSERT_EQ(params->GetInt("codeOffset", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 432); + + ASSERT_EQ(params->GetString("scriptLanguage", &tmpStr), Result::SUCCESS); + EXPECT_EQ("JavaScript", tmpStr); + + ASSERT_EQ(params->GetString("embedderName", &tmpStr), Result::SUCCESS); + EXPECT_EQ("hh", tmpStr); } -HWTEST_F_L0(DebuggerEventsTest, ConsoleProfileFinishedToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, ConsoleProfileFinishedToJsonTest) { ConsoleProfileFinished consoleProfileFinished; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); auto location = std::make_unique(); location->SetScriptId(13).SetLine(20); @@ -420,172 +276,161 @@ HWTEST_F_L0(DebuggerEventsTest, ConsoleProfileFinishedToObjectTest) .SetSamples(std::vector{}) .SetTimeDeltas(std::vector{}); consoleProfileFinished.SetId("11").SetLocation(std::move(location)).SetProfile(std::move(profile)).SetTitle("001"); - Local object1 = consoleProfileFinished.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "id"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "11"); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "location"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "profile"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "title"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "001"); + + std::unique_ptr json = consoleProfileFinished.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + std::string tmpStr; + ASSERT_EQ(params->GetString("id", &tmpStr), Result::SUCCESS); + EXPECT_EQ("11", tmpStr); + + std::unique_ptr tmpJson; + ASSERT_EQ(params->GetObject("location", &tmpJson), Result::SUCCESS); + ASSERT_EQ(params->GetObject("profile", &tmpJson), Result::SUCCESS); + + ASSERT_EQ(params->GetString("title", &tmpStr), Result::SUCCESS); + EXPECT_EQ("001", tmpStr); } -HWTEST_F_L0(DebuggerEventsTest, ConsoleProfileStartedToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, ConsoleProfileStartedToJsonTest) { ConsoleProfileStarted consoleProfileStarted; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); auto location = std::make_unique(); location->SetScriptId(17).SetLine(30); consoleProfileStarted.SetId("12").SetLocation(std::move(location)).SetTitle("002"); - Local object1 = consoleProfileStarted.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "id"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "12"); - - Local tmpObject = consoleProfileStarted.GetLocation()->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - Local tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(tmpResult), "17"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(Local(tmpResult)->Value(), 30); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "title"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "002"); + + std::unique_ptr json = consoleProfileStarted.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + std::string tmpStr; + ASSERT_EQ(params->GetString("id", &tmpStr), Result::SUCCESS); + EXPECT_EQ("12", tmpStr); + + std::unique_ptr tmpJson = consoleProfileStarted.GetLocation()->ToJson(); + ASSERT_EQ(tmpJson->GetString("scriptId", &tmpStr), Result::SUCCESS); + EXPECT_EQ("17", tmpStr); + int tmpInt; + ASSERT_EQ(tmpJson->GetInt("lineNumber", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 30); + + ASSERT_EQ(params->GetString("title", &tmpStr), Result::SUCCESS); + EXPECT_EQ("002", tmpStr); } -HWTEST_F_L0(DebuggerEventsTest, PreciseCoverageDeltaUpdateToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, PreciseCoverageDeltaUpdateToJsonTest) { PreciseCoverageDeltaUpdate preciseCoverageDeltaUpdate; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); std::vector> v; preciseCoverageDeltaUpdate.SetOccasion("percise") .SetResult(std::move(v)) .SetTimestamp(77); - Local object1 = preciseCoverageDeltaUpdate.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "timestamp"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 77); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "occasion"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "percise"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + + std::unique_ptr json = preciseCoverageDeltaUpdate.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + int64_t tmpInt; + ASSERT_EQ(params->GetInt64("timestamp", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 77); + + std::string tmpStr; + ASSERT_EQ(params->GetString("occasion", &tmpStr), Result::SUCCESS); + EXPECT_EQ("percise", tmpStr); + + std::unique_ptr tmpArray; + ASSERT_EQ(params->GetArray("result", &tmpArray), Result::SUCCESS); } -HWTEST_F_L0(DebuggerEventsTest, HeapStatsUpdateToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, HeapStatsUpdateToJsonTest) { HeapStatsUpdate heapStatsUpdate; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - - heapStatsUpdate.SetStatsUpdate(std::vector {}); - Local object1 = heapStatsUpdate.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "statsUpdate"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + heapStatsUpdate.SetStatsUpdate(std::vector {}); + + std::unique_ptr json = heapStatsUpdate.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + std::unique_ptr tmpArray; + ASSERT_EQ(params->GetArray("statsUpdate", &tmpArray), Result::SUCCESS); } -HWTEST_F_L0(DebuggerEventsTest, LastSeenObjectIdToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, LastSeenObjectIdToJsonTest) { LastSeenObjectId lastSeenObjectId; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - lastSeenObjectId.SetLastSeenObjectId(10).SetTimestamp(77); - Local object1 = lastSeenObjectId.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lastSeenObjectId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "timestamp"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 77); + + std::unique_ptr json = lastSeenObjectId.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + int64_t tmpInt64; + ASSERT_EQ(params->GetInt64("timestamp", &tmpInt64), Result::SUCCESS); + EXPECT_EQ(tmpInt64, 77); + + int tmpInt; + ASSERT_EQ(params->GetInt("lastSeenObjectId", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); } -HWTEST_F_L0(DebuggerEventsTest, ReportHeapSnapshotProgressToObjectTest) +HWTEST_F_L0(DebuggerEventsTest, ReportHeapSnapshotProgressToJsonTest) { ReportHeapSnapshotProgress reportHeapSnapshotProgress; - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "params"); - reportHeapSnapshotProgress.SetDone(10).SetTotal(100); - Local object1 = reportHeapSnapshotProgress.ToObject(ecmaVm); - Local result = object1->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - Local object = Local(result); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "done"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "total"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 100); + + std::unique_ptr json = reportHeapSnapshotProgress.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + int tmpInt; + ASSERT_EQ(params->GetInt("done", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ASSERT_EQ(params->GetInt("total", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 100); +} + +HWTEST_F_L0(DebuggerEventsTest, BufferUsageToJsonTest) +{ + BufferUsage bufferUsage; + bufferUsage.SetPercentFull(17).SetEventCount(15).SetValue(12); + + std::unique_ptr json = bufferUsage.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + int tmpInt; + ASSERT_EQ(params->GetInt("percentFull", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 17); + + ASSERT_EQ(params->GetInt("eventCount", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 15); + + ASSERT_EQ(params->GetInt("value", &tmpInt), Result::SUCCESS); + EXPECT_EQ(tmpInt, 12); +} + +HWTEST_F_L0(DebuggerEventsTest, TracingCompleteToJsonTest) +{ + TracingComplete tracingComplete; + auto traceFormat = std::make_unique(); + auto streamCompression = std::make_unique(); + tracingComplete.SetDataLossOccurred(true) + .SetTraceFormat(std::move(traceFormat)) + .SetStreamCompression(std::move(streamCompression)); + + std::unique_ptr json = tracingComplete.ToJson(); + std::unique_ptr params; + ASSERT_EQ(json->GetObject("params", ¶ms), Result::SUCCESS); + + bool tmpBool; + ASSERT_EQ(params->GetBool("dataLossOccurred", &tmpBool), Result::SUCCESS); + + std::string tmpStr; + ASSERT_EQ(params->GetString("traceFormat", &tmpStr), Result::SUCCESS); + ASSERT_EQ(params->GetString("streamCompression", &tmpStr), Result::SUCCESS); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tooling/test/debugger_params_test.cpp b/ecmascript/tooling/test/debugger_params_test.cpp index b9802d058816fc66b6e5ccbace265d0b5054fee4..6b2e83a0a6f540a0712bba6b93c838401bb2f021 100644 --- a/ecmascript/tooling/test/debugger_params_test.cpp +++ b/ecmascript/tooling/test/debugger_params_test.cpp @@ -72,13 +72,13 @@ HWTEST_F_L0(DebuggerParamsTest, EnableParamsCreateTest) // abnormal msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - enableParams = EnableParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); + enableParams = EnableParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(enableParams, nullptr); EXPECT_FALSE(enableParams->HasMaxScriptsCacheSize()); // normal msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"maxScriptsCacheSize":100}})"; - enableParams = EnableParams::Create(DispatchRequest(ecmaVm, msg).GetParams()); + enableParams = EnableParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(enableParams, nullptr); EXPECT_EQ(enableParams->GetMaxScriptsCacheSize(), 100); } @@ -88,41 +88,31 @@ HWTEST_F_L0(DebuggerParamsTest, StartSamplingParamsCreateTest) std::string msg; std::unique_ptr startSamplingData; - // abnormal params of null msg - msg = std::string() + R"({})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(startSamplingData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(startSamplingData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(startSamplingData, nullptr); EXPECT_EQ(startSamplingData->GetSamplingInterval(), 32768); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(startSamplingData, nullptr); EXPECT_EQ(startSamplingData->GetSamplingInterval(), 32768); // abnormal params of params.sub-key=["samplingInterval":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"samplingInterval":true}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(startSamplingData, nullptr); // abnormal params of params.sub-key=["samplingInterval":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"samplingInterval":"Test"}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(startSamplingData, nullptr); // abnormal params of params.sub-key = [ "size"=100,"nodeId"=1,"ordinal"=10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"samplingInterval":1000}})"; - startSamplingData = StartSamplingParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + startSamplingData = StartSamplingParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(startSamplingData, nullptr); EXPECT_EQ(startSamplingData->GetSamplingInterval(), 1000); } @@ -132,41 +122,31 @@ HWTEST_F_L0(DebuggerParamsTest, StartTrackingHeapObjectsParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetTrackAllocations()); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetTrackAllocations()); // abnormal params of params.sub-key=["trackAllocations":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":10}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["trackAllocations":"Test"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":"Test"}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["trackAllocations":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"trackAllocations":true}})"; - objectData = StartTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_TRUE(objectData->GetTrackAllocations()); } @@ -176,19 +156,9 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetReportProgress()); ASSERT_FALSE(objectData->GetTreatGlobalObjectsAsRoots()); @@ -196,7 +166,7 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsCreateTest) // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_FALSE(objectData->GetReportProgress()); ASSERT_FALSE(objectData->GetTreatGlobalObjectsAsRoots()); @@ -206,21 +176,21 @@ HWTEST_F_L0(DebuggerParamsTest, StopTrackingHeapObjectsParamsCreateTest) "reportProgress":10, "treatGlobalObjectsAsRoots":10, "captureNumericValue":10}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "reportProgress":"Test", "treatGlobalObjectsAsRoots":"Test", "captureNumericValue":"Test"}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "reportProgress":true, "treatGlobalObjectsAsRoots":true, "captureNumericValue":true}})"; - objectData = StopTrackingHeapObjectsParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StopTrackingHeapObjectsParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_TRUE(objectData->GetReportProgress()); ASSERT_TRUE(objectData->GetTreatGlobalObjectsAsRoots()); @@ -234,39 +204,39 @@ HWTEST_F_L0(DebuggerParamsTest, AddInspectedHeapObjectParamsCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["heapObjectId":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":10}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["heapObjectId":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":true}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["heapObjectId":“10”] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"heapObjectId":"10"}})"; - objectData = AddInspectedHeapObjectParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = AddInspectedHeapObjectParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); - EXPECT_EQ((int)objectData->GetHeapObjectId(), 10); + EXPECT_EQ(objectData->GetHeapObjectId(), 10); } HWTEST_F_L0(DebuggerParamsTest, GetHeapObjectIdParamsCreateTest) @@ -274,39 +244,19 @@ HWTEST_F_L0(DebuggerParamsTest, GetHeapObjectIdParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of null params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unknown params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of params.sub-key=["objectId":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":10}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":true}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":“10”] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})"; - objectData = GetHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ((int)objectData->GetObjectId(), 10); } @@ -316,45 +266,25 @@ HWTEST_F_L0(DebuggerParamsTest, GetObjectByHeapObjectIdParamsCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of null params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unknown params.sub-key - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of params.sub-key=["objectId":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":10}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":10}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of params.sub-key=["objectId":“10”] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10"}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ((int)objectData->GetObjectId(), 10); ASSERT_FALSE(objectData->HasObjectGroup()); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"objectId":"10", "objectGroup":"groupname"}})"; - objectData = GetObjectByHeapObjectIdParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = GetObjectByHeapObjectIdParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ((int)objectData->GetObjectId(), 10); EXPECT_EQ(objectData->GetObjectGroup(), "groupname"); @@ -365,45 +295,35 @@ HWTEST_F_L0(DebuggerParamsTest, StartPreciseCoverageParamCreateTest) std::string msg; std::unique_ptr objectData; - // abnormal params of null msg - msg = std::string() + R"({})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - - // abnormal params of unexist key params - msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - EXPECT_EQ(objectData, nullptr); - // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callCount":8, "detailed":8, "allowTriggeredUpdates":8}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callCount":"Test", "detailed":"Test", "allowTriggeredUpdates":"Test"}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callCount":true, "detailed":true, "allowTriggeredUpdates":true}})"; - objectData = StartPreciseCoverageParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = StartPreciseCoverageParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); ASSERT_TRUE(objectData->GetCallCount()); ASSERT_TRUE(objectData->GetDetailed()); @@ -417,32 +337,140 @@ HWTEST_F_L0(DebuggerParamsTest, SetSamplingIntervalParamsCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "interval":"500"}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(objectData, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"interval":500}})"; - objectData = SetSamplingIntervalParams::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + objectData = SetSamplingIntervalParams::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(objectData, nullptr); EXPECT_EQ(objectData->GetInterval(), 500); } + +HWTEST_F_L0(DebuggerParamsTest, RecordClockSyncMarkerParamsCreateTest) +{ + std::string msg; + std::unique_ptr objectData; + + // abnormal params of null msg + msg = std::string() + R"({})"; + objectData = RecordClockSyncMarkerParams::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(objectData, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + objectData = RecordClockSyncMarkerParams::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(objectData, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + objectData = RecordClockSyncMarkerParams::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(objectData, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + objectData = RecordClockSyncMarkerParams::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(objectData, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"syncId":"101"}})"; + objectData = RecordClockSyncMarkerParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + EXPECT_EQ(objectData->GetSyncId(), "101"); +} + +HWTEST_F_L0(DebuggerParamsTest, RequestMemoryDumpParamsCreateTest) +{ + std::string msg; + std::unique_ptr objectData; + + // abnormal params of null msg + msg = std::string() + R"({})"; + objectData = RequestMemoryDumpParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + objectData = RequestMemoryDumpParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + objectData = RequestMemoryDumpParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + objectData = RequestMemoryDumpParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"deterministic":true, + "levelOfDetail":"background"}})"; + objectData = RequestMemoryDumpParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + ASSERT_TRUE(objectData->GetDeterministic()); + EXPECT_EQ(objectData->GetLevelOfDetail(), "background"); +} + +HWTEST_F_L0(DebuggerParamsTest, StartParamsCreateTest) +{ + std::string msg; + std::unique_ptr objectData; + + // abnormal params of null msg + msg = std::string() + R"({})"; + objectData = StartParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + objectData = StartParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + objectData = StartParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + objectData = StartParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"categories":"filter1", + "options":"1", "bufferUsageReportingInterval":11, "transferMode":"ReportEvents", "streamFormat":"json", + "streamCompression":"none", "traceConfig": {"recordMode":"recordUntilFull"}, "perfettoConfig":"categories", + "tracingBackend":"auto"}})"; + objectData = StartParams::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(objectData, nullptr); + EXPECT_EQ(objectData->GetCategories(), "filter1"); + EXPECT_EQ(objectData->GetOptions(), "1"); + EXPECT_EQ(objectData->GetBufferUsageReportingInterval(), 11); + EXPECT_EQ(objectData->GetTransferMode(), "ReportEvents"); + EXPECT_EQ(objectData->GetStreamFormat(), "json"); + EXPECT_EQ(objectData->GetStreamCompression(), "none"); + TraceConfig *traceConfig = objectData->GetTraceConfig(); + ASSERT_NE(traceConfig, nullptr); + EXPECT_EQ(traceConfig->GetRecordMode(), "recordUntilFull"); + EXPECT_EQ(objectData->GetPerfettoConfig(), "categories"); + EXPECT_EQ(objectData->GetTracingBackend(), "auto"); +} } // namespace panda::test diff --git a/ecmascript/tooling/test/debugger_returns_test.cpp b/ecmascript/tooling/test/debugger_returns_test.cpp index 1d60edf8e2a56b6d5c795a23f8b3f6614a63ce80..8ea789525ff4c110c41f9021b9e848dd0d100b1e 100644 --- a/ecmascript/tooling/test/debugger_returns_test.cpp +++ b/ecmascript/tooling/test/debugger_returns_test.cpp @@ -60,325 +60,343 @@ protected: JSThread *thread {nullptr}; }; -HWTEST_F_L0(DebuggerReturnsTest, EnableReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, EnableReturnsToJsonTest) { std::unique_ptr enableReturns = std::make_unique(100U); ASSERT_NE(enableReturns, nullptr); - Local enableObject = enableReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "debuggerId"); - ASSERT_TRUE(enableObject->Has(ecmaVm, tmpStr)); - Local result = enableObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("100"), DebuggerApi::ToStdString(result)); + + std::string debuggerId; + ASSERT_EQ(enableReturns->ToJson()->GetString("debuggerId", &debuggerId), Result::SUCCESS); + EXPECT_EQ(debuggerId, "100"); } -HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointByUrlReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointByUrlReturnsToJsonTest) { auto locations = std::vector>(); std::unique_ptr location = std::make_unique(); - location->SetScriptId(1); + location->SetScriptId(1).SetLine(99); locations.emplace_back(std::move(location)); - ASSERT_EQ(locations.back()->GetScriptId(), 1); - std::unique_ptr setBreakpointByUrlReturns = std::make_unique("11", std::move(locations)); ASSERT_NE(setBreakpointByUrlReturns, nullptr); - Local setObject = setBreakpointByUrlReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "breakpointId"); - ASSERT_TRUE(setObject->Has(ecmaVm, tmpStr)); - Local result = setObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("11"), DebuggerApi::ToStdString(result)); + std::string id; + ASSERT_EQ(setBreakpointByUrlReturns->ToJson()->GetString("breakpointId", &id), Result::SUCCESS); + EXPECT_EQ(id, "11"); + + std::unique_ptr locationsJson; + ASSERT_EQ(setBreakpointByUrlReturns->ToJson()->GetArray("locations", &locationsJson), Result::SUCCESS); + ASSERT_NE(locationsJson, nullptr); + EXPECT_EQ(locationsJson->GetSize(), 1); } -HWTEST_F_L0(DebuggerReturnsTest, EvaluateOnCallFrameReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, EvaluateOnCallFrameReturnsToJsonTest) { - std::unique_ptr result1 = std::make_unique(); + std::unique_ptr result = std::make_unique(); + result->SetType("idle"); std::unique_ptr exceptionDetails = std::make_unique(); + exceptionDetails->SetExceptionId(12); std::unique_ptr evaluateOnCallFrameReturns - = std::make_unique(std::move(result1), std::move(exceptionDetails)); + = std::make_unique(std::move(result), std::move(exceptionDetails)); ASSERT_NE(evaluateOnCallFrameReturns, nullptr); - Local callObject = evaluateOnCallFrameReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(callObject->Has(ecmaVm, tmpStr)); - Local result = callObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_EQ(std::move(result1), nullptr); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "exceptionDetails"); - ASSERT_TRUE(callObject->Has(ecmaVm, tmpStr)); - result = callObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_EQ(std::move(exceptionDetails), nullptr); + std::unique_ptr json; + ASSERT_EQ(evaluateOnCallFrameReturns->ToJson()->GetObject("result", &json), Result::SUCCESS); + std::string type; + ASSERT_EQ(json->GetString("type", &type), Result::SUCCESS); + EXPECT_EQ(type, "idle"); + + std::unique_ptr tmpJson; + ASSERT_EQ(evaluateOnCallFrameReturns->ToJson()->GetObject("exceptionDetails", &tmpJson), Result::SUCCESS); + int32_t exceptionId; + ASSERT_EQ(tmpJson->GetInt("exceptionId", &exceptionId), Result::SUCCESS); + EXPECT_EQ(exceptionId, 12); } -HWTEST_F_L0(DebuggerReturnsTest, GetPossibleBreakpointsReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetPossibleBreakpointsReturnsToJsonTest) { auto locations = std::vector>(); std::unique_ptr breakLocation = std::make_unique(); + breakLocation->SetScriptId(11).SetLine(1).SetColumn(44).SetType("idel5"); + locations.emplace_back(std::move(breakLocation)); std::unique_ptr getPossibleBreakpointsReturns = std::make_unique (std::move(locations)); - Local getObject = getPossibleBreakpointsReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "locations"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local result = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + + std::unique_ptr locationsJson; + ASSERT_EQ(getPossibleBreakpointsReturns->ToJson()->GetArray("locations", &locationsJson), Result::SUCCESS); + ASSERT_NE(locationsJson, nullptr); + EXPECT_EQ(locationsJson->GetSize(), 1); } -HWTEST_F_L0(DebuggerReturnsTest, GetScriptSourceReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetScriptSourceReturnsToJsonTest) { std::unique_ptr getScriptSourceReturns = std::make_unique - ("source_1", "bytecode_1"); + ("source_1", "bytecode_1"); ASSERT_NE(getScriptSourceReturns, nullptr); - Local scriptObject = getScriptSourceReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptSource"); - ASSERT_TRUE(scriptObject->Has(ecmaVm, tmpStr)); - Local result = scriptObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("source_1"), DebuggerApi::ToStdString(result)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "bytecode"); - ASSERT_TRUE(scriptObject->Has(ecmaVm, tmpStr)); - result = scriptObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("bytecode_1"), DebuggerApi::ToStdString(result)); + + std::string scriptSource; + ASSERT_EQ(getScriptSourceReturns->ToJson()->GetString("scriptSource", &scriptSource), Result::SUCCESS); + EXPECT_EQ(scriptSource, "source_1"); + + std::string bytecode; + ASSERT_EQ(getScriptSourceReturns->ToJson()->GetString("bytecode", &bytecode), Result::SUCCESS); + EXPECT_EQ(bytecode, "bytecode_1"); } -HWTEST_F_L0(DebuggerReturnsTest, RestartFrameReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, RestartFrameReturnsToJsonTest) { auto callFrames = std::vector>(); std::unique_ptr callFrame = std::make_unique(); + std::unique_ptr location = std::make_unique(); + location->SetScriptId(13).SetLine(16); + + std::unique_ptr res = std::make_unique(); + res->SetType("idle2"); + + callFrame->SetCallFrameId(55); + callFrame->SetLocation(std::move(location)); + callFrame->SetThis(std::move(res)); + callFrames.emplace_back(std::move(callFrame)); std::unique_ptr restartFrameReturns = std::make_unique - (std::move(callFrames)); - Local restartObject = restartFrameReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrames"); - ASSERT_TRUE(restartObject->Has(ecmaVm, tmpStr)); - Local result = restartObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + (std::move(callFrames)); + + std::unique_ptr json; + ASSERT_EQ(restartFrameReturns->ToJson()->GetArray("callFrames", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 1); } -HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, SetBreakpointReturnsToJsonTest) { std::unique_ptr location = std::make_unique(); std::unique_ptr setBreakpointReturns = std::make_unique("breakpointId_1", std::move(location)); ASSERT_NE(setBreakpointReturns, nullptr); - Local breakObject = setBreakpointReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "breakpointId"); - ASSERT_TRUE(breakObject->Has(ecmaVm, tmpStr)); - Local result = breakObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("breakpointId_1"), DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "actualLocation"); - ASSERT_TRUE(breakObject->Has(ecmaVm, tmpStr)); - result = breakObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_EQ(std::move(location), nullptr); + std::string breakpointId; + ASSERT_EQ(setBreakpointReturns->ToJson()->GetString("breakpointId", &breakpointId), Result::SUCCESS); + EXPECT_EQ(breakpointId, "breakpointId_1"); + + std::unique_ptr tmpJson; + ASSERT_EQ(setBreakpointReturns->ToJson()->GetObject("actualLocation", &tmpJson), Result::SUCCESS); } -HWTEST_F_L0(DebuggerReturnsTest, SetInstrumentationBreakpointReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, SetInstrumentationBreakpointReturnsToJsonTest) { std::unique_ptr setInstrumentationBreakpointReturns = std::make_unique("111"); ASSERT_NE(setInstrumentationBreakpointReturns, nullptr); - Local instrumentationObject = setInstrumentationBreakpointReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "breakpointId"); - ASSERT_TRUE(instrumentationObject->Has(ecmaVm, tmpStr)); - Local result = instrumentationObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("111"), DebuggerApi::ToStdString(result)); + + std::string breakpointId; + ASSERT_EQ(setInstrumentationBreakpointReturns->ToJson()->GetString("breakpointId", &breakpointId), + Result::SUCCESS); + EXPECT_EQ(breakpointId, "111"); } -HWTEST_F_L0(DebuggerReturnsTest, SetScriptSourceReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, SetScriptSourceReturnsToJsonTest) { auto callFrames = std::vector>(); std::unique_ptr callFrame = std::make_unique(); - std::unique_ptr exceptionDetails = std::make_unique(); + std::unique_ptr location = std::make_unique(); + location->SetScriptId(3).SetLine(36); + + std::unique_ptr res = std::make_unique(); + res->SetType("idle5"); + + callFrame->SetCallFrameId(33); + callFrame->SetLocation(std::move(location)); + callFrame->SetThis(std::move(res)); + callFrames.emplace_back(std::move(callFrame)); std::unique_ptr setScriptSourceReturns = std::make_unique (std::move(callFrames)); - Local setObject = setScriptSourceReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrames"); - ASSERT_TRUE(setObject->Has(ecmaVm, tmpStr)); - Local result = setObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - - ASSERT_NE(setScriptSourceReturns, nullptr); - exceptionDetails->SetScriptId(5); - ASSERT_EQ(exceptionDetails->GetScriptId(), 5); + + std::unique_ptr json; + ASSERT_EQ(setScriptSourceReturns->ToJson()->GetArray("callFrames", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 1); } -HWTEST_F_L0(DebuggerReturnsTest, GetPropertiesReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetPropertiesReturnsToJsonTest) { auto descriptor = std::vector>(); std::unique_ptr propertyDescriptor = std::make_unique(); - std::unique_ptr exceptionDetails = std::make_unique(); + propertyDescriptor->SetName("filename1").SetConfigurable(true).SetEnumerable(true); + descriptor.emplace_back(std::move(propertyDescriptor)); std::unique_ptr getPropertiesReturns = std::make_unique (std::move(descriptor)); ASSERT_NE(getPropertiesReturns, nullptr); - exceptionDetails->SetScriptId(6); - ASSERT_EQ(exceptionDetails->GetScriptId(), 6); - - Local getObject = getPropertiesReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local result = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - - auto internalDescripties = std::vector>(); - std::unique_ptr internalPropertyDescriptor = - std::make_unique(); - internalPropertyDescriptor->SetName("filename1"); - internalDescripties.emplace_back(std::move(internalPropertyDescriptor)); - ASSERT_EQ(internalDescripties.back()->GetName(), "filename1"); - - auto privateProperties = std::vector>(); - std::unique_ptr privatePropertyDescriptor = - std::make_unique(); - privatePropertyDescriptor->SetName("filename2"); - privateProperties.emplace_back(std::move(privatePropertyDescriptor)); - ASSERT_EQ(privateProperties.back()->GetName(), "filename2"); + + std::unique_ptr json; + ASSERT_EQ(getPropertiesReturns->ToJson()->GetArray("result", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 1); } -HWTEST_F_L0(DebuggerReturnsTest, StopSamplingReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, CallFunctionOnReturnsToJsonTest) { + std::unique_ptr result = std::make_unique(); + result->SetType("idle2"); + std::unique_ptr exceptionDetails = std::make_unique(); + std::unique_ptr callFunctionOnReturns + = std::make_unique(std::move(result), std::move(exceptionDetails)); + ASSERT_NE(callFunctionOnReturns, nullptr); + std::unique_ptr json; + ASSERT_EQ(callFunctionOnReturns->ToJson()->GetObject("result", &json), Result::SUCCESS); + std::string type; + ASSERT_EQ(json->GetString("type", &type), Result::SUCCESS); + EXPECT_EQ(type, "idle2"); + + std::unique_ptr tmpJson; + ASSERT_EQ(callFunctionOnReturns->ToJson()->GetObject("exceptionDetails", &tmpJson), Result::SUCCESS); +} + +HWTEST_F_L0(DebuggerReturnsTest, StopSamplingReturnsToJsonTest) +{ + auto res = std::vector>(); + std::unique_ptr runtime = std::make_unique(); + std::unique_ptr node = std::make_unique(); + node->SetCallFrame(std::move(runtime)); std::unique_ptr profile = std::make_unique(); + profile->SetHead(std::move(node)); + profile->SetSamples(std::move(res)); std::unique_ptr stopSamplingReturns = std::make_unique(std::move(profile)); ASSERT_NE(stopSamplingReturns, nullptr); - Local object = stopSamplingReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "profile"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); + + std::unique_ptr json; + ASSERT_EQ(stopSamplingReturns->ToJson()->GetObject("profile", &json), Result::SUCCESS); } -HWTEST_F_L0(DebuggerReturnsTest, GetHeapObjectIdReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetHeapObjectIdReturnsToJsonTest) { std::unique_ptr getHeapObjectIdReturns = std::make_unique(10); ASSERT_NE(getHeapObjectIdReturns, nullptr); - - Local object = getHeapObjectIdReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "heapSnapshotObjectId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string("10"), DebuggerApi::ToStdString(result)); + + std::string heapSnapshotObjectId; + ASSERT_EQ(getHeapObjectIdReturns->ToJson()->GetString("heapSnapshotObjectId", &heapSnapshotObjectId), + Result::SUCCESS); + EXPECT_EQ(heapSnapshotObjectId, "10"); } -HWTEST_F_L0(DebuggerReturnsTest, GetObjectByHeapObjectIdReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetObjectByHeapObjectIdReturnsToJsonTest) { std::unique_ptr remoteObjectResult = std::make_unique(); + remoteObjectResult->SetType("idle5"); std::unique_ptr getObjectByHeapObjectIdReturns = std::make_unique(std::move(remoteObjectResult)); ASSERT_NE(getObjectByHeapObjectIdReturns, nullptr); - Local object = getObjectByHeapObjectIdReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_EQ(std::move(remoteObjectResult), nullptr); + std::unique_ptr json; + ASSERT_EQ(getObjectByHeapObjectIdReturns->ToJson()->GetObject("result", &json), Result::SUCCESS); + std::string type; + ASSERT_EQ(json->GetString("type", &type), Result::SUCCESS); + EXPECT_EQ(type, "idle5"); } -HWTEST_F_L0(DebuggerReturnsTest, StopReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, StopReturnsToJsonTest) { std::unique_ptr profile = std::make_unique(); std::unique_ptr stopReturns= std::make_unique(std::move(profile)); ASSERT_NE(stopReturns, nullptr); - Local temp = stopReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "profile"); - ASSERT_TRUE(temp->Has(ecmaVm, tmpStr)); - Local result = temp->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); + + std::unique_ptr json; + ASSERT_EQ(stopReturns->ToJson()->GetObject("profile", &json), Result::SUCCESS); } -HWTEST_F_L0(DebuggerReturnsTest, GetHeapUsageReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetHeapUsageReturnsToJsonTest) { double usedSize = 1; double totalSize = 1; std::unique_ptr getHeapUsageReturns = std::make_unique(usedSize, totalSize); ASSERT_NE(getHeapUsageReturns, nullptr); - Local getObject = getHeapUsageReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "usedSize"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local result = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 1); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "totalSize"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - result = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 1); + + double pUsedSize; + ASSERT_EQ(getHeapUsageReturns->ToJson()->GetDouble("usedSize", &pUsedSize), Result::SUCCESS); + EXPECT_EQ(pUsedSize, 1); + + double pTotalSize; + ASSERT_EQ(getHeapUsageReturns->ToJson()->GetDouble("totalSize", &pTotalSize), Result::SUCCESS); + EXPECT_EQ(pTotalSize, 1); } -HWTEST_F_L0(DebuggerReturnsTest, GetBestEffortCoverageReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, GetBestEffortCoverageReturnsToJsonTest) { auto result = std::vector>(); std::unique_ptr scriptCoverage = std::make_unique(); std::unique_ptr getBestEffortCoverageReturns = std::make_unique(std::move(result)); - Local getObject = getBestEffortCoverageReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local tmpResult = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - ASSERT_TRUE(tmpResult->IsArray(ecmaVm)); + + std::unique_ptr json; + ASSERT_EQ(getBestEffortCoverageReturns->ToJson()->GetArray("result", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 0); } -HWTEST_F_L0(DebuggerReturnsTest, StartPreciseCoverageReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, StartPreciseCoverageReturnsToJsonTest) { std::unique_ptr startPreciseCoverageReturns = std::make_unique(1001); ASSERT_NE(startPreciseCoverageReturns, nullptr); - Local getObject = startPreciseCoverageReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "timestamp"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local result = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 1001); + + int32_t timestamp; + ASSERT_EQ(startPreciseCoverageReturns->ToJson()->GetInt("timestamp", ×tamp), Result::SUCCESS); + EXPECT_EQ(timestamp, 1001); } -HWTEST_F_L0(DebuggerReturnsTest, TakePreciseCoverageReturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, TakePreciseCoverageReturnsToJsonTest) { auto coverage = std::vector>(); std::unique_ptr takePreciseCoverageReturns = std::make_unique(std::move(coverage), 1001); ASSERT_NE(takePreciseCoverageReturns, nullptr); - Local getObject = takePreciseCoverageReturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local result = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - - Local instrumentationObject = takePreciseCoverageReturns->ToObject(ecmaVm); - Local tmperStr = StringRef::NewFromUtf8(ecmaVm, "timestamp"); - ASSERT_TRUE(instrumentationObject->Has(ecmaVm, tmperStr)); - Local tmpResult = instrumentationObject->Get(ecmaVm, tmperStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(Local(tmpResult)->Value(), 1001); + + std::unique_ptr json; + ASSERT_EQ(takePreciseCoverageReturns->ToJson()->GetArray("result", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 0); + + int32_t timestamp; + ASSERT_EQ(takePreciseCoverageReturns->ToJson()->GetInt("timestamp", ×tamp), Result::SUCCESS); + EXPECT_EQ(timestamp, 1001); } -HWTEST_F_L0(DebuggerReturnsTest, TakeTypeProfileturnsToObjectTest) +HWTEST_F_L0(DebuggerReturnsTest, TakeTypeProfileturnsToJsonTest) { auto result = std::vector>(); std::unique_ptr scriptTypeProfile = std::make_unique(); - std::unique_ptr takeTypeProfileturns = std::make_unique - (std::move(result)); - Local getObject = takeTypeProfileturns->ToObject(ecmaVm); - Local tmpStr = StringRef::NewFromUtf8(ecmaVm, "result"); - ASSERT_TRUE(getObject->Has(ecmaVm, tmpStr)); - Local tmpResult = getObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - ASSERT_TRUE(tmpResult->IsArray(ecmaVm)); + std::unique_ptr takeTypeProfileturns = std::make_unique + (std::move(result)); + + std::unique_ptr json; + ASSERT_EQ(takeTypeProfileturns->ToJson()->GetArray("result", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 0); +} + +HWTEST_F_L0(DebuggerReturnsTest, GetCategoriesReturnsToJsonTest) +{ + auto result = std::vector(); + std::unique_ptr getCategoriesReturns = std::make_unique + (std::move(result)); + + std::unique_ptr json; + ASSERT_EQ(getCategoriesReturns->ToJson()->GetArray("categories", &json), Result::SUCCESS); + ASSERT_NE(json, nullptr); + EXPECT_EQ(json->GetSize(), 0); +} + +HWTEST_F_L0(DebuggerReturnsTest, RequestMemoryDumpReturnsToJsonTest) +{ + std::unique_ptr requestMemoryDumpReturns + = std::make_unique("123", true); + ASSERT_NE(requestMemoryDumpReturns, nullptr); + + std::string dumpGuid; + ASSERT_EQ(requestMemoryDumpReturns->ToJson()->GetString("dumpGuid", &dumpGuid), + Result::SUCCESS); + EXPECT_EQ(dumpGuid, "123"); + + bool success; + ASSERT_EQ(requestMemoryDumpReturns->ToJson()->GetBool("success", &success), Result::SUCCESS); + ASSERT_TRUE(success); } } // namespace panda::test \ No newline at end of file diff --git a/ecmascript/tooling/test/debugger_types_test.cpp b/ecmascript/tooling/test/debugger_types_test.cpp index 513b2c1b02818951ac42724aa67bb0bac8db2566..a84d038ab553a4acf4cc31290b19bcb9a722ddaf 100644 --- a/ecmascript/tooling/test/debugger_types_test.cpp +++ b/ecmascript/tooling/test/debugger_types_test.cpp @@ -69,60 +69,59 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) { std::string msg; std::unique_ptr remoteObject; - Local tmpStr; // abnormal params of null msg msg = std::string() + R"({})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = 100, ] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = [ "sub": "test" ] }, ] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // normal params of params.sub-key = [ type = "object", ] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"("}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); // abnormal params of params.sub-key = [ type = "object", subtype = "unknown"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","subtype":"unknown"}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = "object", subtype = 100] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","subtype":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // normal params of params.sub-key = [ type = "object", subtype = "array"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Array + R"("}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasSubType()); @@ -131,19 +130,19 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) // abnormal params of params.sub-key = [ type = "object", className = 100] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","className":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = "object", className = {"xx":"yy"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","className":{"xx":"yy"}}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // normal params of params.sub-key = [ type = "object", className = "TestClass"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","className":"TestClass"}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasClassName()); @@ -152,48 +151,40 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) // normal params of params.sub-key = [ type = "object", value = 100] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","value":100}})"; - remoteObject = RemoteObject::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); - ASSERT_TRUE(remoteObject->HasValue()); - EXPECT_EQ(Local(remoteObject->GetValue())->Value(), 100.0); // normal params of params.sub-key = [ type = "object", value = {"xx":"yy"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","value":{"xx":"yy"}}})"; - remoteObject = RemoteObject::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); - ASSERT_TRUE(remoteObject->HasValue()); - ASSERT_TRUE(remoteObject->GetValue()->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "xx"); - ASSERT_TRUE(Local(remoteObject->GetValue())->Has(ecmaVm, Local(tmpStr))); // normal params of params.sub-key = [ type = "object", value = "Test"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","value":"Test"}})"; - remoteObject = RemoteObject::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); - ASSERT_TRUE(remoteObject->HasValue()); - EXPECT_EQ("Test", DebuggerApi::ToStdString(remoteObject->GetValue())); // abnormal params of params.sub-key = [ type = "object", unserializableValue = 100] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","unserializableValue":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = "object", unserializableValue = {"xx":"yy"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","unserializableValue":{"xx":"yy"}}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // normal params of params.sub-key = [ type = "object", unserializableValue = "TestClass"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","unserializableValue":"Test"}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasUnserializableValue()); @@ -202,19 +193,19 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) // abnormal params of params.sub-key = [ type = "object", description = 100] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","description":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = "object", description = {"xx":"yy"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","description":{"xx":"yy"}}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // normal params of params.sub-key = [ type = "object", description = "Test"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","description":"Test"}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasDescription()); @@ -223,75 +214,25 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectCreateTest) // abnormal params of params.sub-key = [ type = "object", objectId = 100] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","objectId":100}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // abnormal params of params.sub-key = [ type = "object", objectId = {"xx":"yy"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","objectId":{"xx":"yy"}}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(remoteObject, nullptr); // normal params of params.sub-key = [ type = "object", objectId = "id_1"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(","objectId":"1"}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); EXPECT_EQ(ObjectType::Object, remoteObject->GetType()); ASSERT_TRUE(remoteObject->HasObjectId()); EXPECT_EQ(remoteObject->GetObjectId(), 1); } -HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToObjectTest) -{ - std::string msg; - std::unique_ptr remoteObject; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + - R"(", "subtype":")" + ObjectSubType::Array + - R"(","className":"TestClass","value":100, "unserializableValue":"Test","description":"Test","objectId":"1"}})"; - remoteObject = RemoteObject::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(remoteObject, nullptr); - Local object = remoteObject->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Array.c_str()), DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "className"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("TestClass", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "value"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 100.0); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "unserializableValue"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("Test", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "description"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("Test", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "objectId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("1", DebuggerApi::ToStdString(result)); -} - HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToJsonTest) { std::string msg; @@ -302,7 +243,7 @@ HWTEST_F_L0(DebuggerTypesTest, RemoteObjectToJsonTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"type":")" + ObjectType::Object + R"(", "subtype":")" + ObjectSubType::Array + R"(","className":"TestClass","value":100, "unserializableValue":"Test","description":"Test","objectId":"1"}})"; - remoteObject = RemoteObject::Create(DispatchRequest(ecmaVm, msg).GetParams()); + remoteObject = RemoteObject::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(remoteObject, nullptr); auto objJson = remoteObject->ToJson(); @@ -338,76 +279,76 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId="Test","text"="text0","lineNumber"=10,"columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":"Test","text":"text0","lineNumber":10,"columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId={"xx":"yy"},"text"="text0","lineNumber"=10,"columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":{"xx":"yy"},"text":"text0","lineNumber":10,"columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId=3,"text"=10,"lineNumber"=10,"columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":10,"lineNumber":10,"columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId=3,"text"=["text0"],"lineNumber"=10,"columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":["text0"],"lineNumber":10,"columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"="10","columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":"10","columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=["10"],"columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":["10"],"columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"="20"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":"20"}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=["20"]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":["20"]}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // normal params of params.sub-key = [ exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3); EXPECT_EQ("text0", exceptionMetaData->GetText()); @@ -418,21 +359,21 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"=10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":10}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"=["10"]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":["10"]}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // normal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"scriptId"="id0"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"0"}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3); EXPECT_EQ("text0", exceptionMetaData->GetText()); @@ -444,21 +385,21 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"=10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"url":10}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"=["10"]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"url":["10"]}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // normal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"url"="url0"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"url":"url0"}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3); EXPECT_EQ("text0", exceptionMetaData->GetText()); @@ -470,14 +411,14 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"exception"=10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"exception":10}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"exception"=["10"]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"exception":["10"]}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // normal params of params.sub-key = @@ -485,7 +426,7 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"exception":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Error + R"("}}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3); EXPECT_EQ("text0", exceptionMetaData->GetText()); @@ -500,21 +441,21 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"executionContextId"="10"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"executionContextId":"10"}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // abnormal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"executionContextId"=["10"]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"executionContextId":["10"]}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(exceptionMetaData, nullptr); // normal params of params.sub-key = // [exceptionId=3,"text"="text0","lineNumber"=10,"columnNumber"=20,"executionContextId"=2] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "exceptionId":3,"text":"text0","lineNumber":10,"columnNumber":20,"executionContextId":2}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); EXPECT_EQ(exceptionMetaData->GetExceptionId(), 3); EXPECT_EQ("text0", exceptionMetaData->GetText()); @@ -523,72 +464,6 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsCreateTest) EXPECT_EQ(exceptionMetaData->GetExecutionContextId(), 2); } -HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToObjectTest) -{ - std::string msg; - std::unique_ptr exceptionMetaData; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "exceptionId":5,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"100","url":"url0", - "exception":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Error + R"("},"executionContextId":30}})"; - exceptionMetaData = ExceptionDetails::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(exceptionMetaData, nullptr); - Local object = exceptionMetaData->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "exceptionId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 5); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "text"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("text0", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "columnNumber"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 20); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("100", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("url0", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "exception"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - Local subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Error.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "executionContextId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 30); -} - HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToJsonTest) { std::string msg; @@ -602,7 +477,7 @@ HWTEST_F_L0(DebuggerTypesTest, ExceptionDetailsToJsonTest) "exceptionId":5,"text":"text0","lineNumber":10,"columnNumber":20,"scriptId":"100","url":"url0", "exception":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Error + R"("},"executionContextId":30}})"; - exceptionMetaData = ExceptionDetails::Create(DispatchRequest(ecmaVm, msg).GetParams()); + exceptionMetaData = ExceptionDetails::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(exceptionMetaData, nullptr); auto objJson = exceptionMetaData->ToJson(); @@ -652,79 +527,79 @@ HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key=["name":"name8"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":99}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key=["name":"name8"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":99}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key=["name":"name8","value":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":99}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key=["name":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":99}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key=["name":[99]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":[99]}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name7"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name7"}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(internalPropertyDescriptor, nullptr); EXPECT_EQ("name7", internalPropertyDescriptor->GetName()); // abnormal params of unknown params.sub-key=["name":"name8","value":{"type":"object","subtype":"map"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":"99"}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // abnormal params of unknown params.sub-key=["name":"name8","value":{"type":"object","subtype":"wrong"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":{"type":")" + ObjectType::Object + R"(","subtype":"wrong"}}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(internalPropertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","value":{"type":"object","subtype":"map"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("}}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(internalPropertyDescriptor, nullptr); EXPECT_EQ("name8", internalPropertyDescriptor->GetName()); ASSERT_TRUE(internalPropertyDescriptor->HasValue()); @@ -734,42 +609,6 @@ HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorCreateTest) EXPECT_EQ(value->GetSubType(), ObjectSubType::Map); } -HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorToObjectTest) -{ - std::string msg; - std::unique_ptr internalPropertyDescriptor; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "name":"name8","value":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("}}})"; - internalPropertyDescriptor = - InternalPropertyDescriptor::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(internalPropertyDescriptor, nullptr); - Local object = internalPropertyDescriptor->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "name"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name8", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "value"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - Local subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Map.c_str()), DebuggerApi::ToStdString(subResult)); -} - HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorToJsonTest) { std::string msg; @@ -781,7 +620,7 @@ HWTEST_F_L0(DebuggerTypesTest, InternalPropertyDescriptorToJsonTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name8","value":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("}}})"; - internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + internalPropertyDescriptor = InternalPropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(internalPropertyDescriptor, nullptr); auto objJson = internalPropertyDescriptor->ToJson(); @@ -807,77 +646,77 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":10,"configurable":true,"enumerable":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":10,"configurable":true,"enumerable":true,"value":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":["name85"],"configurable":true,"enumerable":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":["name85"],"configurable":true,"enumerable":true,"value":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":10,"enumerable":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":10,"enumerable":true}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":"true","enumerable":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":"true","enumerable":true}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":"true"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":"true"}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"value":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"value":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"value":{"ee":"11"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"value":{"ee":"11"}}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"value":{..}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"value":{"type":")" + ObjectType::Symbol + R"("}}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -889,19 +728,19 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"writable":98] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"writable":98}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"writable":[true]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"writable":[true]}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"writable":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"writable":true}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -911,20 +750,20 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"get":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"get":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"get":[10]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"get":[10]}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"get":{}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"get":{"type":")" + ObjectType::Function + R"("}}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -936,20 +775,20 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"set":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"set":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"set":[10]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"set":[10]}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"set":{}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"set":{"type":")" + ObjectType::String + R"("}}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -961,19 +800,19 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"wasThrown":98] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"wasThrown":98}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"wasThrown":[true]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"wasThrown":[true]}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"wasThrown":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"wasThrown":true}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -983,19 +822,19 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"isOwn":98] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"isOwn":98}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"isOwn":[true]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"isOwn":[true]}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true,"isOwn":true] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"isOwn":true}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -1005,20 +844,20 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true, "symbol":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"symbol":10}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // abnormal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true, "symbol":[10]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"symbol":[10]}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(propertyDescriptor, nullptr); // normal params of params.sub-key=["name":"name8","configurable":true,"enumerable":true, "symbol":{}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "name":"name85","configurable":true,"enumerable":true,"symbol":{"type":")" + ObjectType::Wasm + R"("}}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); EXPECT_EQ("name85", propertyDescriptor->GetName()); ASSERT_TRUE(propertyDescriptor->GetConfigurable()); @@ -1028,116 +867,6 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorCreateTest) EXPECT_EQ(symbol->GetType(), ObjectType::Wasm); } -HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToObjectTest) -{ - std::string msg; - std::unique_ptr propertyDescriptor; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "name":"name8","value":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Map + R"("}, - "writable":true,"get":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Regexp + R"("},"set":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Generator + - R"("},"configurable":true,"enumerable":true,"wasThrown":true,"isOwn":true,"symbol":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Proxy + R"("}}})"; - propertyDescriptor = PropertyDescriptor::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(propertyDescriptor, nullptr); - Local object = propertyDescriptor->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "name"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name8", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "value"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - Local subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Map.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "writable"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "get"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Regexp.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "set"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Generator.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "configurable"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "enumerable"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "wasThrown"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "isOwn"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "symbol"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Proxy.c_str()), DebuggerApi::ToStdString(subResult)); -} - HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToJsonTest) { std::string msg; @@ -1155,7 +884,7 @@ HWTEST_F_L0(DebuggerTypesTest, PropertyDescriptorToJsonTest) ObjectType::Object + R"(","subtype":")" + ObjectSubType::Generator + R"("},"configurable":true,"enumerable":true,"wasThrown":true,"isOwn":true,"symbol":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Proxy + R"("}}})"; - propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(ecmaVm, msg).GetParams()); + propertyDescriptor = PropertyDescriptor::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(propertyDescriptor, nullptr); auto objJson = propertyDescriptor->ToJson(); @@ -1231,57 +960,57 @@ HWTEST_F_L0(DebuggerTypesTest, LocationCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of params.sub-key=["scriptId":10,"lineNumber":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":10,"lineNumber":99 }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of params.sub-key=["scriptId":["id3"],"lineNumber":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":["id3"],"lineNumber":99 }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of params.sub-key=["scriptId":"222","lineNumber":"99"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":"99" }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // abnormal params of params.sub-key=["scriptId":"222","lineNumber":[99]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":[99] }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(location, nullptr); // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":899,"columnNumber":138 }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(location, nullptr); EXPECT_EQ(location->GetScriptId(), 222); EXPECT_EQ(location->GetLine(), 899); @@ -1291,42 +1020,12 @@ HWTEST_F_L0(DebuggerTypesTest, LocationCreateTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"2122","lineNumber":8299 }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(location, nullptr); EXPECT_EQ(location->GetScriptId(), 2122); EXPECT_EQ(location->GetLine(), 8299); } -HWTEST_F_L0(DebuggerTypesTest, LocationToObjectTest) -{ - std::string msg; - std::unique_ptr location; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"2","lineNumber":99,"columnNumber":18 - }})"; - location = Location::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(location, nullptr); - Local object = location->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("2", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 99); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "columnNumber"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 18); -} - HWTEST_F_L0(DebuggerTypesTest, LocationToJsonTest) { std::string msg; @@ -1338,7 +1037,7 @@ HWTEST_F_L0(DebuggerTypesTest, LocationToJsonTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"2","lineNumber":99,"columnNumber":18 }})"; - location = Location::Create(DispatchRequest(ecmaVm, msg).GetParams()); + location = Location::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(location, nullptr); auto objJson = location->ToJson(); @@ -1362,78 +1061,78 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":10,"lineNumber":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":10,"lineNumber":99 }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":["id3"],"lineNumber":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":["id3"],"lineNumber":99 }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":"222","lineNumber":"99"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":"99" }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":"222","lineNumber":[99]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":[99] }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":899,"columnNumber":"18" }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18","type":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":899,"columnNumber":"18","type":10 }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // abnormal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":"18","type":"ee"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":899,"columnNumber":"18","type":"ee" }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(breakLocation, nullptr); // normal params of params.sub-key=["scriptId":"2","lineNumber":99,"columnNumber":138,"type":"return"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"222","lineNumber":899,"columnNumber":138,"type":"return" }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(breakLocation, nullptr); EXPECT_EQ(breakLocation->GetScriptId(), 222); EXPECT_EQ(breakLocation->GetLine(), 899); @@ -1444,47 +1143,12 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationCreateTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"2122","lineNumber":8299 }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(breakLocation, nullptr); EXPECT_EQ(breakLocation->GetScriptId(), 2122); EXPECT_EQ(breakLocation->GetLine(), 8299); } -HWTEST_F_L0(DebuggerTypesTest, BreakLocationToObjectTest) -{ - std::string msg; - std::unique_ptr breakLocation; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"12","lineNumber":919,"columnNumber":148,"type":"call" - }})"; - breakLocation = BreakLocation::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(breakLocation, nullptr); - Local object = breakLocation->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("12", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 919); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "columnNumber"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 148); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("call", DebuggerApi::ToStdString(result)); -} - HWTEST_F_L0(DebuggerTypesTest, BreakLocationToJsonTest) { std::string msg; @@ -1496,7 +1160,7 @@ HWTEST_F_L0(DebuggerTypesTest, BreakLocationToJsonTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "scriptId":"12","lineNumber":919,"columnNumber":148,"type":"call" }})"; - breakLocation = BreakLocation::Create(DispatchRequest(ecmaVm, msg).GetParams()); + breakLocation = BreakLocation::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(breakLocation, nullptr); auto objJson = breakLocation->ToJson(); @@ -1524,70 +1188,70 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"ss","object":{..}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"ss","object":{"type":")" + ObjectType::Bigint + R"("}}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":12,"object":{..}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":12,"object":{"type":")" + ObjectType::Bigint + R"("}}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":10}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":{..}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"ww":")" + ObjectType::Bigint + R"("}}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":{..},"name":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"name":10}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":{..},"name":["10"]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"name":["10"]}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // normal params of params.sub-key=["type":"global","object":{..},"name":"name128"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"name":"name117"}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(scope, nullptr); EXPECT_EQ("name117", scope->GetName()); @@ -1595,35 +1259,35 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeCreateTest) msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"startLocation":10}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":{..},"startLocation":{"12":"34"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"startLocation":{"12":"34"}}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":{..},"endLocation":10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"endLocation":10}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // abnormal params of params.sub-key=["type":"global","object":{..},"endLocation":{"12":"34"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("},"endLocation":{"12":"34"}}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scope, nullptr); // normal params of params.sub-key=["type":"global","object":{..}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "type":"global","object":{"type":")" + ObjectType::Bigint + R"("}}})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(scope, nullptr); EXPECT_EQ("global", scope->GetType()); RemoteObject *object = scope->GetObject(); @@ -1631,79 +1295,6 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeCreateTest) EXPECT_EQ(object->GetType(), ObjectType::Bigint); } -HWTEST_F_L0(DebuggerTypesTest, ScopeToObjectTest) -{ - std::string msg; - std::unique_ptr scope; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "type":"global","object":{"type":")" + - ObjectType::Object + R"(","subtype":")" + ObjectSubType::Dataview + R"("},"name":"name9", - "startLocation":{"scriptId":"2","lineNumber":99}, - "endLocation":{"scriptId":"13","lineNumber":146} - }})"; - scope = Scope::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(scope, nullptr); - Local object = scope->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("global", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "object"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - Local subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Dataview.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "name"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name9", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startLocation"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("2", DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(Local(subResult)->Value(), 99); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endLocation"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("13", DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(Local(subResult)->Value(), 146); -} - HWTEST_F_L0(DebuggerTypesTest, ScopeToJsonTest) { std::string msg; @@ -1719,7 +1310,7 @@ HWTEST_F_L0(DebuggerTypesTest, ScopeToJsonTest) "startLocation":{"scriptId":"2","lineNumber":99}, "endLocation":{"scriptId":"13","lineNumber":146} }})"; - scope = Scope::Create(DispatchRequest(ecmaVm, msg).GetParams()); + scope = Scope::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(scope, nullptr); auto objJson = scope->ToJson(); @@ -1769,22 +1360,22 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1794,7 +1385,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1804,7 +1395,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1814,7 +1405,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1824,7 +1415,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1834,7 +1425,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1844,7 +1435,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1854,7 +1445,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1864,7 +1455,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1874,7 +1465,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1884,7 +1475,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1892,7 +1483,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) "callFrameId":"0","functionName":"name0", "location":{"scriptId":"5","lineNumber":19}, "url":"url7","scopeChain":10,"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1902,7 +1493,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) {"type":"22","object":{"type":")" + ObjectType::Object + R"("}},"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1912,7 +1503,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":10}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1922,7 +1513,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"11":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1933,7 +1524,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}, "returnValue":10}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // abnormal params of params.sub-key=[..] @@ -1944,7 +1535,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}, "returnValue":{"type":"object","subtype":"11"}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(callFrame, nullptr); // normal params of params.sub-key=[..] @@ -1954,7 +1545,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) [{"type":"global","object":{"type":")" + ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(callFrame, nullptr); EXPECT_EQ(callFrame->GetCallFrameId(), 0); EXPECT_EQ("name0", callFrame->GetFunctionName()); @@ -1979,7 +1570,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::V128 + R"("},"returnValue":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::I32 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(callFrame, nullptr); EXPECT_EQ(callFrame->GetCallFrameId(), 10); EXPECT_EQ("name0", callFrame->GetFunctionName()); @@ -2002,107 +1593,6 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameCreateTest) EXPECT_EQ(returnObj->GetSubType(), ObjectSubType::I32); } -HWTEST_F_L0(DebuggerTypesTest, CallFrameToObjectTest) -{ - std::string msg; - std::unique_ptr callFrame; - Local tmpStr; - - msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "callFrameId":"0","functionName":"name0","functionLocation":{"scriptId":"3","lineNumber":16}, - "location":{"scriptId":"5","lineNumber":19},"url":"url7","scopeChain": - [{"type":"global","object":{"type":")" + - ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + - R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Iterator + - R"("},"returnValue":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::I64 + R"("}}})"; - callFrame = CallFrame::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); - ASSERT_NE(callFrame, nullptr); - Local object = callFrame->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrameId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("0", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionName"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("name0", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionLocation"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - Local subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("3", DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(Local(subResult)->Value(), 16); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "location"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ("5", DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(Local(subResult)->Value(), 19); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ("url7", DebuggerApi::ToStdString(result)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scopeChain"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - - EXPECT_EQ(Local(result)->Length(ecmaVm), 2); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "this"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::Iterator.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "returnValue"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsObject()); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "type"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectType::Object.c_str()), DebuggerApi::ToStdString(subResult)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "subtype"); - ASSERT_TRUE(Local(result)->Has(ecmaVm, Local(tmpStr))); - subResult = Local(result)->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(std::string(ObjectSubType::I64.c_str()), DebuggerApi::ToStdString(subResult)); -} - HWTEST_F_L0(DebuggerTypesTest, CallFrameToJsonTest) { std::string msg; @@ -2119,7 +1609,7 @@ HWTEST_F_L0(DebuggerTypesTest, CallFrameToJsonTest) ObjectType::Object + R"("}}, {"type":"local","object":{"type":")" + ObjectType::Object + R"("}}],"this":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::Iterator + R"("},"returnValue":{"type":")" + ObjectType::Object + R"(","subtype":")" + ObjectSubType::I64 + R"("}}})"; - callFrame = CallFrame::Create(DispatchRequest(ecmaVm, msg).GetParams()); + callFrame = CallFrame::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(callFrame, nullptr); auto objJson = callFrame->ToJson(); @@ -2188,74 +1678,68 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileSampleCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of params.sub-key = [ "size"="Test","nodeId"="Test","ordinal"="Test"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "size":"Test","nodeId":"Test","ordinal":"Test"}})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of params.sub-key = [ "size"={"xx":"yy"},"nodeId"={"xx":"yy"},"ordinal"={"xx":"yy"}] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "size":{"xx":"yy"},"nodeId":{"xx":"yy"},"ordinal":{"xx":"yy"}}})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of params.sub-key = [ "size"=100,"nodeId"=1,"ordinal"=10] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"size":100,"nodeId":1,"ordinal":10}})"; - object = SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(object, nullptr); EXPECT_EQ(object->GetSize(), 100); EXPECT_EQ(object->GetNodeId(), 1); EXPECT_EQ(object->GetOrdinal(), 10); } -HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileSampleToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileSampleToJsonTest) { std::string msg; std::unique_ptr samplingHeapProfileSampleData; - Local tmpStr; + std::string tmpStr; + int32_t tmpInt; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"size":100,"nodeId":1,"ordinal":10}})"; samplingHeapProfileSampleData = - SamplingHeapProfileSample::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + SamplingHeapProfileSample::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(samplingHeapProfileSampleData, nullptr); - Local object = samplingHeapProfileSampleData->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "size"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 100); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "nodeId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 1); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "ordinal"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); + auto json = samplingHeapProfileSampleData->ToJson(); + + ret = json->GetInt("size", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 100); + ret = json->GetInt("nodeId", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 1); + ret = json->GetInt("ordinal", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); } HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeCreateTest) @@ -2265,22 +1749,22 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - object = SamplingHeapProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - object = SamplingHeapProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - object = SamplingHeapProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - object = SamplingHeapProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ @@ -2289,7 +1773,7 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeCreateTest) "id":5, "children":[] }})"; - object = SamplingHeapProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(object, nullptr); RuntimeCallFrame *runTimeCallFrame = object->GetCallFrame(); ASSERT_NE(runTimeCallFrame, nullptr); @@ -2306,11 +1790,14 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeCreateTest) EXPECT_EQ((int)children->size(), 0); } -HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeToJsonTest) { std::string msg; std::unique_ptr samplingHeapProfileNode; - Local tmpStr; + std::string tmpStr; + std::unique_ptr tmpJson; + int32_t tmpInt; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20}, @@ -2318,48 +1805,33 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileNodeToObjectTest) "id":5, "children":[] }})"; - samplingHeapProfileNode = SamplingHeapProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + samplingHeapProfileNode = SamplingHeapProfileNode::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(samplingHeapProfileNode, nullptr); - Local object = samplingHeapProfileNode->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrame"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - - Local subObject = samplingHeapProfileNode->GetCallFrame()->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionName"); - ASSERT_TRUE(subObject->Has(ecmaVm, tmpStr)); - Local subResult = subObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(subResult), "Create"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(subObject->Has(ecmaVm, tmpStr)); - subResult = subObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(subResult), "10"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(subObject->Has(ecmaVm, tmpStr)); - subResult = subObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(subResult), "url3"); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "selfSize"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "id"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 5); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "children"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + auto json = samplingHeapProfileNode->ToJson(); + + ret = json->GetObject("callFrame", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + ret = tmpJson->GetString("functionName", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "Create"); + ret = tmpJson->GetString("scriptId", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "10"); + ret = tmpJson->GetString("url", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "url3"); + + ret = json->GetInt("selfSize", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + ret = json->GetInt("id", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 5); + ret = json->GetArray("children", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + EXPECT_EQ(tmpJson->GetSize(), 0); } HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileCreateTest) @@ -2369,22 +1841,22 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - object = SamplingHeapProfile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - object = SamplingHeapProfile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - object = SamplingHeapProfile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - object = SamplingHeapProfile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(object, nullptr); msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ @@ -2396,7 +1868,7 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileCreateTest) }, "samples":[{"size":100, "nodeId":1, "ordinal":10}] }})"; - object = SamplingHeapProfile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + object = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(object, nullptr); SamplingHeapProfileNode *head = object->GetHead(); ASSERT_NE(head, nullptr); @@ -2423,11 +1895,16 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileCreateTest) EXPECT_EQ(samples->data()->get()->GetOrdinal(), 10); } -HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileToJsonTest) { std::string msg; std::unique_ptr samplingHeapProfile; - Local tmpStr; + std::string tmpStr; + int32_t tmpInt; + std::unique_ptr tmpJson; + std::unique_ptr varTmpJson; + std::unique_ptr exTmpJson; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "head": { @@ -2439,80 +1916,41 @@ HWTEST_F_L0(DebuggerTypesTest, SamplingHeapProfileToObjectTest) "samples":[{"size":100, "nodeId":1, "ordinal":10}] }})"; - samplingHeapProfile = SamplingHeapProfile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + samplingHeapProfile = SamplingHeapProfile::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(samplingHeapProfile, nullptr); - Local object = samplingHeapProfile->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "head"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - - Local headObject = samplingHeapProfile->GetHead()->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrame"); - ASSERT_TRUE(headObject->Has(ecmaVm, tmpStr)); - result = headObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - - Local callFrameObject = samplingHeapProfile->GetHead()->GetCallFrame()->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionName"); - ASSERT_TRUE(callFrameObject->Has(ecmaVm, tmpStr)); - Local subResult = callFrameObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(subResult), "Create"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(callFrameObject->Has(ecmaVm, tmpStr)); - subResult = callFrameObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(subResult), "10"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(callFrameObject->Has(ecmaVm, tmpStr)); - subResult = callFrameObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!subResult.IsEmpty() && !subResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(subResult), "url3"); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "selfSize"); - ASSERT_TRUE(headObject->Has(ecmaVm, tmpStr)); - result = headObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "id"); - ASSERT_TRUE(headObject->Has(ecmaVm, tmpStr)); - result = headObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 5); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "children"); - ASSERT_TRUE(headObject->Has(ecmaVm, tmpStr)); - result = headObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "samples"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - - Local samplesObject = samplingHeapProfile->GetSamples()->data()->get()->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "size"); - ASSERT_TRUE(samplesObject->Has(ecmaVm, tmpStr)); - result = samplesObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 100); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "nodeId"); - ASSERT_TRUE(samplesObject->Has(ecmaVm, tmpStr)); - result = samplesObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 1); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "ordinal"); - ASSERT_TRUE(samplesObject->Has(ecmaVm, tmpStr)); - result = samplesObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); + auto json = samplingHeapProfile->ToJson(); + + ret = json->GetObject("head", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + ret = tmpJson->GetObject("callFrame", &varTmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(varTmpJson, nullptr); + ret = varTmpJson->GetString("functionName", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "Create"); + ret = varTmpJson->GetString("scriptId", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "10"); + ret = varTmpJson->GetString("url", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "url3"); + + ret = tmpJson->GetInt("selfSize", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + ret = tmpJson->GetInt("id", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 5); + ret = tmpJson->GetArray("children", &exTmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(exTmpJson, nullptr); + EXPECT_EQ(exTmpJson->GetSize(), 0); + + ret = json->GetArray("samples", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + EXPECT_EQ(tmpJson->GetSize(), 1); } HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoCreateTest) @@ -2522,73 +1960,69 @@ HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // abnormal params of params.sub-key=["line":11,"ticks":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "line":"11","ticks":99}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // abnormal params of params.sub-key=["line":"11","ticks":"99"] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "line":"11","ticks":"99"}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // abnormal params of params.sub-key=["line":[11],"ticks":[99]] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "line":[11],"ticks":[99]}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(positionTickInfo, nullptr); // normal params of params.sub-key=["line":11,"ticks":99] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"line":1,"ticks":0}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(positionTickInfo, nullptr); EXPECT_EQ(positionTickInfo->GetLine(), 1); EXPECT_EQ(positionTickInfo->GetTicks(), 0); } - -HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, PositionTickInfoToJsonTest) { std::string msg; std::unique_ptr positionTickInfo; - Local tmpStr; + int32_t tmpInt; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"line":1,"ticks":0}})"; - positionTickInfo = PositionTickInfo::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + positionTickInfo = PositionTickInfo::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(positionTickInfo, nullptr); - Local object = positionTickInfo->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "line"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 1); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "ticks"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 0); + auto json = positionTickInfo->ToJson(); + + ret = json->GetInt("line", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 1); + + ret = json->GetInt("ticks", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 0); } HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest) @@ -2598,22 +2032,22 @@ HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - profileNode = ProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profileNode, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - profileNode = ProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profileNode, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - profileNode = ProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profileNode, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - profileNode = ProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profileNode, nullptr); // normal params of params.sub-key=[..] @@ -2621,7 +2055,7 @@ HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest) "id":10, "callFrame": {"functionName":"name0", "scriptId":"12", "url":"url15", "lineNumber":11, "columnNumber":20}, "hitCount":15,"children":[],"positionTicks":[],"deoptReason":"yyy"}})"; - profileNode = ProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profileNode = ProfileNode::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(profileNode, nullptr); EXPECT_EQ(profileNode->GetId(), 10); @@ -2637,69 +2071,53 @@ HWTEST_F_L0(DebuggerTypesTest, ProfileNodeCreateTest) EXPECT_EQ(profileNode->GetDeoptReason(), "yyy"); } -HWTEST_F_L0(DebuggerTypesTest, ProfileNodeToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, ProfileNodeToJsonTest) { std::string msg; std::unique_ptr profilenode; - Local tmpStr; + std::string tmpStr; + int32_t tmpInt; + std::unique_ptr tmpJson; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "id":10, "callFrame": {"functionName":"name0", "scriptId":"12", "url":"url15", "lineNumber":11, "columnNumber":20}, "hitCount":15,"children":[],"positionTicks":[],"deoptReason":"yyy"}})"; - profilenode = ProfileNode::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profilenode = ProfileNode::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(profilenode, nullptr); - Local object = profilenode->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "id"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "callFrame"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - - Local tmpObject = profilenode->GetCallFrame()->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionName"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - Local tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(tmpResult), "name0"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(tmpResult), "12"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(tmpResult), "url15"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "lineNumber"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(Local(tmpResult)->Value(), 11); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "columnNumber"); - ASSERT_TRUE(tmpObject->Has(ecmaVm, tmpStr)); - tmpResult = tmpObject->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!tmpResult.IsEmpty() && !tmpResult->IsUndefined()); - EXPECT_EQ(Local(tmpResult)->Value(), 20); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "hitCount"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 15); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "deoptReason"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "yyy"); + auto json = profilenode->ToJson(); + + ret = json->GetInt("id", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ret = json->GetObject("callFrame", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + ret = tmpJson->GetString("functionName", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "name0"); + ret = tmpJson->GetString("scriptId", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "12"); + ret = tmpJson->GetString("url", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "url15"); + ret = tmpJson->GetInt("lineNumber", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 11); + ret = tmpJson->GetInt("columnNumber", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 20); + + ret = json->GetInt("hitCount", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 15); + + ret = json->GetString("deoptReason", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "yyy"); } HWTEST_F_L0(DebuggerTypesTest, ProfileCreateTest) @@ -2709,65 +2127,63 @@ HWTEST_F_L0(DebuggerTypesTest, ProfileCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - profile = Profile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profile = Profile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profile, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - profile = Profile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profile = Profile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profile, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - profile = Profile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profile = Profile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profile, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - profile = Profile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + profile = Profile::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(profile, nullptr); // abnormal params of params.sub-key=[..] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "startTime":10,"endTime":25,"nodes":[],"samples":[],"timeDeltas":[]}})"; - profile = Profile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + "startTime":10, "endTime":25, "nodes":[{"id":12, + "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20}}], + "samples":[],"timeDeltas":[]}})"; + profile = Profile::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(profile, nullptr); EXPECT_EQ(profile->GetStartTime(), 10LL); EXPECT_EQ(profile->GetEndTime(), 25LL); const std::vector> *profileNode = profile->GetNodes(); ASSERT_NE(profileNode, nullptr); - EXPECT_EQ((int)profileNode->size(), 0); + EXPECT_EQ((int)profileNode->size(), 1); } -HWTEST_F_L0(DebuggerTypesTest, ProfileToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, ProfileToJsonTest) { std::string msg; std::unique_ptr profile; - Local tmpStr; + std::string tmpStr; + int32_t tmpInt; + std::unique_ptr tmpJson; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "startTime":10,"endTime":25,"nodes":[],"samples":[],"timeDeltas":[]}})"; - profile = Profile::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + "startTime":10, "endTime":25, "nodes":[{"id":12, + "callFrame": {"functionName":"Create", "scriptId":"10", "url":"url3", "lineNumber":100, "columnNumber":20}}], + "samples":[],"timeDeltas":[]}})"; + profile = Profile::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(profile, nullptr); - Local object = profile->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startTime"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 10); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endTime"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 25); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "nodes"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + auto json = profile->ToJson(); + + ret = json->GetInt("startTime", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 10); + + ret = json->GetInt("endTime", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 25); } HWTEST_F_L0(DebuggerTypesTest, CoverageCreateTest) @@ -2777,64 +2193,59 @@ HWTEST_F_L0(DebuggerTypesTest, CoverageCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - coverage = Coverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + coverage = Coverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(coverage, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - coverage = Coverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + coverage = Coverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(coverage, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - coverage = Coverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + coverage = Coverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(coverage, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - coverage = Coverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + coverage = Coverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(coverage, nullptr); // normal params of params.sub-key=["startOffset":0,"endOffset":5,"count":13] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "startOffset":0,"endOffset":13,"count":13}})"; - coverage = Coverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + coverage = Coverage::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(coverage, nullptr); EXPECT_EQ(coverage->GetStartOffset(), 0); EXPECT_EQ(coverage->GetEndOffset(), 13); EXPECT_EQ(coverage->GetCount(), 13); } -HWTEST_F_L0(DebuggerTypesTest, CoverageToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, CoverageToJsonTest) { std::string msg; std::unique_ptr coverage; - Local tmpStr; + std::string tmpStr; + int32_t tmpInt; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ "startOffset":0,"endOffset":13,"count":13}})"; - coverage = Coverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + coverage = Coverage::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(coverage, nullptr); - Local object = coverage->ToObject(ecmaVm); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "startOffset"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 0); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "endOffset"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 13); - - tmpStr = StringRef::NewFromUtf8(ecmaVm, "count"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(Local(result)->Value(), 13); + auto json = coverage->ToJson(); + + ret = json->GetInt("startOffset", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 0); + + ret = json->GetInt("endOffset", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 13); + + ret = json->GetInt("count", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 13); } HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageCreateTest) @@ -2844,64 +2255,64 @@ HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - functionCoverage = FunctionCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(functionCoverage, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - functionCoverage = FunctionCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(functionCoverage, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - functionCoverage = FunctionCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(functionCoverage, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - functionCoverage = FunctionCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(functionCoverage, nullptr); // normal params of params.sub-key=[..] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "functionName":"Create0","ranges":[],"isBlockCoverage":true}})"; - functionCoverage = FunctionCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + "functionName":"Create0","ranges":[{"startOffset":0,"endOffset":13,"count":13}],"isBlockCoverage":true}})"; + functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(functionCoverage, nullptr); EXPECT_EQ(functionCoverage->GetFunctionName(), "Create0"); const std::vector> *ranges = functionCoverage->GetRanges(); ASSERT_NE(ranges, nullptr); - EXPECT_EQ((int)ranges->size(), 0); + EXPECT_EQ((int)ranges->size(), 1); ASSERT_TRUE(functionCoverage->GetIsBlockCoverage()); } -HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, FunctionCoverageToJsonTest) { std::string msg; std::unique_ptr functionCoverage; - Local tmpStr; + std::string tmpStr; + bool tmpBool; + std::unique_ptr tmpJson; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "functionName":"Create0","ranges":[],"isBlockCoverage":true}})"; - functionCoverage = FunctionCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + "functionName":"Create0","ranges":[{"startOffset":0,"endOffset":13,"count":13}],"isBlockCoverage":true}})"; + functionCoverage = FunctionCoverage::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(functionCoverage, nullptr); - Local object = functionCoverage->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functionName"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "Create0"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "ranges"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "isBlockCoverage"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsTrue()); + auto json = functionCoverage->ToJson(); + + ret = json->GetString("functionName", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "Create0"); + + ret = json->GetArray("ranges", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + EXPECT_EQ(tmpJson->GetSize(), 1); + + ret = json->GetBool("isBlockCoverage", &tmpBool); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_TRUE(tmpBool); } HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageCreateTest) @@ -2911,62 +2322,316 @@ HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageCreateTest) // abnormal params of null msg msg = std::string() + R"({})"; - scriptCoverage = ScriptCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scriptCoverage, nullptr); // abnormal params of unexist key params msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; - scriptCoverage = ScriptCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scriptCoverage, nullptr); // abnormal params of null params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; - scriptCoverage = ScriptCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scriptCoverage, nullptr); // abnormal params of unknown params.sub-key msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; - scriptCoverage = ScriptCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams()); EXPECT_EQ(scriptCoverage, nullptr); // normal params of params.sub-key=[..] msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"1001","url":"url17","functions":[]}})"; - scriptCoverage = ScriptCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + "scriptId":"1001", + "url":"url17", + "functions":[{"functionName":"Create0", + "ranges":[{"startOffset":0, "endOffset":13, "count":13}], + "isBlockCoverage":true}]}})"; + scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(scriptCoverage, nullptr); EXPECT_EQ(scriptCoverage->GetScriptId(), "1001"); EXPECT_EQ(scriptCoverage->GetUrl(), "url17"); const std::vector> *functions = scriptCoverage->GetFunctions(); ASSERT_NE(functions, nullptr); - EXPECT_EQ((int)functions->size(), 0); + EXPECT_EQ((int)functions->size(), 1); } -HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageToObjectTest) +HWTEST_F_L0(DebuggerTypesTest, ScriptCoverageToJsonTest) { std::string msg; std::unique_ptr scriptCoverage; - Local tmpStr; + std::string tmpStr; + std::unique_ptr tmpJson; + Result ret; msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ - "scriptId":"1001","url":"url17","functions":[]}})"; - scriptCoverage = ScriptCoverage::Create(ecmaVm, DispatchRequest(ecmaVm, msg).GetParamsObj()); + "scriptId":"1001", + "url":"url17", + "functions": [{"functionName":"Create0", + "ranges": [{"startOffset":0, "endOffset":13, "count":13}], + "isBlockCoverage":true}]}})"; + scriptCoverage = ScriptCoverage::Create(DispatchRequest(msg).GetParams()); ASSERT_NE(scriptCoverage, nullptr); - Local object = scriptCoverage->ToObject(ecmaVm); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "scriptId"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - Local result = object->Get(ecmaVm, tmpStr); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "1001"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "url"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - EXPECT_EQ(DebuggerApi::ToStdString(result), "url17"); - tmpStr = StringRef::NewFromUtf8(ecmaVm, "functions"); - ASSERT_TRUE(object->Has(ecmaVm, tmpStr)); - result = object->Get(ecmaVm, tmpStr); - ASSERT_TRUE(!result.IsEmpty() && !result->IsUndefined()); - ASSERT_TRUE(result->IsArray(ecmaVm)); + auto json = scriptCoverage->ToJson(); + + ret = json->GetString("scriptId", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "1001"); + + ret = json->GetString("url", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "url17"); + + ret = json->GetArray("functions", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + EXPECT_EQ(tmpJson->GetSize(), 1); +} + +HWTEST_F_L0(DebuggerTypesTest, TypeObjectCreateTest) +{ + std::string msg; + std::unique_ptr typeObject; + + // abnormal params of null msg + msg = std::string() + R"({})"; + typeObject = TypeObject::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeObject, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + typeObject = TypeObject::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeObject, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + typeObject = TypeObject::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeObject, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + typeObject = TypeObject::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeObject, nullptr); + + // normal params of params.sub-key=[..] + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "name":"Create1"}})"; + typeObject = TypeObject::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(typeObject, nullptr); + EXPECT_EQ(typeObject->GetName(), "Create1"); +} + +HWTEST_F_L0(DebuggerTypesTest, TypeObjectToJsonTest) +{ + std::string msg; + std::unique_ptr typeObject; + std::string tmpStr; + Result ret; + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "name":"Create1"}})"; + typeObject = TypeObject::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(typeObject, nullptr); + auto json = typeObject->ToJson(); + + ret = json->GetString("name", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "Create1"); +} + +HWTEST_F_L0(DebuggerTypesTest, TypeProfileEntryCreateTest) +{ + std::string msg; + std::unique_ptr typeProfileEntry; + + // abnormal params of null msg + msg = std::string() + R"({})"; + typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeProfileEntry, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeProfileEntry, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeProfileEntry, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(typeProfileEntry, nullptr); + + // normal params of params.sub-key=[..] + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "offset":11,"types":[{"name":"Create1"}]}})"; + typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(typeProfileEntry, nullptr); + EXPECT_EQ(typeProfileEntry->GetOffset(), 11); + const std::vector> *typeObject = typeProfileEntry->GetTypes(); + ASSERT_NE(typeObject, nullptr); + EXPECT_EQ((int)typeObject->size(), 1); +} + +HWTEST_F_L0(DebuggerTypesTest, TypeProfileEntryToJsonTest) +{ + std::string msg; + std::unique_ptr typeProfileEntry; + int32_t tmpInt; + std::unique_ptr tmpJson; + Result ret; + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "offset":11,"types":[{"name":"Create1"}]}})"; + typeProfileEntry = TypeProfileEntry::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(typeProfileEntry, nullptr); + auto json = typeProfileEntry->ToJson(); + + ret = json->GetInt("offset", &tmpInt); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpInt, 11); + + ret = json->GetArray("types", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + EXPECT_EQ(tmpJson->GetSize(), 1); +} + +HWTEST_F_L0(DebuggerTypesTest, ScriptTypeProfileCreateTest) +{ + std::string msg; + std::unique_ptr scriptTypeProfile; + + // abnormal params of null msg + msg = std::string() + R"({})"; + scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(scriptTypeProfile, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(scriptTypeProfile, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(scriptTypeProfile, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams()); + EXPECT_EQ(scriptTypeProfile, nullptr); + + // normal params of params.sub-key=[..] + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "scriptId":"122","url":"url15","entries":[{"offset":11,"types":[{"name":"Create1"}]}]}})"; + scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(scriptTypeProfile, nullptr); + EXPECT_EQ(scriptTypeProfile->GetScriptId(), "122"); + EXPECT_EQ(scriptTypeProfile->GetUrl(), "url15"); + const std::vector> *typeProfileEntry = scriptTypeProfile->GetEntries(); + ASSERT_NE(typeProfileEntry, nullptr); + EXPECT_EQ((int)typeProfileEntry->size(), 1); +} + +HWTEST_F_L0(DebuggerTypesTest, ScriptTypeProfileToJsonTest) +{ + std::string msg; + std::unique_ptr scriptTypeProfile; + std::string tmpStr; + std::unique_ptr tmpJson; + Result ret; + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "scriptId":"122","url":"url15","entries":[{"offset":11,"types":[{"name":"Create1"}]}]}})"; + scriptTypeProfile = ScriptTypeProfile::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(scriptTypeProfile, nullptr); + auto json = scriptTypeProfile->ToJson(); + + ret = json->GetString("scriptId", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "122"); + + ret = json->GetString("url", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "url15"); + + ret = json->GetArray("entries", &tmpJson); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_NE(tmpJson, nullptr); + EXPECT_EQ(tmpJson->GetSize(), 1); +} + +HWTEST_F_L0(DebuggerTypesTest, TraceConfigCreateTest) +{ + std::string msg; + std::unique_ptr traceConfig; + + // abnormal params of null msg + msg = std::string() + R"({})"; + traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(traceConfig, nullptr); + + // abnormal params of unexist key params + msg = std::string() + R"({"id":0,"method":"Debugger.Test"})"; + traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(traceConfig, nullptr); + + // abnormal params of null params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{}})"; + traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(traceConfig, nullptr); + + // abnormal params of unknown params.sub-key + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{"unknownKey":100}})"; + traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(traceConfig, nullptr); + + // normal params of params.sub-key=[..] + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "recordMode":"recordUntilFull", "enableSampling":true, "enableSystrace":true, + "enableArgumentFilter":true}})"; + traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(traceConfig, nullptr); + + EXPECT_EQ(traceConfig->GetRecordMode(), "recordUntilFull"); + ASSERT_TRUE(traceConfig->GetEnableSampling()); + ASSERT_TRUE(traceConfig->GetEnableSystrace()); + ASSERT_TRUE(traceConfig->GetEnableArgumentFilter()); +} + +HWTEST_F_L0(DebuggerTypesTest, TraceConfigToJsonTest) +{ + std::string msg; + std::unique_ptr traceConfig; + std::string tmpStr; + std::unique_ptr tmpJson; + bool tmpBool; + Result ret; + + msg = std::string() + R"({"id":0,"method":"Debugger.Test","params":{ + "recordMode":"recordUntilFull", "enableSampling":true, "enableSystrace":true, + "enableArgumentFilter":true}})"; + traceConfig = TraceConfig::Create(DispatchRequest(msg).GetParams()); + ASSERT_NE(traceConfig, nullptr); + auto json = traceConfig->ToJson(); + + ret = json->GetString("recordMode", &tmpStr); + EXPECT_EQ(ret, Result::SUCCESS); + EXPECT_EQ(tmpStr, "recordUntilFull"); + + ret = json->GetBool("enableSampling", &tmpBool); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ret = json->GetBool("enableSystrace", &tmpBool); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_TRUE(tmpBool); + + ret = json->GetBool("enableArgumentFilter", &tmpBool); + EXPECT_EQ(ret, Result::SUCCESS); + ASSERT_TRUE(tmpBool); } } // namespace panda::test diff --git a/ecmascript/tooling/test/js/RangeError.js b/ecmascript/tooling/test/js/RangeError.js new file mode 100644 index 0000000000000000000000000000000000000000..51b82854ebd58b3eeb4591aefe8cb1fa0cc869ac --- /dev/null +++ b/ecmascript/tooling/test/js/RangeError.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function rangeErrorException() { + let a = new Array(-1); +} + +print("begin"); +rangeErrorException(); +print("end"); \ No newline at end of file diff --git a/ecmascript/tooling/test/js/StepInto.js b/ecmascript/tooling/test/js/StepInto.js new file mode 100644 index 0000000000000000000000000000000000000000..c9dbfa24658728b527048af06b47faebcd99be41 --- /dev/null +++ b/ecmascript/tooling/test/js/StepInto.js @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function countToTen() { + var a = 1; + a = 2; + a = 3; + a = 4; + a = 5; + a = 6; + a = 7; + a = 8; + a = 9; + a = 10; +} + +countToTen(); +var b = 10 \ No newline at end of file diff --git a/ecmascript/tooling/test/js/syntaxException.js b/ecmascript/tooling/test/js/syntaxException.js new file mode 100644 index 0000000000000000000000000000000000000000..899ab23097303126bb9188d4efff35f612aa16f7 --- /dev/null +++ b/ecmascript/tooling/test/js/syntaxException.js @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function countSyntaxException() { + var sum = 0; + try { + adddlert("hello! "); + } + catch(err) { + print(err); + sum += 1; + } + return sum; +} +print("begin"); +countSyntaxException(); +print("end"); \ No newline at end of file diff --git a/ecmascript/tooling/test/js/throwException.js b/ecmascript/tooling/test/js/throwException.js new file mode 100644 index 0000000000000000000000000000000000000000..6d2b9f0d157f3ddf7270162392253a884aaf39a4 --- /dev/null +++ b/ecmascript/tooling/test/js/throwException.js @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function countThrowException() { + var sum = 0; + print(sum) + try { + throw 'error'; + print("error"); + } + catch(err) { + print("catch: " + err); + sum += 1; + } + return sum; +} +print("begin"); +print(countThrowException()); +print("end"); + + + diff --git a/ecmascript/tooling/test/utils/test_entry.h b/ecmascript/tooling/test/utils/test_entry.h index 0e6414a966161e7ee1635d35be2c3f8ccecb9268..7625844f3d0ab64547f4cb8728ecd6ae00504c57 100644 --- a/ecmascript/tooling/test/utils/test_entry.h +++ b/ecmascript/tooling/test/utils/test_entry.h @@ -16,11 +16,14 @@ #ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TEST_ENTRY_H #define ECMASCRIPT_TOOLING_TEST_UTILS_TEST_ENTRY_H -#include "ecmascript/ecma_vm.h" +#include -namespace panda::ecmascript::tooling::test { +namespace panda::ecmascript { +class EcmaVM; +namespace tooling::test { bool StartDebuggerImpl(const std::string &name, EcmaVM *vm, bool isDebugMode); bool StopDebuggerImpl(const std::string &name); -} // namespace panda::ecmascript::tooling::test +} // namespace tooling::test +} // namespace panda::ecmascript #endif // ECMASCRIPT_TOOLING_TEST_UTILS_TEST_ENTRY_H \ No newline at end of file diff --git a/ecmascript/tooling/test/utils/test_events.h b/ecmascript/tooling/test/utils/test_events.h index 54e41ba60d26c21c55862ce955a9230c48b275d7..f61bff21f8cf3977c8aa759b0d881ecf2d9ad060 100644 --- a/ecmascript/tooling/test/utils/test_events.h +++ b/ecmascript/tooling/test/utils/test_events.h @@ -33,6 +33,7 @@ enum class DebugEvent { BREAKPOINT, LOAD_MODULE, PAUSED, + STEP_COMPLETE, EXCEPTION, METHOD_ENTRY, SINGLE_STEP, diff --git a/ecmascript/tooling/test/utils/test_hooks.h b/ecmascript/tooling/test/utils/test_hooks.h index e5fa79c77b3a01fae02273a09b2faadc517d1a7c..e4edc3248e43026cf9b77688810b7e051b6bcc09 100644 --- a/ecmascript/tooling/test/utils/test_hooks.h +++ b/ecmascript/tooling/test/utils/test_hooks.h @@ -103,7 +103,7 @@ public: if (TestUtil::IsTestFinished()) { return; } - LOG(FATAL, DEBUGGER) << "Test " << testName_ << " failed"; + LOG_DEBUGGER(FATAL) << "Test " << testName_ << " failed"; } ~TestHooks() = default; diff --git a/ecmascript/tooling/test/utils/test_util.h b/ecmascript/tooling/test/utils/test_util.h index 993826daaa6ab679d838a4835ecbe4c1c2da5a9f..9304a47bb0101082fc7ad6a813ccc4edc46b2b41 100644 --- a/ecmascript/tooling/test/utils/test_util.h +++ b/ecmascript/tooling/test/utils/test_util.h @@ -43,7 +43,7 @@ public: if (iter != testMap_.end()) { return iter->second.get(); } - LOG(FATAL, DEBUGGER) << "Test " << name << " not found"; + LOG_DEBUGGER(FATAL) << "Test " << name << " not found"; return nullptr; } @@ -66,6 +66,12 @@ public: }, [] {}); } + static bool WaitForStepComplete() + { + auto predicate = []() REQUIRES(eventMutex_) { return lastEvent_ == DebugEvent::STEP_COMPLETE; }; + return WaitForEvent(DebugEvent::STEP_COMPLETE, predicate, [] {}); + } + static bool WaitForException() { auto predicate = []() REQUIRES(eventMutex_) { return lastEvent_ == DebugEvent::EXCEPTION; }; @@ -82,7 +88,7 @@ public: static void Event(DebugEvent event, JSPtLocation location = JSPtLocation("", EntityId(0), 0)) { - LOG(DEBUG, DEBUGGER) << "Occurred event " << event; + LOG_DEBUGGER(DEBUG) << "Occurred event " << event; os::memory::LockHolder holder(eventMutex_); lastEvent_ = event; lastEventLocation_ = location; @@ -167,7 +173,7 @@ private: constexpr uint64_t TIMEOUT_MSEC = 10000U; bool timeExceeded = eventCv_.TimedWait(&eventMutex_, TIMEOUT_MSEC); if (timeExceeded) { - LOG(FATAL, DEBUGGER) << "Time limit exceeded while waiting " << event; + LOG_DEBUGGER(FATAL) << "Time limit exceeded while waiting " << event; return false; } } diff --git a/ecmascript/tooling/test/utils/testcases/js_breakpoint_arrow_test.h b/ecmascript/tooling/test/utils/testcases/js_breakpoint_arrow_test.h index e502c037e4e62878d9f6ffde4b706ef9576a4ee5..104825c8524671f48e7ba0303460244e16d13ebf 100644 --- a/ecmascript/tooling/test/utils/testcases/js_breakpoint_arrow_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_breakpoint_arrow_test.h @@ -38,16 +38,11 @@ public: }; loadModule = [this](std::string_view moduleName) { - if (flag_) { - if (moduleName != pandaFile_) { - return true; - } - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); - flag_ = false; - auto condFuncRef = FunctionRef::Undefined(vm_); - auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); - ASSERT_TRUE(ret); - } + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); return true; }; @@ -77,7 +72,6 @@ private: std::string entryPoint_ = "_GLOBAL::func_main_0"; JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; size_t breakpointCounter_ = 0; - bool flag_ = true; }; std::unique_ptr GetJsBreakpointArrowTest() diff --git a/ecmascript/tooling/test/utils/testcases/js_breakpoint_async_test.h b/ecmascript/tooling/test/utils/testcases/js_breakpoint_async_test.h index 2c90269baa86b9f4c68ced80cc3727f5081583b8..43fcc28c43b8355fa61113c4d54a61fe7a446d3b 100644 --- a/ecmascript/tooling/test/utils/testcases/js_breakpoint_async_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_breakpoint_async_test.h @@ -38,16 +38,11 @@ public: }; loadModule = [this](std::string_view moduleName) { - if (flag_) { - if (moduleName != pandaFile_) { - return true; - } - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); - flag_ = false; - auto condFuncRef = FunctionRef::Undefined(vm_); - auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); - ASSERT_TRUE(ret); - } + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); return true; }; @@ -79,7 +74,6 @@ private: std::string entryPoint_ = "_GLOBAL::func_main_0"; JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; size_t breakpointCounter_ = 0; - bool flag_ = true; }; std::unique_ptr GetJsBreakpointAsyncTest() diff --git a/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h b/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h index a598d261669e910793fccc9991f3ca1b7fe3e0ff..f1d44c8341c360c157142c3b28e3e6923f7b517d 100644 --- a/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_breakpoint_test.h @@ -38,16 +38,11 @@ public: }; loadModule = [this](std::string_view moduleName) { - if (flag_) { - if (moduleName != pandaFile_) { - return true; - } - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); - flag_ = false; - auto condFuncRef = FunctionRef::Undefined(vm_); - auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); - ASSERT_TRUE(ret); - } + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); return true; }; @@ -79,7 +74,6 @@ private: std::string entryPoint_ = "_GLOBAL::func_main_0"; JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; size_t breakpointCounter_ = 0; - bool flag_ = true; }; std::unique_ptr GetJsBreakpointTest() diff --git a/ecmascript/tooling/test/utils/testcases/js_exception_test.h b/ecmascript/tooling/test/utils/testcases/js_exception_test.h index 94b3b5317d037100e16c1ca340abab7e53e7a7da..e8d08a279708101b22601e1bbbf3d7f078790c60 100644 --- a/ecmascript/tooling/test/utils/testcases/js_exception_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_exception_test.h @@ -61,16 +61,11 @@ public: }; loadModule = [this](std::string_view moduleName) { - if (flag_) { - if (moduleName != pandaFile_) { - return true; - } - ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); - flag_ = false; - auto condFuncRef = FunctionRef::Undefined(vm_); - auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); - ASSERT_TRUE(ret); - } + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); return true; }; @@ -104,7 +99,6 @@ private: JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; size_t breakpointCounter_ = 0; size_t exceptionCounter_ = 0; - bool flag_ = true; }; std::unique_ptr GetJsExceptionTest() diff --git a/ecmascript/tooling/test/utils/testcases/js_range_error_test.h b/ecmascript/tooling/test/utils/testcases/js_range_error_test.h new file mode 100644 index 0000000000000000000000000000000000000000..5bd3c4523573c7833cc95d0319db0d345cdce1f2 --- /dev/null +++ b/ecmascript/tooling/test/utils/testcases/js_range_error_test.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_RANGE_ERROR_TEST_H +#define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_RANGE_ERROR_TEST_H + +#include "ecmascript/tooling/test/utils/test_util.h" + +namespace panda::ecmascript::tooling::test { +class JsRangeErrorTest : public TestEvents { +public: + JsRangeErrorTest() + { + vmStart = [this] { + location_ = TestUtil::GetLocation("RangeError.js", 20, 0, pandaFile_.c_str()); + ASSERT_TRUE(location_.GetMethodId().IsValid()); + return true; + }; + + breakpoint = [this](const JSPtLocation &location) { + ASSERT_TRUE(location.GetMethodId().IsValid()); + ASSERT_LOCATION_EQ(location, location_); + ++breakpointCounter_; + std::vector> callFrames; + ASSERT_TRUE(debugger_->GenerateCallFrames(&callFrames)); + ASSERT_TRUE(callFrames.size() > 0); + auto jsLocation = callFrames[0]->GetLocation(); + ASSERT_TRUE(jsLocation != nullptr); + ASSERT_EQ(jsLocation->GetLine(), 20); + ASSERT_EQ(jsLocation->GetColumn(), 0); + TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location); + return true; + }; + + exception = [this](const JSPtLocation &location) { + auto sourceLocation = TestUtil::GetSourceLocation(location, pandaFile_.c_str()); + ASSERT_EQ(sourceLocation.line, 16); + ASSERT_EQ(sourceLocation.column, 12); + ++exceptionCounter_; + std::vector> callFrames; + ASSERT_TRUE(debugger_->GenerateCallFrames(&callFrames)); + ASSERT_TRUE(callFrames.size() > 0); + auto jsLocation = callFrames[0]->GetLocation(); + ASSERT_TRUE(jsLocation != nullptr); + ASSERT_EQ(jsLocation->GetLine(), 16); + ASSERT_EQ(jsLocation->GetColumn(), 12); + TestUtil::SuspendUntilContinue(DebugEvent::EXCEPTION, location); + return true; + }; + + loadModule = [this](std::string_view moduleName) { + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); + return true; + }; + + scenario = [this]() { + ASSERT_BREAKPOINT_SUCCESS(location_); + TestUtil::Continue(); + TestUtil::WaitForException(); + TestUtil::Continue(); + auto ret = debugInterface_->RemoveBreakpoint(location_); + ASSERT_TRUE(ret); + ASSERT_EXITED(); + return true; + }; + + vmDeath = [this]() { + ASSERT_EQ(breakpointCounter_, 1U); + ASSERT_EQ(exceptionCounter_, 1U); + return true; + }; + } + + std::pair GetEntryPoint() override + { + return {pandaFile_, entryPoint_}; + } + ~JsRangeErrorTest() = default; + +private: + std::string pandaFile_ = DEBUGGER_ABC_DIR "RangeError.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; + size_t breakpointCounter_ = 0; + size_t exceptionCounter_ = 0; +}; + +std::unique_ptr GetJsRangeErrorTest() +{ + return std::make_unique(); +} +} // namespace panda::ecmascript::tooling::test + +#endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_RANGE_ERROR_TEST_H diff --git a/ecmascript/tooling/test/utils/testcases/js_single_step_test.h b/ecmascript/tooling/test/utils/testcases/js_single_step_test.h index 08cc43d5667dfa9eddf5d6e7d6511b910ba123b5..972a6927300eca468efd1b11639640dad792b041 100644 --- a/ecmascript/tooling/test/utils/testcases/js_single_step_test.h +++ b/ecmascript/tooling/test/utils/testcases/js_single_step_test.h @@ -36,15 +36,10 @@ public: }; loadModule = [this](std::string_view moduleName) { - if (flag_) { - if (moduleName != pandaFile_) { - return true; - } - flag_ = false; - auto condFuncRef = FunctionRef::Undefined(vm_); - auto ret = debugInterface_->SetBreakpoint(locationEnd_, condFuncRef); - ASSERT_TRUE(ret); - } + ASSERT_EQ(moduleName, pandaFile_); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(locationEnd_, condFuncRef); + ASSERT_TRUE(ret); return true; }; @@ -92,7 +87,6 @@ private: int32_t breakpointCounter_ = 0; bool collectSteps_ = false; uint32_t bytecodeOffset_ = std::numeric_limits::max(); - bool flag_ = true; }; std::unique_ptr GetJsSingleStepTest() diff --git a/ecmascript/tooling/test/utils/testcases/js_step_into_test.h b/ecmascript/tooling/test/utils/testcases/js_step_into_test.h new file mode 100644 index 0000000000000000000000000000000000000000..a060b4ad3e5b18cb4ed5d1066f0487b54ff662f0 --- /dev/null +++ b/ecmascript/tooling/test/utils/testcases/js_step_into_test.h @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_STEP_INTO_TEST_H +#define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_STEP_INTO_TEST_H + +#include "ecmascript/tooling/test/utils/test_util.h" + +namespace panda::ecmascript::tooling::test { +class JsStepIntoTest : public TestEvents { +public: + JsStepIntoTest() + { + vmStart = [this] { + location1_ = TestUtil::GetLocation("StepInto.js", 28, 0, pandaFile_.c_str()); // 28: line number + location2_ = TestUtil::GetLocation("StepInto.js", 16, 0, pandaFile_.c_str()); // 16: line number + return true; + }; + + vmDeath = [this]() { + ASSERT_EQ(breakpointCounter_, 1); + ASSERT_EQ(stepCompleteCounter_, 1); + return true; + }; + + loadModule = [this](std::string_view moduleName) { + ASSERT_EQ(moduleName, pandaFile_); + debugger_->NotifyScriptParsed(0, moduleName.data()); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location1_, condFuncRef); + ASSERT_TRUE(ret); + return true; + }; + + breakpoint = [this](const JSPtLocation &location) { + ASSERT_TRUE(location.GetMethodId().IsValid()); + ASSERT_LOCATION_EQ(location, location1_); + ++breakpointCounter_; + TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location); + debugger_->StepInto(StepIntoParams()); + return true; + }; + + singleStep = [this](const JSPtLocation &location) { + if (debugger_->NotifySingleStep(location)) { + ASSERT_TRUE(location.GetMethodId().IsValid()); + ASSERT_LOCATION_EQ(location, location2_); + stepCompleteCounter_++; + TestUtil::Event(DebugEvent::STEP_COMPLETE); + return true; + } + return false; + }; + + scenario = [this]() { + ASSERT_BREAKPOINT_SUCCESS(location1_); + TestUtil::Continue(); + auto ret = debugInterface_->RemoveBreakpoint(location1_); + TestUtil::WaitForStepComplete(); + ASSERT_TRUE(ret); + ASSERT_EXITED(); + return true; + }; + } + + std::pair GetEntryPoint() override + { + return {pandaFile_, entryPoint_}; + } + +private: + std::string pandaFile_ = DEBUGGER_ABC_DIR "StepInto.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + JSPtLocation location1_ {nullptr, JSPtLocation::EntityId(0), 0}; + JSPtLocation location2_ {nullptr, JSPtLocation::EntityId(0), 0}; + int32_t breakpointCounter_ = 0; + int32_t stepCompleteCounter_ = 0; +}; + +std::unique_ptr GetJsStepIntoTest() +{ + return std::make_unique(); +} +} // namespace panda::ecmascript::tooling::test + +#endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_STEP_INTO_TEST_H diff --git a/ecmascript/tooling/test/utils/testcases/js_syntaxException_test.h b/ecmascript/tooling/test/utils/testcases/js_syntaxException_test.h new file mode 100644 index 0000000000000000000000000000000000000000..d294862a036706ac54a702428d7ed9229b6afbc8 --- /dev/null +++ b/ecmascript/tooling/test/utils/testcases/js_syntaxException_test.h @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_SYNTAX_EXCEPTION_TEST_H +#define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_SYNTAX_EXCEPTION_TEST_H + +#include "ecmascript/tooling/test/utils/test_util.h" + +namespace panda::ecmascript::tooling::test { +class JsSyntaxExceptionTest : public TestEvents { +public: + JsSyntaxExceptionTest() + { + vmStart = [this] { + location_ = TestUtil::GetLocation("syntaxException.js", 27, 0, pandaFile_.c_str()); // 27: breakpointer line + ASSERT_TRUE(location_.GetMethodId().IsValid()); + return true; + }; + + breakpoint = [this](const JSPtLocation &location) { + ASSERT_TRUE(location.GetMethodId().IsValid()); + ASSERT_LOCATION_EQ(location, location_); + ++breakpointCounter_; + std::vector> callFrames; + ASSERT_TRUE(debugger_->GenerateCallFrames(&callFrames)); + ASSERT_TRUE(callFrames.size() > 0); + auto jsLocation = callFrames[0]->GetLocation(); + ASSERT_TRUE(jsLocation != nullptr); + ASSERT_EQ(jsLocation->GetLine(), 27); // 27: breakpointer line + ASSERT_EQ(jsLocation->GetColumn(), 0); + TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location); + return true; + }; + + exception = [this](const JSPtLocation &location) { + auto sourceLocation = TestUtil::GetSourceLocation(location, pandaFile_.c_str()); + ASSERT_EQ(sourceLocation.line, 18); // 18: exception line + ASSERT_EQ(sourceLocation.column, 8); // 8: exception column + ++exceptionCounter_; + std::vector> callFrames; + ASSERT_TRUE(debugger_->GenerateCallFrames(&callFrames)); + ASSERT_TRUE(callFrames.size() > 0); + auto jsLocation = callFrames[0]->GetLocation(); + ASSERT_TRUE(jsLocation != nullptr); + ASSERT_EQ(jsLocation->GetLine(), 18); // 18: exception line + ASSERT_EQ(jsLocation->GetColumn(), 8); // 8: exception column + TestUtil::SuspendUntilContinue(DebugEvent::EXCEPTION, location); + return true; + }; + + loadModule = [this](std::string_view moduleName) { + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); + return true; + }; + + scenario = [this]() { + ASSERT_BREAKPOINT_SUCCESS(location_); + TestUtil::Continue(); + TestUtil::WaitForException(); + TestUtil::Continue(); + auto ret = debugInterface_->RemoveBreakpoint(location_); + ASSERT_TRUE(ret); + ASSERT_EXITED(); + return true; + }; + + vmDeath = [this]() { + ASSERT_EQ(breakpointCounter_, 1U); + ASSERT_EQ(exceptionCounter_, 1U); + return true; + }; + } + + std::pair GetEntryPoint() override + { + return {pandaFile_, entryPoint_}; + } + ~JsSyntaxExceptionTest() = default; + +private: + std::string pandaFile_ = DEBUGGER_ABC_DIR "syntaxException.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; + size_t breakpointCounter_ = 0; + size_t exceptionCounter_ = 0; +}; + +std::unique_ptr GetJsSyntaxExceptionTest() +{ + return std::make_unique(); +} +} // namespace panda::ecmascript::tooling::test + +#endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_SYNTAX_EXCEPTION_TEST_H diff --git a/ecmascript/tooling/test/utils/testcases/js_throwException_test.h b/ecmascript/tooling/test/utils/testcases/js_throwException_test.h new file mode 100644 index 0000000000000000000000000000000000000000..353dc4c0c18ac983f19ef47bb5e60fd4e7ec260f --- /dev/null +++ b/ecmascript/tooling/test/utils/testcases/js_throwException_test.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_THROW_EXCEPTION_TEST_H +#define ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_THROW_EXCEPTION_TEST_H + +#include "ecmascript/tooling/test/utils/test_util.h" + +namespace panda::ecmascript::tooling::test { +class JsThrowExceptionTest : public TestEvents { +public: + JsThrowExceptionTest() + { + vmStart = [this] { + location_ = TestUtil::GetLocation("throwException.js", 28, 0, pandaFile_.c_str()); // 28: breakpointer line + std::cout<<"vmStart1"<> callFrames; + ASSERT_TRUE(debugger_->GenerateCallFrames(&callFrames)); + ASSERT_TRUE(callFrames.size() > 0); + auto jsLocation = callFrames[0]->GetLocation(); + ASSERT_TRUE(jsLocation != nullptr); + ASSERT_EQ(jsLocation->GetLine(), 28); // 28: breakpointer line + ASSERT_EQ(jsLocation->GetColumn(), 0); + TestUtil::SuspendUntilContinue(DebugEvent::BREAKPOINT, location); + return true; + }; + + exception = [this](const JSPtLocation &location) { + auto sourceLocation = TestUtil::GetSourceLocation(location, pandaFile_.c_str()); + ASSERT_EQ(sourceLocation.line, 19); // 19: exception line + ASSERT_EQ(sourceLocation.column, 8); // 8: exception column + ++exceptionCounter_; + std::vector> callFrames; + ASSERT_TRUE(debugger_->GenerateCallFrames(&callFrames)); + ASSERT_TRUE(callFrames.size() > 0); + auto jsLocation = callFrames[0]->GetLocation(); + ASSERT_TRUE(jsLocation != nullptr); + ASSERT_EQ(jsLocation->GetLine(), 19); // 19: exception line + ASSERT_EQ(jsLocation->GetColumn(), 8); // 8: exception column + ++exceptionCounter_; + TestUtil::SuspendUntilContinue(DebugEvent::EXCEPTION, location); + return true; + }; + + loadModule = [this](std::string_view moduleName) { + ASSERT_EQ(moduleName, pandaFile_); + ASSERT_TRUE(debugger_->NotifyScriptParsed(0, pandaFile_)); + auto condFuncRef = FunctionRef::Undefined(vm_); + auto ret = debugInterface_->SetBreakpoint(location_, condFuncRef); + ASSERT_TRUE(ret); + return true; + }; + + scenario = [this]() { + ASSERT_BREAKPOINT_SUCCESS(location_); + TestUtil::Continue(); + TestUtil::WaitForException(); + TestUtil::Continue(); + auto ret = debugInterface_->RemoveBreakpoint(location_); + ASSERT_TRUE(ret); + ASSERT_EXITED(); + return true; + }; + + vmDeath = [this]() { + ASSERT_EQ(breakpointCounter_, 1U); + ASSERT_EQ(exceptionCounter_, 2U); + return true; + }; + } + + std::pair GetEntryPoint() override + { + return {pandaFile_, entryPoint_}; + } + ~JsThrowExceptionTest() = default; + +private: + std::string pandaFile_ = DEBUGGER_ABC_DIR "throwException.abc"; + std::string entryPoint_ = "_GLOBAL::func_main_0"; + JSPtLocation location_ {nullptr, JSPtLocation::EntityId(0), 0}; + size_t breakpointCounter_ = 0; + size_t exceptionCounter_ = 0; +}; + +std::unique_ptr GetJsThrowExceptionTest() +{ + return std::make_unique(); +} +} // namespace panda::ecmascript::tooling::test + +#endif // ECMASCRIPT_TOOLING_TEST_UTILS_TESTCASES_JS_THROW_EXCEPTION_TEST_H diff --git a/ecmascript/tooling/test/utils/testcases/test_list.cpp b/ecmascript/tooling/test/utils/testcases/test_list.cpp index 2cb272b7006398dfaf1bdd8d45688679b49ce08a..1237825372d4c961d150c53a84f74df12be75ce3 100644 --- a/ecmascript/tooling/test/utils/testcases/test_list.cpp +++ b/ecmascript/tooling/test/utils/testcases/test_list.cpp @@ -22,7 +22,11 @@ #include "js_breakpoint_arrow_test.h" #include "js_breakpoint_async_test.h" #include "js_exception_test.h" +#include "js_range_error_test.h" #include "js_single_step_test.h" +#include "js_step_into_test.h" +#include "js_syntaxException_test.h" +#include "js_throwException_test.h" namespace panda::ecmascript::tooling::test { static std::string g_currentTestName = ""; @@ -35,6 +39,10 @@ static void RegisterTests() TestUtil::RegisterTest("JsBreakpointTest", GetJsBreakpointTest()); TestUtil::RegisterTest("JsBreakpointAsyncTest", GetJsBreakpointAsyncTest()); TestUtil::RegisterTest("JsBreakpointArrowTest", GetJsBreakpointArrowTest()); + TestUtil::RegisterTest("JsRangeErrorTest", GetJsRangeErrorTest()); + TestUtil::RegisterTest("JsSyntaxExceptionTest", GetJsSyntaxExceptionTest()); + TestUtil::RegisterTest("JsThrowExceptionTest", GetJsThrowExceptionTest()); + TestUtil::RegisterTest("JsStepIntoTest", GetJsStepIntoTest()); } std::vector GetTestList() diff --git a/ecmascript/tooling/test/utils/testcases/test_list.h b/ecmascript/tooling/test/utils/testcases/test_list.h index 0409f3897f74f25d6260b4220a268850523408e9..0f208fe16353fb3d89ca5f7a8df36765dd7177c0 100644 --- a/ecmascript/tooling/test/utils/testcases/test_list.h +++ b/ecmascript/tooling/test/utils/testcases/test_list.h @@ -21,7 +21,6 @@ #include "ecmascript/mem/c_containers.h" #include "ecmascript/mem/c_string.h" -#include "libpandafile/file_items.h" namespace panda::ecmascript::tooling::test { std::vector GetTestList(); diff --git a/ecmascript/ts_types/global_ts_type_ref.h b/ecmascript/ts_types/global_ts_type_ref.h index 56f5f57c15a30ffc78f066b165d25b45b882cfba..b4131b4cbed5eaf6628a526776532675426a944e 100644 --- a/ecmascript/ts_types/global_ts_type_ref.h +++ b/ecmascript/ts_types/global_ts_type_ref.h @@ -18,7 +18,6 @@ #include "ecmascript/ecma_macros.h" #include "libpandabase/utils/bit_field.h" -#include "libpandabase/utils/logger.h" namespace panda::ecmascript { enum class TSTypeKind : int { @@ -50,13 +49,20 @@ enum class TSPrimitiveType : int { class GlobalTSTypeRef { public: explicit GlobalTSTypeRef(uint32_t type = 0) : type_(type) {} - explicit GlobalTSTypeRef(int moduleId, int localId, int typeKind) + explicit GlobalTSTypeRef(int moduleId, int localId, int typeKind) : type_(0) { - type_ = 0; SetKind(typeKind); SetLocalId(localId); SetModuleId(moduleId); } + + explicit GlobalTSTypeRef(int moduleId, int localId, TSTypeKind typeKind) : type_(0) + { + SetKind(static_cast(typeKind)); + SetLocalId(localId); + SetModuleId(moduleId); + } + ~GlobalTSTypeRef() = default; static constexpr int TS_TYPE_RESERVED_COUNT = 50; @@ -113,11 +119,11 @@ public: void Dump() const { - uint8_t kind = GetKind(); + uint32_t kind = GetKind(); uint32_t gcType = GetGCType(); uint32_t moduleId = GetModuleId(); uint32_t localId = GetLocalId(); - LOG(ERROR, ECMASCRIPT) << "kind: " << kind << " gcType: " << gcType + LOG_ECMA(ERROR) << "kind: " << kind << " gcType: " << gcType << " moduleId: " << moduleId << " localId: " << localId; } @@ -126,4 +132,4 @@ private: }; } // namespace panda::ecmascript -#endif // ECMASCRIPT_TS_TYPES_GLOBAL_TS_TYPE_REF_H \ No newline at end of file +#endif // ECMASCRIPT_TS_TYPES_GLOBAL_TS_TYPE_REF_H diff --git a/ecmascript/ts_types/ts_loader.cpp b/ecmascript/ts_types/ts_loader.cpp index a0ae66ae3959204aec21fb54df2bff7f6397eee0..4afe487b227837798d5ed38e7f29a3cac41f62e6 100644 --- a/ecmascript/ts_types/ts_loader.cpp +++ b/ecmascript/ts_types/ts_loader.cpp @@ -211,7 +211,7 @@ GlobalTSTypeRef TSLoader::GetGTFromPandaFile(const panda_file::File &pf, uint32_ auto *elemName = reinterpret_cast(pf.GetStringData(adae.GetNameId()).data); ASSERT(elemName != nullptr); uint32_t elemCount = adae.GetArrayValue().GetCount(); - if (::strcmp("typeOfVreg", elemName) == 0) { // verg table -> [v1, 1, v2, 51, v3, 56] + if (::strcmp("_TypeOfInstruction", elemName) == 0) { for (uint32_t j = 0; j < elemCount; j = j + 2) { // + 2 means localId index auto value = adae.GetArrayValue().Get(j).GetOffset(); if (value == vregId) { @@ -362,6 +362,11 @@ void TSLoader::Iterate(const RootVisitor &v) for (uint64_t i = 0; i < length; i++) { v(Root::ROOT_VM, ObjectSlot(reinterpret_cast(&(constantStringTable_.data()[i])))); } + + uint64_t hclassTableLength = staticHClassTable_.size(); + for (uint64_t i = 0; i < hclassTableLength; i++) { + v(Root::ROOT_VM, ObjectSlot(reinterpret_cast(&(staticHClassTable_.data()[i])))); + } } GlobalTSTypeRef TSLoader::GetImportTypeTargetGT(GlobalTSTypeRef gt) const @@ -487,6 +492,37 @@ bool TSLoader::GetTypeInferenceLog() const return vm_->GetJSOptions().GetLogTypeInfer(); } +void TSLoader::GenerateStaticHClass(JSHandle tsTypeTable) +{ + JSThread *thread = vm_->GetJSThread(); + + JSMutableHandle instanceType(thread, JSTaggedValue::Undefined()); + for (int index = 1; index <= tsTypeTable->GetNumberOfTypes(); ++index) { + JSTaggedValue type = tsTypeTable->Get(index); + if (!type.IsTSClassType()) { + continue; + } + + TSClassType *classType = TSClassType::Cast(type.GetTaggedObject()); + instanceType.Update(classType->GetInstanceType()); + GlobalTSTypeRef gt = classType->GetGTRef(); + JSTaggedValue ihc = JSTaggedValue(TSObjectType::GetOrCreateHClass(thread, instanceType)); + AddStaticHClassInCompilePhase(gt, ihc); + } +} + +JSHandle TSLoader::GetType(const GlobalTSTypeRef >) const +{ + JSThread *thread = vm_->GetJSThread(); + uint32_t moduleId = gt.GetModuleId(); + uint32_t localId = gt.GetLocalId(); + + JSHandle mTable = GetTSModuleTable(); + JSHandle typeTable = mTable->GetTSTypeTable(thread, moduleId); + JSHandle type(thread, typeTable->Get(localId)); + return type; +} + void TSModuleTable::Initialize(JSThread *thread, JSHandle mTable) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); diff --git a/ecmascript/ts_types/ts_loader.h b/ecmascript/ts_types/ts_loader.h index c3d8014102053f4d080ed4a5e3b20f023a554ad7..539bd0187be8b383a554cdefbdf004077a4d7ac5 100644 --- a/ecmascript/ts_types/ts_loader.h +++ b/ecmascript/ts_types/ts_loader.h @@ -217,6 +217,31 @@ public: return JSHandle(reinterpret_cast(&(constantStringTable_.at(index)))); } + CVector GetStaticHClassTable() const + { + return staticHClassTable_; + } + + void AddStaticHClassInCompilePhase(GlobalTSTypeRef gt, JSTaggedValue hclass) + { + staticHClassTable_.emplace_back(hclass.GetRawData()); + gtHClassIndexMap_[gt] = staticHClassTable_.size() - 1; + } + + void AddStaticHClassInRuntimePhase(JSTaggedValue hclass) + { + staticHClassTable_.emplace_back(hclass.GetRawData()); + } + + std::map GetGtHClassIndexMap() + { + return gtHClassIndexMap_; + } + + void GenerateStaticHClass(JSHandle tsTypeTable); + + JSHandle GetType(const GlobalTSTypeRef >) const; + private: NO_COPY_SEMANTIC(TSLoader); @@ -239,6 +264,8 @@ private: EcmaVM *vm_ {nullptr}; JSTaggedValue globalModuleTable_ {JSTaggedValue::Hole()}; CVector constantStringTable_ {}; + CVector staticHClassTable_ {}; // store hclass which produced from static type info + std::map gtHClassIndexMap_ {}; // record gt and static hclass index mapping relation friend class EcmaVM; }; } // namespace panda::ecmascript diff --git a/ecmascript/ts_types/ts_obj_layout_info.h b/ecmascript/ts_types/ts_obj_layout_info.h index d3d48b24f391cfd410d662c55e22a3bf64850d02..3f530534fe312558a8406f671cf672bf0cb34f41 100644 --- a/ecmascript/ts_types/ts_obj_layout_info.h +++ b/ecmascript/ts_types/ts_obj_layout_info.h @@ -32,7 +32,7 @@ public: static constexpr int ENTRY_TYPE_OFFSET = 1; static constexpr int ENTRY_KEY_OFFSET = 0; - inline static TSObjLayoutInfo *Cast(ObjectHeader *obj) + inline static TSObjLayoutInfo *Cast(TaggedObject *obj) { ASSERT(JSTaggedValue(obj).IsTaggedArray()); return reinterpret_cast(obj); diff --git a/ecmascript/ts_types/ts_type.cpp b/ecmascript/ts_types/ts_type.cpp index 6551a897e41cf3c843a364a86b6d9b1985a368f4..1d97bfdea099245d6fb9815edd6b4fdf92abbf54 100644 --- a/ecmascript/ts_types/ts_type.cpp +++ b/ecmascript/ts_types/ts_type.cpp @@ -24,15 +24,15 @@ #include "ecmascript/ts_types/ts_type_table.h" namespace panda::ecmascript { -JSHClass *TSObjectType::GetOrCreateHClass(JSThread *thread) +JSHClass *TSObjectType::GetOrCreateHClass(JSThread *thread, JSHandle objectType) { - JSTaggedValue mayBeHClass = GetHClass(); + JSTaggedValue mayBeHClass = objectType->GetHClass(); if (mayBeHClass.IsJSHClass()) { return JSHClass::Cast(mayBeHClass.GetTaggedObject()); } - JSHandle propTypeInfo(thread, GetObjLayoutInfo().GetTaggedObject()); - JSHClass *hclass = CreateHClassByProps(thread, propTypeInfo); - SetHClass(thread, JSTaggedValue(hclass)); + JSHandle propTypeInfo(thread, objectType->GetObjLayoutInfo()); + JSHClass *hclass = objectType->CreateHClassByProps(thread, propTypeInfo); + objectType->SetHClass(thread, JSTaggedValue(hclass)); return hclass; } @@ -41,15 +41,15 @@ JSHClass *TSObjectType::CreateHClassByProps(JSThread *thread, JSHandleGetEcmaVM()->GetFactory(); - uint32_t length = propType->GetLength(); - if (length > PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES) { - LOG(ERROR, RUNTIME) << "TSobject type has too many keys and cannot create hclass"; + uint32_t numOfProps = propType->NumberOfElements(); + if (numOfProps > PropertyAttributes::MAX_CAPACITY_OF_PROPERTIES) { + LOG_ECMA(ERROR) << "TSobject type has too many keys and cannot create hclass"; UNREACHABLE(); } JSMutableHandle key(thread, JSTaggedValue::Undefined()); - JSHandle layout = factory->CreateLayoutInfo(length); - for (uint32_t index = 0; index < length; ++index) { + JSHandle layout = factory->CreateLayoutInfo(numOfProps); + for (uint32_t index = 0; index < numOfProps; ++index) { JSTaggedValue tsPropKey = propType->GetKey(index); key.Update(tsPropKey); ASSERT_PRINT(JSTaggedValue::IsPropertyKey(key), "Key is not a property key"); @@ -59,9 +59,10 @@ JSHClass *TSObjectType::CreateHClassByProps(JSThread *thread, JSHandleAddKey(thread, index, key.GetTaggedValue(), attributes); } - JSHandle hclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, length); + JSHandle hclass = factory->NewEcmaDynClass(JSObject::SIZE, JSType::JS_OBJECT, numOfProps); hclass->SetLayout(thread, layout); - hclass->SetNumberOfProps(length); + hclass->SetNumberOfProps(numOfProps); + hclass->SetTSType(true); return *hclass; } @@ -203,4 +204,4 @@ GlobalTSTypeRef TSArrayType::GetElementTypeGT(JSHandle typeTable) TSType* Type = TSType::Cast(typeTable->Get(index).GetTaggedObject()); return Type->GetGTRef(); } -} // namespace panda::ecmascript \ No newline at end of file +} // namespace panda::ecmascript diff --git a/ecmascript/ts_types/ts_type.h b/ecmascript/ts_types/ts_type.h index 889f26af8cc8ed4c398c2036c1578e8ddf494373..d02519dc9c807de535448815db4d985a4f476d34 100644 --- a/ecmascript/ts_types/ts_type.h +++ b/ecmascript/ts_types/ts_type.h @@ -35,7 +35,8 @@ public: return static_cast(const_cast(object)); } - ACCESSORS_PRIMITIVE_FIELD(GT, uint64_t, BIT_FIELD_OFFSET, SIZE); + ACCESSORS_PRIMITIVE_FIELD(GT, uint32_t, BIT_FIELD_OFFSET, LAST_OFFSET); + DEFINE_ALIGN_SIZE(LAST_OFFSET); GlobalTSTypeRef GetGTRef() const { @@ -54,7 +55,7 @@ public: static constexpr size_t PROPERTIES_OFFSET = TSType::SIZE; - JSHClass *GetOrCreateHClass(JSThread *thread); + static JSHClass *GetOrCreateHClass(JSThread *thread, JSHandle objectType); static GlobalTSTypeRef GetPropTypeGT(JSHandle &table, JSHandle objType, JSHandle propName); @@ -81,12 +82,44 @@ public: ACCESSORS(InstanceType, INSTANCE_TYPE_OFFSET, CONSTRUCTOR_TYPE_OFFSET); ACCESSORS(ConstructorType, CONSTRUCTOR_TYPE_OFFSET, PROTOTYPE_TYPE_OFFSET); - ACCESSORS(PrototypeType, PROTOTYPE_TYPE_OFFSET, EXTENSION_TYPE_OFFSET); - ACCESSORS(ExtensionType, EXTENSION_TYPE_OFFSET, LAST_OFFSET); + ACCESSORS(PrototypeType, PROTOTYPE_TYPE_OFFSET, EXTENSION_GT_RAW_DATA_OFFSET); + ACCESSORS_PRIMITIVE_FIELD(ExtensionGTRawData, uint32_t, EXTENSION_GT_RAW_DATA_OFFSET, BIT_FIELD_OFFSET) + ACCESSORS_BIT_FIELD(BitField, BIT_FIELD_OFFSET, LAST_OFFSET) DEFINE_ALIGN_SIZE(LAST_OFFSET); - DECL_VISIT_OBJECT(INSTANCE_TYPE_OFFSET, LAST_OFFSET) + // define BitField + static constexpr size_t HAS_LINKED_BITS = 1; + FIRST_BIT_FIELD(BitField, HasLinked, bool, HAS_LINKED_BITS); + + DECL_VISIT_OBJECT(INSTANCE_TYPE_OFFSET, EXTENSION_GT_RAW_DATA_OFFSET) DECL_DUMP() + + // Judgment base classType by extends typeId, ts2abc write 0 in base class type extends domain + inline static bool IsBaseClassType(int extendsTypeId) + { + const int baseClassTypeExtendsTypeId = 0; + return extendsTypeId == baseClassTypeExtendsTypeId; + } + + GlobalTSTypeRef GetExtensionGT() const + { + uint32_t extensionGTRawData = GetExtensionGTRawData(); + return GlobalTSTypeRef(extensionGTRawData); + } + + void SetExtensionGT(GlobalTSTypeRef gt) + { + uint32_t extensionGTRawData = gt.GetType(); + SetExtensionGTRawData(extensionGTRawData); + } + + JSHandle GetExtendClassType(JSThread *thread) const + { + GlobalTSTypeRef extensionGT = GetExtensionGT(); + JSHandle extendClassType = thread->GetEcmaVM()->GetTSLoader()->GetType(extensionGT); + ASSERT(extendClassType->IsTSClassType()); + return JSHandle(extendClassType); + } }; class TSClassInstanceType : public TSType { diff --git a/ecmascript/ts_types/ts_type_table.cpp b/ecmascript/ts_types/ts_type_table.cpp index 35a19a492c652d2741d9abd190bb659c20634e7a..438e6f8839e7cd7241855d0e9628f0670b018223 100644 --- a/ecmascript/ts_types/ts_type_table.cpp +++ b/ecmascript/ts_types/ts_type_table.cpp @@ -32,11 +32,14 @@ void TSTypeTable::Initialize(JSThread *thread, const JSPandaFile *jsPandaFile, TSLoader *tsLoader = vm->GetTSLoader(); ObjectFactory *factory = vm->GetFactory(); - JSHandle tsTypetable = GenerateTypeTable(thread, jsPandaFile, recordImportModules); + JSHandle tsTypeTable = GenerateTypeTable(thread, jsPandaFile, recordImportModules); // Set TStypeTable -> GlobleModuleTable JSHandle fileName = factory->NewFromUtf8(jsPandaFile->GetJSPandaFileDesc()); - tsLoader->AddTypeTable(JSHandle(tsTypetable), fileName); + tsLoader->AddTypeTable(JSHandle(tsTypeTable), fileName); + + TSTypeTable::LinkClassType(thread, tsTypeTable); + tsLoader->GenerateStaticHClass(tsTypeTable); // management dependency module while (recordImportModules.size() > 0) { @@ -87,7 +90,7 @@ JSHandle TSTypeTable::ParseType(JSThread *thread, JSHandle(literal->Get(TYPE_KIND_INDEX_IN_LITERAL).GetInt()); switch (kind) { case TSTypeKind::CLASS: { - JSHandle classType = ParseClassType(thread, table, literal); + JSHandle classType = ParseClassType(thread, literal); return JSHandle(classType); } case TSTypeKind::CLASS_INSTANCE: { @@ -226,9 +229,9 @@ JSHandle TSTypeTable::GetExportTableFromPandFile(JSThread *thread, } }); - array_size_t length = exportTable.size(); + uint32_t length = exportTable.size(); JSHandle exportArray = factory->NewTaggedArray(length); - for (array_size_t i = 0; i < length; i ++) { + for (uint32_t i = 0; i < length; i ++) { JSHandle typeIdString = factory->NewFromUtf8(exportTable[i]); exportArray->Set(thread, i, typeIdString); } @@ -250,16 +253,25 @@ JSHandle TSTypeTable::ParseImportType(JSThread *thread, const JSHa return importType; } -JSHandle TSTypeTable::ParseClassType(JSThread *thread, JSHandle &typeTable, - const JSHandle &literal) +JSHandle TSTypeTable::ParseClassType(JSThread *thread, const JSHandle &literal) { ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); JSHandle classType = factory->NewTSClassType(); int32_t index = 0; ASSERT(static_cast(literal->Get(index).GetInt()) == TSTypeKind::CLASS); - index = index + 2; // 2: ignore accessFlag and readonly - int32_t extendsTypeId = literal->Get(index++).GetInt(); + const int32_t ignoreLength = 2; // 2: ignore accessFlag and readonly + index += ignoreLength; + int extendsTypeId = literal->Get(index++).GetInt(); + if (TSClassType::IsBaseClassType(extendsTypeId)) { + classType->SetExtensionGT(GlobalTSTypeRef::Default()); + classType->SetHasLinked(true); + } else { + int moduleId = thread->GetEcmaVM()->GetTSLoader()->GetNextModuleId(); + GlobalTSTypeRef extensionGT = GlobalTSTypeRef(moduleId, extendsTypeId - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT, + TSTypeKind::CLASS); + classType->SetExtensionGT(extensionGT); + } // ignore implement int32_t numImplement = literal->Get(index++).GetInt(); @@ -269,27 +281,17 @@ JSHandle TSTypeTable::ParseClassType(JSThread *thread, JSHandle typeId(thread, JSTaggedValue::Undefined()); // resolve instance type - uint32_t numBaseFields = 0; uint32_t numFields = static_cast(literal->Get(index++).GetInt()); - JSHandle instanceType; - if (extendsTypeId) { // base class is 0 - uint32_t realExtendsTypeId = static_cast(extendsTypeId - GlobalTSTypeRef::TS_TYPE_RESERVED_COUNT); - JSHandle extensionType(thread, typeTable->Get(realExtendsTypeId)); - ASSERT(extensionType.GetTaggedValue().IsTSClassType()); - classType->SetExtensionType(thread, extensionType); - instanceType = LinkSuper(thread, extensionType, &numBaseFields, numFields); - } else { - instanceType = factory->NewTSObjectType(numFields); - } - + JSHandle instanceType = factory->NewTSObjectType(numFields); JSHandle instanceTypeInfo(thread, instanceType->GetObjLayoutInfo()); - ASSERT(instanceTypeInfo->GetPropertiesCapacity() == numBaseFields + numFields); + ASSERT(instanceTypeInfo->GetPropertiesCapacity() == numFields); + for (uint32_t fieldIndex = 0; fieldIndex < numFields; ++fieldIndex) { key.Update(literal->Get(index++)); typeId.Update(literal->Get(index++)); index += 2; // 2: ignore accessFlag and readonly - instanceTypeInfo->SetKey(thread, numBaseFields + fieldIndex, key.GetTaggedValue(), typeId.GetTaggedValue()); + instanceTypeInfo->SetKey(thread, fieldIndex, key.GetTaggedValue(), typeId.GetTaggedValue()); } classType->SetInstanceType(thread, instanceType); @@ -373,30 +375,6 @@ JSHandle TSTypeTable::ParseInterfaceType(JSThread *thread, cons return interfaceType; } -JSHandle TSTypeTable::LinkSuper(JSThread *thread, JSHandle &baseClassType, - uint32_t *numBaseFields, uint32_t numDerivedFields) -{ - ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); - - JSHandle baseInstanceType(thread, baseClassType->GetInstanceType()); - JSHandle baseInstanceTypeInfo(thread, baseInstanceType->GetObjLayoutInfo()); - - *numBaseFields = baseInstanceTypeInfo->NumberOfElements(); - - JSHandle derivedInstanceType = factory->NewTSObjectType(*numBaseFields + numDerivedFields); - JSHandle derivedInstanceTypeInfo(thread, derivedInstanceType->GetObjLayoutInfo()); - - JSMutableHandle baseInstanceKey(thread, JSTaggedValue::Undefined()); - JSMutableHandle baseInstanceTypeId(thread, JSTaggedValue::Undefined()); - for (uint32_t index = 0; index < baseInstanceTypeInfo->NumberOfElements(); ++index) { - baseInstanceKey.Update(baseInstanceTypeInfo->GetKey(index)); - baseInstanceTypeId.Update(baseInstanceTypeInfo->GetTypeId(index)); - derivedInstanceTypeInfo->SetKey(thread, index, baseInstanceKey.GetTaggedValue(), - baseInstanceTypeId.GetTaggedValue()); - } - return derivedInstanceType; -} - JSHandle TSTypeTable::ParseUnionType(JSThread *thread, const JSPandaFile *jsPandaFile, const JSHandle &literal) { @@ -569,4 +547,68 @@ JSHandle TSTypeTable::PushBackTypeToInferTable(JSThread *thread, JS return table; } + +void TSTypeTable::LinkClassType(JSThread *thread, JSHandle table) +{ + int numTypes = table->GetNumberOfTypes(); + JSMutableHandle type(thread, JSTaggedValue::Undefined()); + for (int i = 1; i <= numTypes; ++i) { + type.Update(table->Get(i)); + if (!type->IsTSClassType()) { + continue; + } + + JSHandle classType(type); + if (classType->GetHasLinked()) { // has linked + continue; + } + + JSHandle extendClassType = classType->GetExtendClassType(thread); + MergeClassFiled(thread, classType, extendClassType); + } +} + +void TSTypeTable::MergeClassFiled(JSThread *thread, JSHandle classType, + JSHandle extendClassType) +{ + ASSERT(!classType->GetHasLinked()); + + if (!extendClassType->GetHasLinked()) { + MergeClassFiled(thread, extendClassType, extendClassType->GetExtendClassType(thread)); + } + + ASSERT(extendClassType->GetHasLinked()); + + JSHandle field(thread, classType->GetInstanceType()); + JSHandle layout(thread, field->GetObjLayoutInfo()); + uint32_t numSelfTypes = layout->NumberOfElements(); + + JSHandle extendField(thread, extendClassType->GetInstanceType()); + JSHandle extendLayout(thread, extendField->GetObjLayoutInfo()); + uint32_t numExtendTypes = extendLayout->NumberOfElements(); + + uint32_t numTypes = numSelfTypes + numExtendTypes; + + ObjectFactory *factory = thread->GetEcmaVM()->GetFactory(); + JSHandle newLayout = factory->CreateTSObjLayoutInfo(numTypes); + + uint32_t index = 0; + while (index < numExtendTypes) { + JSTaggedValue key = extendLayout->GetKey(index); + JSTaggedValue type = extendLayout->GetTypeId(index); + newLayout->SetKey(thread, index, key, type); + index++; + } + + index = 0; + while (index < numSelfTypes) { + JSTaggedValue key = layout->GetKey(index); + JSTaggedValue type = layout->GetTypeId(index); + newLayout->SetKey(thread, numExtendTypes + index, key, type); + index++; + } + + field->SetObjLayoutInfo(thread, newLayout); + classType->SetHasLinked(true); +} } // namespace panda::ecmascript diff --git a/ecmascript/ts_types/ts_type_table.h b/ecmascript/ts_types/ts_type_table.h index db9b0c4ca92bf039012c98fbec326e8d65ea1494..0bd334e8d45b08f653771ddbd2d95a2e9b9f6119 100644 --- a/ecmascript/ts_types/ts_type_table.h +++ b/ecmascript/ts_types/ts_type_table.h @@ -79,25 +79,21 @@ public: private: static JSHandle GenerateTypeTable(JSThread *thread, const JSPandaFile *jsPandaFile, - CVector> &recordImportModules); + CVector> &recordImportModules); static JSHandle GetExportTableFromPandFile(JSThread *thread, const panda_file::File &pf); static panda_file::File::EntityId GetFileId(const panda_file::File &pf); - static JSHandle ParseClassType(JSThread *thread, JSHandle &typeTable, - const JSHandle &literal); + static JSHandle ParseClassType(JSThread *thread, const JSHandle &literal); static JSHandle ParseInterfaceType(JSThread *thread, const JSHandle &literal); static JSHandle ParseUnionType(JSThread *thread, const JSPandaFile *jsPandaFile, const JSHandle &literal); - static JSHandle LinkSuper(JSThread *thread, JSHandle &baseClassType, - uint32_t *numBaseFields, uint32_t numDerivedFields); - static void CheckModule(JSThread *thread, const TSLoader* tsLoader, const JSHandle target, - CVector> &recordImportModules); + CVector> &recordImportModules); static JSHandle GenerateVarNameAndPath(JSThread *thread, JSHandle importPath, JSHandle fileName, @@ -110,6 +106,11 @@ private: static JSHandle ParseObjectType(JSThread *thread, const JSHandle &literal); static int GetTypeKindFromFileByLocalId(JSThread *thread, const JSPandaFile *jsPandaFile, int localId); + + static void LinkClassType(JSThread *thread, JSHandle table); + + static void MergeClassFiled(JSThread *thread, JSHandle classType, + JSHandle extendClassType); }; } // namespace panda::ecmascript diff --git a/ecmascript/weak_vector.h b/ecmascript/weak_vector.h index bab4363db4a3908c9ac491f34dcdc3fce9cc3b4b..9da8b63686db8f99ffd235656f6c129beb1e0a5c 100644 --- a/ecmascript/weak_vector.h +++ b/ecmascript/weak_vector.h @@ -23,7 +23,7 @@ namespace panda::ecmascript { class WeakVector : public TaggedArray { public: - static WeakVector *Cast(ObjectHeader *object) + static WeakVector *Cast(TaggedObject *object) { return static_cast(object); } diff --git a/js_runtime_config.gni b/js_runtime_config.gni index 440bc3441029d8c903df74ce29d19172ff17ca44..5120619df7cddae808c1094db4f21aaf68b27db4 100644 --- a/js_runtime_config.gni +++ b/js_runtime_config.gni @@ -11,18 +11,19 @@ # See the License for the specific language governing permissions and # limitations under the License. -if (!defined(ark_independent_build)) { +if (!defined(ark_standalone_build)) { ark_root = "//ark/runtime_core" js_root = "//ark/js_runtime" - third_party_gn_path = "//third_party" } else { ark_root = "//runtime_core" js_root = "//js_runtime" - third_party_gn_path = "$build_root/third_party_gn" } +third_party_gn_path = "//third_party" compile_llvm_online = false run_with_asan = false enable_bytrace = true +enable_hitrace = true +enable_hilog = true enable_dump_in_faultlog = true asan_lib_path = "/usr/lib/llvm-10/lib/clang/10.0.0/lib/linux" diff --git a/script/build_resource_to_cpp.py b/script/build_resource_to_cpp.py new file mode 100755 index 0000000000000000000000000000000000000000..fa3210edc2fc49d97215df08cf33ecc0c7f759c3 --- /dev/null +++ b/script/build_resource_to_cpp.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python3 +#coding: utf-8 +""" +Copyright (c) 2022-2023 Huawei Device Co., Ltd. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +Description: run script + expect_output will get run result, + expect_sub_output will catch pivotal sub output, + expect_file will get print string +""" + +import argparse +import os +import sys + + +def resource_file_to_cpp(input_dir, input_file, output_path): + with open(os.path.join(input_dir, input_file), 'rb')\ + as resource_file_object: + with open(output_path, 'a') as cpp_file_object: + length = 0; + all_the_content = resource_file_object.read(); + template0 = "#include \n"; + template1 = "extern const uint8_t _binary_$1_start[$2] = {$3};\n"; + template2 = \ + "extern const uint32_t _binary_$1_length = $2;"; + + formats = "," + seq = [] + for content in all_the_content: + seq.append(str(hex(content))) + length = length + 1 + byte_code = formats.join(seq); + input_file = input_file.replace(".", "_") + template1 = template1.replace("$1", str(input_file)) \ + .replace("$2", str(length)) \ + .replace("$3", str(byte_code)) + template2 = template2.replace("$1", str(input_file)) \ + .replace("$2", str(length)) + cpp_file_object.seek(0) + cpp_file_object.truncate(); + cpp_file_object.write(template0 + template1 + template2); + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('--input', type=str, required=True) + parser.add_argument('--output', type=str, required=True) + + args = parser.parse_args() + + input_dir, input_file = os.path.split(args.input) + output_path = os.path.abspath(args.output) + resource_file_to_cpp(input_dir, input_file, output_path) + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/script/run_ark_executable.py b/script/run_ark_executable.py index eeae2556f4a292808c2f8a54610205b8c95c1186..4588c493b9c11816d78f541eecd0177529a3e6fe 100755 --- a/script/run_ark_executable.py +++ b/script/run_ark_executable.py @@ -69,6 +69,7 @@ def judge_output(args): try: out, err = subp.communicate(timeout=timeout_limit) except subprocess.TimeoutExpired: + print('Run [', cmd, '] timeout, timeout_limit = ', timeout_limit, 's') subp.kill() out, err = subp.communicate() diff --git a/test/aottest/BUILD.gn b/test/aottest/BUILD.gn index 69bdc94f007086d7560d99c47b62639edd1b73cd..8287b993e1319c7af80493692101d539d3e32f80 100644 --- a/test/aottest/BUILD.gn +++ b/test/aottest/BUILD.gn @@ -16,59 +16,126 @@ group("ark_aot_test") { deps = [ "add:addAotAction", "and:andAotAction", + "aot_compatibility_test:aot_compatibility_test", "ashr:ashrAotAction", + + #"asyncfunctionenter:asyncfunctionenterAotAction", + #bigint_typed_array_constructors:js + "bind:bindAotAction", + + #call_default_args:js + #"call_same_bytecode_func:call_same_bytecode_funcAotAction", + "callithisrange:callithisrangeAotAction", + "calls:callsAotAction", + "closeiterator:closeiteratorAotAction", + "copyrestargs:copyrestargsAotAction", "createarraywithbuffer:createarraywithbufferAotAction", "createemptyarray:createemptyarrayAotAction", "createemptyobject:createemptyobjectAotAction", + + #creategeneratorobj:creategeneratorobjAotAction", + #"createiterresultobj:createiterresultobjAotAction", + + "createobjecthavingmethod:createobjecthavingmethodAotAction", "createobjectwithbuffer:createobjectwithbufferAotAction", "createregexpwithliteral:createregexpwithliteralAotAction", + + #constructor_returns_non_object:js "dec:decAotAction", + "defineasyncfunc:defineasyncfuncAotAction", + "defineclasswithbuffer:defineclasswithbufferAotAction", + "definefunc:definefuncAotAction", + "definefunc_variable_args:definefunc_variable_argsAotAction", - # "definefunc:definefuncAotAction", - # "definemethod:definemethodAotAction", - # "definencfunc:definencfuncAotAction", + #"definegeneratorfunc:definegeneratorfuncAotAction", + #"definegettersetterbyvalue:definegettersetterbyvalueAotAction", + "definemethod:definemethodAotAction", + "definencfunc:definencfuncAotAction", "delobjprop:delobjpropAotAction", + + #"destructuring:destructuringAotAction", "div:divAotAction", + "duplicatefunctions:duplicatefunctionsAotAction", "exceptionhandler:exceptionhandlerAotAction", "exp:expAotAction", + "getiterator:getiteratorAotAction", + + #"getiteratornext:getiteratornextAotAction", + "getnextpropname:getnextpropnameAotAction", + "getpropiterator:getpropiteratorAotAction", + + #"getresumemode:getresumemodeAotAction", + #"gettemplateobject:gettemplateobjectAotAction", + #"getunmappedargs:getunmappedargsAotAction", "helloaot:helloaotAotAction", "inc:incAotAction", "instanceof:instanceofAotAction", "isfalse:isfalseAotAction", "isin:isinAotAction", "istrue:istrueAotAction", + + #"ldbigint:ldbigintAotAction", + "ldconst:ldconstAotAction", "ldfunctionpref:ldfunctionprefAotAction", "ldglobalvar:ldglobalvarAotAction", "ldobjbyname:ldobjbynameAotAction", + "ldstlexvar:ldstlexvarAotAction", + + #"ldsuperbyname:ldsuperbynameAotAction", "logic_op:logic_opAotAction", "loops:loopsAotAction", "mod:modAotAction", "mul:mulAotAction", "neg:negAotAction", "new:newAotAction", + "newlexenv:newlexenvAotAction", + "newobjspread:newobjspreadAotAction", "not:notAotAction", "or:orAotAction", + "poplexenv:poplexenvAotAction", + + #"resumegenerator:resumegeneratorAotAction", "setobjectwithproto:setobjectwithprotoAotAction", "shl:shlAotAction", "shr:shrAotAction", "starrayspread:starrayspreadAotAction", + "stclasstoglobalrecord:stclasstoglobalrecordAotAction", "stconsttoglobalrecord:stconsttoglobalrecordAotAction", "stglobalvar:stglobalvarAotAction", "stlettoglobalrecord:stlettoglobalrecordAotAction", + + #"stobjbyindex:stobjbyindexAotAction", "stobjbyname:stobjbynameAotAction", + + #"stobjbyvalue:stobjbyvalueAotAction", "stownbyindex:stownbyindexAotAction", "stownbyname:stownbynameAotAction", "stownbynamewithnameset:stownbynamewithnamesetAotAction", "stownbyvalue:stownbyvalueAotAction", - - #"stownbyvaluewithnameset:stownbyvaluewithnamesetAotAction", + "stownbyvaluewithnameset:stownbyvaluewithnamesetAotAction", "strictequal:strictequalAotAction", "strictnotequal:strictnotequalAotAction", + + #stsuperbyname:stsuperbynameAotAction", "sub:subAotAction", + + #"supercall:supercallAotAction", + #"supercallspread:supercallspreadAotAction", + "suspendgenerator:suspendgeneratorAotAction", + "suspendgeneratorbranch:suspendgeneratorbranchAotAction", + + #"suspendgeneratorfor:suspendgeneratorforAotAction", + "suspendgeneratorphi:suspendgeneratorphiAotAction", + "suspendgeneratorreturn:suspendgeneratorreturnAotAction", + "suspendgeneratorthrow:suspendgeneratorthrowAotAction", "throw:throwAotAction", + "throwifsupernotcorrectcall:throwifsupernotcorrectcallAotAction", + "throwundefindeifhole:throwundefindeifholeAotAction", "tonumber:tonumberAotAction", "trystglobalbynameprefid32:trystglobalbynameprefid32AotAction", "typeof:typeofAotAction", + + #undefined:js "xor:xorAotAction", ] } diff --git a/test/aottest/aot_compatibility_test/BUILD.gn b/test/aottest/aot_compatibility_test/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..dd45f900f0df8010d4d6945253852c301a598c78 --- /dev/null +++ b/test/aottest/aot_compatibility_test/BUILD.gn @@ -0,0 +1,21 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +group("aot_compatibility_test") { + testonly = true + deps = [ + "base_verification:base_verificationAotAction", + "builtins_api:builtins_apiAotAction", + "property_operation:property_operationAotAction", + ] +} diff --git a/test/aottest/aot_compatibility_test/base_verification/BUILD.gn b/test/aottest/aot_compatibility_test/base_verification/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5ccd2e8da91000dc47ad9dc48f227ef0e72b4939 --- /dev/null +++ b/test/aottest/aot_compatibility_test/base_verification/BUILD.gn @@ -0,0 +1,19 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("base_verification") { + deps = [] + is_enable_enableArkTools = true +} diff --git a/test/aottest/aot_compatibility_test/base_verification/base_verification.ts b/test/aottest/aot_compatibility_test/base_verification/base_verification.ts new file mode 100644 index 0000000000000000000000000000000000000000..6d36ee618355bccb8483d9af500de7505022bd47 --- /dev/null +++ b/test/aottest/aot_compatibility_test/base_verification/base_verification.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(arg:boolean):string; +declare var ArkTools:any; + +{ + var hc0; + var hc1; + + class C { + a:number; + constructor() { + hc0 = ArkTools.getHClass(this); + this.a = 2; + } + } + + let c = new C(); + + hc1 = ArkTools.getHClass(c); + print(hc0 === hc1); // verify no transition occurs in constructor + print(ArkTools.isTSHClass(c)); // verify the hclass of c is come from compile phase +} diff --git a/test/aottest/aot_compatibility_test/base_verification/expect_output.txt b/test/aottest/aot_compatibility_test/base_verification/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..bef4805f2fa99a19fbe3047fcce9fdf454cdb19b --- /dev/null +++ b/test/aottest/aot_compatibility_test/base_verification/expect_output.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +true +true diff --git a/test/aottest/suspendgenerator_phi/BUILD.gn b/test/aottest/aot_compatibility_test/builtins_api/BUILD.gn similarity index 93% rename from test/aottest/suspendgenerator_phi/BUILD.gn rename to test/aottest/aot_compatibility_test/builtins_api/BUILD.gn index f7e1649b9917e7020786712dc086e366bf420536..34fbf90ebc92aaacab0ec91fc2a13e81cea6e41b 100644 --- a/test/aottest/suspendgenerator_phi/BUILD.gn +++ b/test/aottest/aot_compatibility_test/builtins_api/BUILD.gn @@ -13,6 +13,6 @@ import("//ark/js_runtime/test/test_helper.gni") -host_aot_test_action("suspendgenerator_phi") { +host_aot_test_action("builtins_api") { deps = [] } diff --git a/test/aottest/aot_compatibility_test/builtins_api/builtins_api.ts b/test/aottest/aot_compatibility_test/builtins_api/builtins_api.ts new file mode 100644 index 0000000000000000000000000000000000000000..a75c95fb37d4f90e00b53a7d5ad41cbeab9ca297 --- /dev/null +++ b/test/aottest/aot_compatibility_test/builtins_api/builtins_api.ts @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(arg:string, arg2:any):string; + +{ + class D { + b:string; + constructor() { + print("this.hasOwnProperty:", this.hasOwnProperty("b")); + print("Reflect.has:", Reflect.has(this, "b")); + print("Object.keys():", Object.keys(this)); + print("Reflect.ownKeys():", Reflect.ownKeys(this)); + this.b = "abc"; + } + } + + let d = new D(); +} \ No newline at end of file diff --git a/test/aottest/aot_compatibility_test/builtins_api/expect_output.txt b/test/aottest/aot_compatibility_test/builtins_api/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..7831e1f9ee1e925f0824a9816c326e245a3a5ff3 --- /dev/null +++ b/test/aottest/aot_compatibility_test/builtins_api/expect_output.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +this.hasOwnProperty: false +Reflect.has: false +Object.keys(): +Reflect.ownKeys(): diff --git a/test/aottest/suspendgenerator_branch/BUILD.gn b/test/aottest/aot_compatibility_test/property_operation/BUILD.gn similarity index 92% rename from test/aottest/suspendgenerator_branch/BUILD.gn rename to test/aottest/aot_compatibility_test/property_operation/BUILD.gn index 559d4b54f791d30bcb7f8ea7b055d30d27a703fd..56b7fdb8f54e3dc22d6a3edce0c5f1c374602475 100644 --- a/test/aottest/suspendgenerator_branch/BUILD.gn +++ b/test/aottest/aot_compatibility_test/property_operation/BUILD.gn @@ -13,6 +13,6 @@ import("//ark/js_runtime/test/test_helper.gni") -host_aot_test_action("suspendgenerator_branch") { +host_aot_test_action("property_operation") { deps = [] } diff --git a/test/aottest/aot_compatibility_test/property_operation/expect_output.txt b/test/aottest/aot_compatibility_test/property_operation/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..c62f13bbc6549b65c465cc39ebd6391b5d926ef4 --- /dev/null +++ b/test/aottest/aot_compatibility_test/property_operation/expect_output.txt @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +get before set: undefined +get after set: 2 +get after change: 3 +delete property: true +get after delete: undefined diff --git a/test/aottest/aot_compatibility_test/property_operation/property_operation.ts b/test/aottest/aot_compatibility_test/property_operation/property_operation.ts new file mode 100644 index 0000000000000000000000000000000000000000..c9855bbedfc5b0b29601280540adfec046291f5d --- /dev/null +++ b/test/aottest/aot_compatibility_test/property_operation/property_operation.ts @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(arg:string, arg2:any):string; + +{ + class C { + a:number; + constructor() { + print("get before set:", this.a); + this.a = 2; + } + } + + let c = new C(); + print("get after set:", c.a); + c.a = 3; + print("get after change:", c.a); + + let del:boolean = Reflect.deleteProperty(c, "a"); + print("delete property:", del); + print("get after delete:", c.a); +} diff --git a/test/aottest/bigint_typed_array_constructors/bigint_typed_array_constructors.js b/test/aottest/bigint_typed_array_constructors/bigint_typed_array_constructors.js new file mode 100644 index 0000000000000000000000000000000000000000..162b3b69360b8e79694b833eaf272f315586cd4c --- /dev/null +++ b/test/aottest/bigint_typed_array_constructors/bigint_typed_array_constructors.js @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function foo(a, b) +{ +} + +foo(function(TA) +{ + var sample = new TA([1n, 2n, 3n]); + result = sample.findIndex(function() { return NaN; }); +}); \ No newline at end of file diff --git a/test/aottest/bigint_typed_array_constructors/expect_output.txt b/test/aottest/bigint_typed_array_constructors/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..c307219bab553370101e7c185df3296f7a7b4476 --- /dev/null +++ b/test/aottest/bigint_typed_array_constructors/expect_output.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/test/aottest/call_default_args/BUILD.gn b/test/aottest/call_default_args/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..527a2e9e13a174b13d112d498e2126c231f69608 --- /dev/null +++ b/test/aottest/call_default_args/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("call_default_args") { + deps = [] +} diff --git a/test/aottest/call_default_args/call_default_args.js b/test/aottest/call_default_args/call_default_args.js new file mode 100644 index 0000000000000000000000000000000000000000..bfba09c6759f8a5e3a60fe08745b8a5d5b1462c0 --- /dev/null +++ b/test/aottest/call_default_args/call_default_args.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function foo(a, b, c, d) +{ + return a + b + c + d; +} + +print(foo(1, 2)); +print(foo(1, 2, 3)); +print(foo(1, 2, 3, 4, 5)); \ No newline at end of file diff --git a/test/aottest/call_default_args/expect_output.txt b/test/aottest/call_default_args/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..0fbad21b29e299f3ffea5e39f02714180eefa2b2 --- /dev/null +++ b/test/aottest/call_default_args/expect_output.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +NaN +NaN +10 diff --git a/test/aottest/call_same_bytecode_func/BUILD.gn b/test/aottest/call_same_bytecode_func/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ff571737ad39b063525f4671c03dc179d3d0b1fb --- /dev/null +++ b/test/aottest/call_same_bytecode_func/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("call_same_bytecode_func") { + deps = [] +} diff --git a/test/aottest/call_same_bytecode_func/call_same_bytecode_func.ts b/test/aottest/call_same_bytecode_func/call_same_bytecode_func.ts new file mode 100644 index 0000000000000000000000000000000000000000..cbcdc609d8196917ebe142fd12c3b8f41fad4105 --- /dev/null +++ b/test/aottest/call_same_bytecode_func/call_same_bytecode_func.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +declare function print(str:any):string; + +function foo1(a:string, b:string) +{ + return a + b; +} + +function foo2(a:number, b:number) +{ + return a + b; +} + +function foo3() +{ + print("hello"); +} + +function foo4() +{ + print("hello"); +} +print(foo2(3, 4)); +print(foo1("1", "2")); + +foo3(); +foo4(); \ No newline at end of file diff --git a/test/aottest/call_same_bytecode_func/expect_output.txt b/test/aottest/call_same_bytecode_func/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..952d41f7e537b726493c2ea38930bc558d81f34f --- /dev/null +++ b/test/aottest/call_same_bytecode_func/expect_output.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +7 +12 +hello +hello diff --git a/test/aottest/calls/calls.ts b/test/aottest/calls/calls.ts index 352a82b64e965268eb70bde38417219f680db211..e155b5fba6338e45a730c279eb6c1d1bcfdbfbde 100644 --- a/test/aottest/calls/calls.ts +++ b/test/aottest/calls/calls.ts @@ -12,31 +12,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -declare function print(str:any):string; +declare function print(str: any): string; -function foo() -{ +function foo() { return "pass"; } -function foo1(a:any) -{ - return "pass"; +function foo1(a: any) { + return a + 1; } -function foo2(a:any, b:any) -{ - return "pass"; +function foo2(a: any, b: any) { + return a + b; } -function foo3(a:any, b:any, c:any) -{ - return "pass"; +function foo3(a: any, b: any, c: any) { + return a + b + c; } -function foo4(a:any, b:any, c:any, d:any) -{ - return "pass"; +function foo4(a: any, b: any, c: any, d: any) { + return a + b + c + d; } print(foo()); diff --git a/test/aottest/calls/expect_output.txt b/test/aottest/calls/expect_output.txt index 423bcc3c0562d848d96d129401841619c2e34141..694b2edf96e9f6ff300768ea27e8c65d2fdf3007 100644 --- a/test/aottest/calls/expect_output.txt +++ b/test/aottest/calls/expect_output.txt @@ -12,7 +12,7 @@ # limitations under the License. pass -pass -pass -pass -pass +2 +3 +6 +10 diff --git a/test/aottest/constructor_returns_non_object/constructor_returns_non_object.js b/test/aottest/constructor_returns_non_object/constructor_returns_non_object.js new file mode 100644 index 0000000000000000000000000000000000000000..3a79c077f445dc577ca07464959ac7ab8e0fffd4 --- /dev/null +++ b/test/aottest/constructor_returns_non_object/constructor_returns_non_object.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +class Obj extends Object { + constructor() { + return 11; + } +} \ No newline at end of file diff --git a/test/aottest/constructor_returns_non_object/expect_output.txt b/test/aottest/constructor_returns_non_object/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..c307219bab553370101e7c185df3296f7a7b4476 --- /dev/null +++ b/test/aottest/constructor_returns_non_object/expect_output.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts b/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts index 6cd4c39de35d3c2eaad40f0dc2b94072db74659e..4ceca6dbda501e6ae0a5ee2d001e887b5797d525 100644 --- a/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts +++ b/test/aottest/defineclasswithbuffer/defineclasswithbuffer.ts @@ -19,15 +19,21 @@ class Obj1 { constructor(value:number) { this.value = value; } + fun(s:number):number { + return 1 + this.value + s; + } } class Obj2 { - fun():void { + fun():void { print("Hello World"); - } + } } -var obj1 = new Obj1(0); +var obj1 = new Obj1(1); print(obj1.value); +print(obj1.fun(2)); var obj2 = new Obj2(); obj2.fun(); + +print(obj1 instanceof Object); diff --git a/test/aottest/defineclasswithbuffer/expect_output.txt b/test/aottest/defineclasswithbuffer/expect_output.txt index 08f99d2d7a29a95fcbb0a2d8858a60a170def8dd..e768ead6ad799f199df61680790f4801db13026d 100644 --- a/test/aottest/defineclasswithbuffer/expect_output.txt +++ b/test/aottest/defineclasswithbuffer/expect_output.txt @@ -11,5 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -0 +1 +4 Hello World +true diff --git a/test/aottest/destructuring/BUILD.gn b/test/aottest/destructuring/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4e71da934aee6593d66e7056f57d442be0516162 --- /dev/null +++ b/test/aottest/destructuring/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("destructuring") { + deps = [] +} diff --git a/test/aottest/destructuring/destructuring.ts b/test/aottest/destructuring/destructuring.ts new file mode 100644 index 0000000000000000000000000000000000000000..d87c6257d89984736c8e8f2201a9962105de18fd --- /dev/null +++ b/test/aottest/destructuring/destructuring.ts @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(arg:any):string; +function foo({x = 11, y = 22}) +{ + return x + y; +} + +print(foo({})); \ No newline at end of file diff --git a/test/aottest/destructuring/expect_output.txt b/test/aottest/destructuring/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..92f1ae9c50f2a7d6790ddc92f80d6cfb7027f80e --- /dev/null +++ b/test/aottest/destructuring/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +33 diff --git a/test/aottest/duplicatefunctions/BUILD.gn b/test/aottest/duplicatefunctions/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6a74d032eb6d72dd984ab8fc23930d5f20409ffa --- /dev/null +++ b/test/aottest/duplicatefunctions/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("duplicatefunctions") { + deps = [] +} diff --git a/test/aottest/duplicatefunctions/duplicatefunctions.ts b/test/aottest/duplicatefunctions/duplicatefunctions.ts new file mode 100644 index 0000000000000000000000000000000000000000..e65d2f1fad5aec4a168c13f88b6cd91c9141fd9f --- /dev/null +++ b/test/aottest/duplicatefunctions/duplicatefunctions.ts @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +declare function print(str:any):string; + +function foo1(a:number, b:number) +{ + return a + b; +} + +var obj = { + fun (a:number, b:number) { return a + b; }, +}; + +class Obj1 { + fun(a:number, b:number):number { + return a + b; + } +} + +function foo2(a:number, b:number) +{ + return a + b; +} + +var obj1 = new Obj1(); + +print(foo1(1, 1)); +print(foo2(2, 2)); +print(obj.fun(3, 3)); +print(obj1.fun(4, 4)); diff --git a/test/aottest/duplicatefunctions/expect_output.txt b/test/aottest/duplicatefunctions/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..adedb79915d92a12104f28994074f2a1fb9457c3 --- /dev/null +++ b/test/aottest/duplicatefunctions/expect_output.txt @@ -0,0 +1,17 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +2 +4 +6 +8 diff --git a/test/aottest/global_this_js/BUILD.gn b/test/aottest/global_this_js/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..340c7f0751bec59f867696673e876c166f2bd440 --- /dev/null +++ b/test/aottest/global_this_js/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("sub") { + deps = [] +} diff --git a/test/aottest/global_this_js/expect_output.txt b/test/aottest/global_this_js/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..c307219bab553370101e7c185df3296f7a7b4476 --- /dev/null +++ b/test/aottest/global_this_js/expect_output.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + diff --git a/test/aottest/global_this_js/global_this_js.js b/test/aottest/global_this_js/global_this_js.js new file mode 100644 index 0000000000000000000000000000000000000000..eef67df6c5c1b454b0ca22060a658646b12e12a2 --- /dev/null +++ b/test/aottest/global_this_js/global_this_js.js @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var global = this; +var a = Object.create({}, { + prop: { + set: global + } +}); + +print(typeof global); \ No newline at end of file diff --git a/test/aottest/global_this_ts/BUILD.gn b/test/aottest/global_this_ts/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..340c7f0751bec59f867696673e876c166f2bd440 --- /dev/null +++ b/test/aottest/global_this_ts/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("sub") { + deps = [] +} diff --git a/test/aottest/global_this_ts/expect_output.txt b/test/aottest/global_this_ts/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..421bb7a7694864e1b89a285d4df002228b0ee68f --- /dev/null +++ b/test/aottest/global_this_ts/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +object diff --git a/test/aottest/global_this_ts/global_this_ts.ts b/test/aottest/global_this_ts/global_this_ts.ts new file mode 100644 index 0000000000000000000000000000000000000000..1660b44c380afce96bb1c8b2c7ee3c1c0067ab99 --- /dev/null +++ b/test/aottest/global_this_ts/global_this_ts.ts @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(str:any):string; + +var global = this; +print(typeof global); \ No newline at end of file diff --git a/test/aottest/makefile b/test/aottest/makefile index 3bf7701adf50cc242524fa40caf113a0ad1da2aa..9cab6937297116e957fae6f4a6fc34694802928a 100644 --- a/test/aottest/makefile +++ b/test/aottest/makefile @@ -13,7 +13,18 @@ debug:=no log:=no +arm:=no args:= +product:= +product_dir:= +qemu:= +compiler:= +compiler_args:= +stub_compiler:= +jsvm:= +module_flag:= +empty:= +space:=$(empty) $(empty) root_dir=$(shell pwd) ifeq ($(test), ) test_name=helloaot @@ -21,58 +32,109 @@ else test_name=$(test) endif +ifeq ($(module), yes) + module_flag=-m +endif + ifeq ($(log), yes) - args+= --log-compiled-methods=all + args+= --log-compiled-methods=all --log-level=info endif -ifeq ($(debug), no) - export LD_LIBRARY_PATH=$(root_dir)/out/hispark_taurus/clang_x64/ark/ark:$(root_dir)/out/hispark_taurus/clang_x64/ark/ark_js_runtime:$(root_dir)/out/hispark_taurus/clang_x64/thirdparty/icu:$(root_dir)/prebuilts/clang/ohos/linux-x86_64/llvm/lib - bin_dir=$(root_dir)/out/hispark_taurus/clang_x64/ark/ark_js_runtime +ifeq ($(arm), no) + product=hispark_taurus + product_dir=$(root_dir)/out/$(product) + ifeq ($(debug), no) + export LD_LIBRARY_PATH=$(product_dir)/clang_x64/ark/ark:$(product_dir)/clang_x64/ark/ark_js_runtime:$(product_dir)/clang_x64/thirdparty/icu:$(root_dir)/prebuilts/clang/ohos/linux-x86_64/llvm/lib + compiler=$(product_dir)/clang_x64/ark/ark_js_runtime/ark_aot_compiler + stub_compiler=$(product_dir)/clang_x64/ark/ark_js_runtime/ark_stub_compiler + jsvm=$(product_dir)/clang_x64/ark/ark_js_runtime/ark_js_vm + else + export LD_LIBRARY_PATH=$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark:$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime:$(product_dir)/clang_x64/lib.unstripped/clang_x64/ark/ark:$(product_dir)/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime:$(product_dir)/clang_x64/lib.unstripped/clang_x64/test/test:$(product_dir)/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:$(root_dir)/prebuilts/clang/ohos/linux-x86_64/llvm/lib + compiler=$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_aot_compiler + stub_compiler=$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_stub_compiler + jsvm=$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_js_vm + endif else - export LD_LIBRARY_PATH=$(root_dir)/out/hispark_taurus/clang_x64/exe.unstripped/clang_x64/ark/ark:$(root_dir)/out/hispark_taurus/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime:$(root_dir)/out/hispark_taurus/clang_x64/lib.unstripped/clang_x64/ark/ark:$(root_dir)/out/hispark_taurus/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime:$(root_dir)/out/hispark_taurus/clang_x64/lib.unstripped/clang_x64/test/test:$(root_dir)/out/hispark_taurus/clang_x64/lib.unstripped/clang_x64/thirdparty/icu:$(root_dir)/prebuilts/clang/ohos/linux-x86_64/llvm/lib - bin_dir=$(root_dir)/out/hispark_taurus/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime + product=rk3568 + product_dir=$(root_dir)/out/$(product) + qemu=qemu-aarch64 + compiler_args+= --target-triple=aarch64-unknown-linux-gnu + ifeq ($(debug), no) + export LD_LIBRARY_PATH=$(product_dir)/ark/ark/:$(product_dir)/ark/ark_js_runtime/:$(root_dir)/prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos/c++/:$(product_dir)/utils/utils_base/:$(product_dir)/thirdparty/icu:$(product_dir)/securec/thirdparty_bounds_checking_function/:$(product_dir)/hiviewdfx/hitrace_native/:$(product_dir)/clang_x64/ark/ark/:$(product_dir)/clang_x64/thirdparty/icu/:$(product_dir)/clang_x64/ark/ark_js_runtime + compiler=$(product_dir)/clang_x64/ark/ark_js_runtime/ark_aot_compiler + stub_compiler=$(product_dir)/clang_x64/ark/ark_js_runtime/ark_stub_compiler + jsvm=$(product_dir)/ark/ark_js_runtime/ark_js_vm + else + export LD_LIBRARY_PATH=$(product_dir)/lib.unstripped/ark/ark/:$(product_dir)/lib.unstripped/ark/ark_js_runtime/:$(root_dir)/prebuilts/clang/ohos/linux-x86_64/llvm/lib/aarch64-linux-ohos/c++/:$(product_dir)/lib.unstripped/utils/utils_base/:$(product_dir)/lib.unstripped/thirdparty/icu:$(product_dir)/lib.unstripped/securec/thirdparty_bounds_checking_function/:$(product_dir)/lib.unstripped/hiviewdfx/hitrace_native/:$(product_dir)/lib.unstripped/clang_x64/ark/ark/:$(product_dir)/clang_x64/lib.unstripped/clang_x64/thirdparty/icu/:$(product_dir)/clang_x64/lib.unstripped/clang_x64/ark/ark/:$(product_dir)/clang_x64/lib.unstripped/clang_x64/ark/ark_js_runtime + compiler=$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_aot_compiler + stub_compiler=$(product_dir)/clang_x64/exe.unstripped/clang_x64/ark/ark_js_runtime/ark_stub_compiler + jsvm=$(product_dir)/exe.unstripped/ark/ark_js_runtime/ark_js_vm + endif endif -ts2abc=$(root_dir)/out/hispark_taurus/clang_x64/obj/ark/ts2abc/ts2panda/build/src/index.js test_dir=$(root_dir)/ark/js_runtime/test/aottest -out_dir=$(root_dir)/out/hispark_taurus/clang_x64/aottest +ts2abc=$(product_dir)/clang_x64/obj/ark/ts2abc/ts2panda/build/src/index.js +out_dir=$(product_dir)/clang_x64/aottest case_dir=$(out_dir)/$(test_name) -com_stub_args= --asm-interpreter=true --stub-file=$(out_dir)/stub.m +com_stub_args=--asm-interpreter=true --stub-file=$(out_dir)/stub.m abc: mkdir -p $(case_dir) - node --expose-gc $(ts2abc) $(test_dir)/$(test_name)/$(test_name).ts -o $(case_dir)/$(test_name).abc + node --expose-gc $(ts2abc) $(wildcard $(test_dir)/$(test_name)/$(test_name).[tj]s) $(module_flag) stub: mkdir -p $(out_dir) - cd $(out_dir) && $(bin_dir)/ark_stub_compiler $(args) --stub-file=stub.m + $(stub_compiler) $(compiler_args) $(args) --stub-file=$(out_dir)/stub.m + aot: - cd $(case_dir) && $(bin_dir)/ark_aot_compiler $(args) $(test_name).abc + $(compiler) $(compiler_args) $(args) --aot-file=$(case_dir)/aot_file.m $(subst $(space),:,$(wildcard $(test_dir)/$(test_name)/*.abc)) aotd: - cd $(case_dir) && gdb --args $(bin_dir)/ark_aot_compiler $(args) $(test_name).abc + gdb --args $(compiler) $(compiler_args) $(args) --aot-file=$(case_dir)/aot_file.m $(subst $(space),:,$(wildcard $(test_dir)/$(test_name)/*.abc)) run: - cd $(case_dir) && $(bin_dir)/ark_js_vm $(args) --aot-file=aot_file.m $(com_stub_args) $(test_name).abc + $(qemu) $(jsvm) $(args) --aot-file=$(case_dir)/aot_file.m $(com_stub_args) $(test_dir)/$(test_name)/$(test_name).abc rund: - cd $(case_dir) && gdb --args $(bin_dir)/ark_js_vm $(args) --aot-file=aot_file.m $(com_stub_args) $(test_name).abc +ifeq ($(arm), no) + gdb --args $(jsvm) $(args) --aot-file=$(case_dir)/aot_file.m $(com_stub_args) $(test_dir)/$(test_name)/$(test_name).abc +else + @echo "gdb-client start: gdb-multiarch $(jsvm)" + @echo "gdb-server connect: target remote:123456" + $(qemu) -cpu max,sve=off -g 123456 $(jsvm) $(args) --aot-file=$(case_dir)/aot_file.m $(com_stub_args) $(test_dir)/$(test_name)/$(test_name).abc +endif int: - cd $(case_dir) && $(bin_dir)/ark_js_vm $(args) $(test_name).abc + $(qemu) $(jsvm) $(args) $(test_dir)/$(test_name)/$(test_name).abc intd: - cd $(case_dir) && gdb --args $(bin_dir)/ark_js_vm $(args) $(test_name).abc +ifeq ($(arm), no) + gdb --args $(jsvm) $(args) $(test_dir)/$(test_name)/$(test_name).abc +else + @echo "gdb-client start: gdb-multiarch $(jsvm)" + @echo "gdb-server connect: target remote:123456" + $(qemu) -cpu max,sve=off -g 123456 $(jsvm) $(args) $(test_dir)/$(test_name)/$(test_name).abc +endif asmint: - cd $(case_dir) && $(bin_dir)/ark_js_vm $(args) $(com_stub_args) $(test_name).abc + $(qemu) $(jsvm) $(args) $(com_stub_args) $(test_dir)/$(test_name)/$(test_name).abc asmintd: - cd $(case_dir) && gdb --args $(bin_dir)/ark_js_vm $(args) $(com_stub_args) $(test_name).abc +ifeq ($(arm), no) + gdb --args $(jsvm) $(args) $(com_stub_args) $(test_dir)/$(test_name)/$(test_name).abc +else + @echo "gdb-client start: gdb-multiarch $(jsvm)" + @echo "gdb-server connect: target remote:123456" + $(qemu) -cpu max,sve=off -g 123456 $(jsvm) $(args) $(com_stub_args) $(test_dir)/$(test_name)/$(test_name).abc +endif + +clean: + rm $(test_dir)/$(test_name)/*.abc + rm -rf $(case_dir) env: @echo "root_dir=$(root_dir)" @echo "test_name=$(test_name)" @echo "test_dir=$(test_dir)" @echo "case_dir=$(case_dir)" - @echo "LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" \ No newline at end of file + @echo "export LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)" \ No newline at end of file diff --git a/test/aottest/module/BUILD.gn b/test/aottest/module/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7d955311f24668891779e35d87899c9f07954747 --- /dev/null +++ b/test/aottest/module/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("stglobalvar") { + deps = [] +} diff --git a/test/aottest/module/add.js b/test/aottest/module/add.js new file mode 100644 index 0000000000000000000000000000000000000000..5f0eb24342fb91f32331fdc270725f733a8a9c2d --- /dev/null +++ b/test/aottest/module/add.js @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export function add(a, b) +{ + return a + b; +} \ No newline at end of file diff --git a/test/aottest/module/expect_output.txt b/test/aottest/module/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..8fb3fad4e8c06455b08b64a7f8ebe0b94b72f08a --- /dev/null +++ b/test/aottest/module/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +3 diff --git a/test/aottest/module/module.js b/test/aottest/module/module.js new file mode 100644 index 0000000000000000000000000000000000000000..ffdcb84865bd8475bce2c2955979c927a410f76b --- /dev/null +++ b/test/aottest/module/module.js @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//declare function print(str:any):number; + +import * as ns from './add.js'; +var a = ns.add(1,2); +print(a) diff --git a/test/aottest/proxy/BUILD.gn b/test/aottest/proxy/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fbe7daaebb6c363ae735b93d496526601aab8dea --- /dev/null +++ b/test/aottest/proxy/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("proxy") { + deps = [] +} diff --git a/test/aottest/proxy/expect_output.txt b/test/aottest/proxy/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..7656742c1f663031365ed68d71c6c18658ff17e9 --- /dev/null +++ b/test/aottest/proxy/expect_output.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +3 +Calculate sum: 1,2 +30 diff --git a/test/aottest/proxy/proxy.ts b/test/aottest/proxy/proxy.ts new file mode 100644 index 0000000000000000000000000000000000000000..fbcda47f55a45f2f12820d881c9502d463844a75 --- /dev/null +++ b/test/aottest/proxy/proxy.ts @@ -0,0 +1,22 @@ +declare function print(str:any):string; + + + +function sum(a:number, b:number):number { + return a + b; + } + +const handler = { + apply: function(target:any, thisArg:any, argumentsList:any[]) { + print(`Calculate sum: ${argumentsList}`); + // expected output: "Calculate sum: 1,2" + + return target(argumentsList[0], argumentsList[1]) * 10; + } +}; + +const proxy1 = new Proxy(sum, handler); + +print(sum(1, 2)); +// expected output: 3 +print(proxy1(1, 2)); diff --git a/test/aottest/runtest.sh b/test/aottest/runtest.sh index a9175fe2b3e4689f31ed83f66ed91c3c53ce11e2..8bde97a8dd668caa4d242d29c3cbdb913801e325 100755 --- a/test/aottest/runtest.sh +++ b/test/aottest/runtest.sh @@ -14,16 +14,14 @@ expect_output="expect_output.txt" run_output="run_output.txt" -build_output="build_output.txt" test_name="" test_dir=$(dirname $0) -out_dir="out/hispark_taurus/clang_x64/aottest" -test_all_mode="no" +product="hispark_taurus" run_args="" -oat_args="" run_mode="aot" +make_opt="" cur_dir=$(pwd) -test_timeout=120 +timeout=20 check_result_fexit() { @@ -60,7 +58,9 @@ echo_fail() run_check() { timeout $@ + # FIXME: run result can not be checked by $? when run unexpectedly exit, such as segmentation fault + ret=0 ret=$? if [ $ret -eq 124 -o $ret -eq 142 ]; then echo_fail "Run timeout, be killed!" @@ -75,9 +75,8 @@ usage() { echo -e "Usage: runtest.sh [options] test_name Options: - -mode:aot run on aot mode, default - -mode:int run on interpret mode - -mode:asmint run on asm interpret mode + -mode [opt] run mode option: aot, int(interpret mode), asmint(asm interpret mode) + -make [opt] pass option to make, supported opt: abc, aot, aotd, run, rund, int, intd, asmint, asmintd -debug run on debug mode -timeout n specify seconds of test timeout, n > 0 -v show version @@ -87,18 +86,22 @@ usage() while [ $# -gt 0 ] do case $1 in - -mode:aot) - run_mode="aot" - shift 1 ;; - -mode:asmint) - run_mode="asmint" - shift 1 ;; - -mode:int) - run_mode="int" - shift 1 ;; + -mode) + run_mode=$2 + shift 2 ;; + -make) + make_opt=$2 + shift 2 ;; -debug) run_args="$run_args debug=yes" shift 1 ;; + -arm) + product="rk3568" + run_args="$run_args arm=yes" + shift 1 ;; + -timeout) + timeout=$2 + shift 2 ;; -v) tail -n +14 $test_dir/version exit 0 ;; @@ -123,29 +126,42 @@ fi test_name=$(basename $test_name) echo "Run test: $test_dir/$test_name =================" +out_dir="out/$product/clang_x64/aottest" if [ ! -f "$out_dir/stub.m" ]; then - make -n -f $test_dir/makefile $run_args stub - run_check $test_timeout make -s -f $test_dir/makefile $run_args stub + make -f $test_dir/makefile $run_args stub + check_result_fexit "make stub.m FAILED" +fi + +module="" +if [ -n "$(grep 'import' $(ls $test_dir/$test_name/$test_name.[tj]s))" ]; then + module="module=yes" +fi + +make_cmd="make -f $test_dir/makefile $run_args test=$test_name $module" + +if [ -n "$make_opt" ]; then + $make_cmd $make_opt + check_result_fexit "make $make_opt FAILED" + exit 0 fi -make_cmd="make -f $test_dir/makefile $run_args test=$test_name" $make_cmd -n abc -run_check $test_timeout $make_cmd -s abc +run_check $timeout $make_cmd -s abc case "$run_mode" in "aot") $make_cmd -n aot - run_check $test_timeout $make_cmd -s aot + run_check $timeout $make_cmd -s aot $make_cmd -n run - run_check $test_timeout $make_cmd -s run > $out_dir/$test_name/$run_output + run_check $timeout $make_cmd -s run > $out_dir/$test_name/$run_output ;; "int") $make_cmd -n int - run_check $test_timeout $make_cmd -s int > $out_dir/$test_name/$run_output + run_check $timeout $make_cmd -s int > $out_dir/$test_name/$run_output ;; "asmint") $make_cmd -n asmint - run_check $test_timeout $make_cmd -s asmint > $out_dir/$test_name/$run_output + run_check $timeout $make_cmd -s asmint > $out_dir/$test_name/$run_output ;; esac diff --git a/test/aottest/runtestall.sh b/test/aottest/runtestall.sh index ef6f434e39ab64197e02983085ecd6b29f969e49..ce2349156bcaefba2da037a5ac1794538fa0b6ea 100755 --- a/test/aottest/runtestall.sh +++ b/test/aottest/runtestall.sh @@ -13,23 +13,18 @@ # limitations under the License. expected="expect_output.txt" -generate_mode="no" -run_mode="aot" -test_range="" run_args="" -out_dir="" test_dir=$(dirname $0) cur_dir=$(pwd) -time_string=`date +%Y%m%d%H%M%S` usage() { echo -e "Usage: runtestall.sh [options] Options: - -mode:aot run on aot mode, default - -mode:int run on interpret mode - -mode:asmint run on asm interpret mode + -mode [opt] run mode option: aot, int(interpret mode), asmint(asm interpret mode) + -make [opt] pass option to make, supported opt: abc, aot, aotd, run, rund, int, intd, asmint, asmintd -debug run on debug mode + -timeout n specify seconds of test timeout, n > 0 -v show version -h print this usage statement" } @@ -47,18 +42,21 @@ echo_fail() while [ $# -gt 0 ] do case $1 in - -mode:aot) - run_mode="aot" - shift 1 ;; - -mode:asmint) - run_mode="asmint" - shift 1 ;; - -mode:int) - run_mode="int" - shift 1 ;; + -mode) + run_args="$run_args -mode $2" + shift 2 ;; + -make) + run_args="$run_args -make $2" + shift 2 ;; -debug) run_args="$run_args -debug" shift 1 ;; + -arm) + run_args="$run_args -arm" + shift 1 ;; + -timeout) + run_args="$run_args -timeout $2" + shift 2 ;; -v) tail -n +14 $test_dir/version exit 0 ;; @@ -90,7 +88,7 @@ do if [ -d "$test" -a -f "$test/$expected" ]; then test_name=$(basename $test) echo $test_name - $test_dir/runtest.sh -mode:$run_mode $run_args $test_name + $test_dir/runtest.sh $run_args $test_name if [ $? -ne 0 ]; then failed_test_array[failed_count]=$test_name let failed_count++ diff --git a/test/aottest/suspendgeneratorbranch/BUILD.gn b/test/aottest/suspendgeneratorbranch/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..5d0e3bc9109d59500f3494ebdae0a85e5856fc71 --- /dev/null +++ b/test/aottest/suspendgeneratorbranch/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("suspendgeneratorbranch") { + deps = [] +} diff --git a/test/aottest/suspendgenerator_branch/expect_output.txt b/test/aottest/suspendgeneratorbranch/expect_output.txt similarity index 100% rename from test/aottest/suspendgenerator_branch/expect_output.txt rename to test/aottest/suspendgeneratorbranch/expect_output.txt diff --git a/test/aottest/suspendgenerator_branch/suspendgenerator_branch.ts b/test/aottest/suspendgeneratorbranch/suspendgeneratorbranch.ts similarity index 100% rename from test/aottest/suspendgenerator_branch/suspendgenerator_branch.ts rename to test/aottest/suspendgeneratorbranch/suspendgeneratorbranch.ts diff --git a/test/aottest/suspendgeneratorfor/BUILD.gn b/test/aottest/suspendgeneratorfor/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b46731d04f8f5639764b95f96f9d8f80b3cdc8ad --- /dev/null +++ b/test/aottest/suspendgeneratorfor/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("suspendgeneratorfor") { + deps = [] +} diff --git a/test/aottest/suspendgeneratorfor/expect_output.txt b/test/aottest/suspendgeneratorfor/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b55b3c53f71638f0247915a7a8d2d2edcd5cd27 --- /dev/null +++ b/test/aottest/suspendgeneratorfor/expect_output.txt @@ -0,0 +1,26 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +10000 +1 +11 +20000 +102 +112 +30000 +1003 +1013 +40000 +1104 +1114 +undefined diff --git a/test/aottest/suspendgeneratorfor/suspendgeneratorfor.ts b/test/aottest/suspendgeneratorfor/suspendgeneratorfor.ts new file mode 100644 index 0000000000000000000000000000000000000000..83c70b5ac23d53deded1cd985ba282c1f031dc0b --- /dev/null +++ b/test/aottest/suspendgeneratorfor/suspendgeneratorfor.ts @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(str: any): string; +function* genFun() { + let t = 0; + for (var i = 0; i < 2; i += 1) { + for (var j = 0; j < 2; j += 1) { + for (var k = 0; k < 1; k += 1) { + t++; + yield t * 10000; + } + for (var k = 0; k < 2; k += 1) { + try { + yield i * 1000 + j * 100 + k * 10 + t; + } catch (e) { + print(e); + } + } + } + } +} + +var func = genFun(); +print(func.next().value); +print(func.next().value); +print(func.next().value); +print(func.next().value); +print(func.next().value); +print(func.next().value); +print(func.next().value); +print(func.next().value); +print(func.next().value); \ No newline at end of file diff --git a/test/aottest/suspendgeneratorphi/BUILD.gn b/test/aottest/suspendgeneratorphi/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..10930e1d9dfed855463349c048a51761909f44d8 --- /dev/null +++ b/test/aottest/suspendgeneratorphi/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("suspendgeneratorphi") { + deps = [] +} diff --git a/test/aottest/suspendgenerator_phi/expect_output.txt b/test/aottest/suspendgeneratorphi/expect_output.txt similarity index 100% rename from test/aottest/suspendgenerator_phi/expect_output.txt rename to test/aottest/suspendgeneratorphi/expect_output.txt diff --git a/test/aottest/suspendgenerator_phi/suspendgenerator_phi.ts b/test/aottest/suspendgeneratorphi/suspendgeneratorphi.ts similarity index 100% rename from test/aottest/suspendgenerator_phi/suspendgenerator_phi.ts rename to test/aottest/suspendgeneratorphi/suspendgeneratorphi.ts diff --git a/test/aottest/suspendgeneratorreturn/BUILD.gn b/test/aottest/suspendgeneratorreturn/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fd75b7238335ae14b312fa2dc0af6f0e9e0a96e8 --- /dev/null +++ b/test/aottest/suspendgeneratorreturn/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("suspendgeneratorreturn") { + deps = [] +} diff --git a/test/aottest/suspendgeneratorreturn/expect_output.txt b/test/aottest/suspendgeneratorreturn/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..604f418f7489bf706edc67eec8c55bc4c09e5c8e --- /dev/null +++ b/test/aottest/suspendgeneratorreturn/expect_output.txt @@ -0,0 +1,16 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +1 +undefined +undefined diff --git a/test/aottest/suspendgeneratorreturn/suspendgeneratorreturn.ts b/test/aottest/suspendgeneratorreturn/suspendgeneratorreturn.ts new file mode 100644 index 0000000000000000000000000000000000000000..da5a36059147e21afa437dc634371e40a05aa593 --- /dev/null +++ b/test/aottest/suspendgeneratorreturn/suspendgeneratorreturn.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(str:any):string; +function* gen() { + yield 1; + yield 2; + yield 3; +} + +var g = gen(); + +print(g.next().value); +print(g.return().value); +print(g.next().value); diff --git a/test/aottest/suspendgeneratorthrow/BUILD.gn b/test/aottest/suspendgeneratorthrow/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e9372e478105c54928f2612eb4c35003ce53843b --- /dev/null +++ b/test/aottest/suspendgeneratorthrow/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("suspendgeneratorthrow") { + deps = [] +} diff --git a/test/aottest/suspendgeneratorthrow/expect_output.txt b/test/aottest/suspendgeneratorthrow/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..860037e120a80b9174f9ac16d89c0b63aa4f4625 --- /dev/null +++ b/test/aottest/suspendgeneratorthrow/expect_output.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +42 +Error caught! diff --git a/test/aottest/suspendgeneratorthrow/suspendgeneratorthrow.ts b/test/aottest/suspendgeneratorthrow/suspendgeneratorthrow.ts new file mode 100644 index 0000000000000000000000000000000000000000..64f9e932642520e97ec19d4f32b9bbc4bdd34741 --- /dev/null +++ b/test/aottest/suspendgeneratorthrow/suspendgeneratorthrow.ts @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +declare function print(str:any): string; +function* gen() { + while (true) { + try { + yield 42; + } catch (e) { + print("Error caught!"); + } + } +} + +var g = gen(); +print(g.next().value); +g.throw(new Error("Something went wrong")); diff --git a/test/aottest/undefined/BUILD.gn b/test/aottest/undefined/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..24af57c42a99e3098b55dd08f87baca6ff6bc1cf --- /dev/null +++ b/test/aottest/undefined/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_aot_test_action("undefined") { + deps = [] +} diff --git a/test/aottest/undefined/expect_output.txt b/test/aottest/undefined/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6d4aa54ae53d11ad10b2cc4fb7fb4512bbb2b1c --- /dev/null +++ b/test/aottest/undefined/expect_output.txt @@ -0,0 +1,20 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +NaN +NaN +NaN +NaN +false +false +false diff --git a/test/aottest/undefined/undefined.js b/test/aottest/undefined/undefined.js new file mode 100644 index 0000000000000000000000000000000000000000..b33df248c2e3b58a7be2d8c3aeaf3169b4a51ae1 --- /dev/null +++ b/test/aottest/undefined/undefined.js @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +print(1 + undefined); +print(1 - undefined); +print(1 * undefined) +print(1 / undefined); +print(1 > undefined); +print(1 < undefined); +print(1 == undefined); \ No newline at end of file diff --git a/test/aottest/version b/test/aottest/version index 09ffd1a3294632f07fcf6c22138add626126af12..945fa73f3d1ebb2ca55593463b04c145507259ba 100644 --- a/test/aottest/version +++ b/test/aottest/version @@ -11,4 +11,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -0.1.0-20220419 +0.2.1-20220620 support js case, and multi files case +0.2.0-20220617 support arm64, and -make option +0.1.0-20220419 first version diff --git a/test/moduletest/BUILD.gn b/test/moduletest/BUILD.gn index eb34af712d8d6481e1d7e939f74b1c047c32b7c8..396da335d433130efde2498e8de074b918ba75c7 100644 --- a/test/moduletest/BUILD.gn +++ b/test/moduletest/BUILD.gn @@ -15,6 +15,7 @@ group("ark_js_moduletest") { testonly = true deps = [ "allocatearraybuffer:allocatearraybufferAction", + "arrayjoin:arrayjoinAction", "async:asyncAction", "bindfunction:bindfunctionAction", "bitwiseop:bitwiseopAction", @@ -32,10 +33,13 @@ group("ark_js_moduletest") { "globalthis:globalthisAction", "helloworld:helloworldAction", "lexicalenv:lexicalenvAction", + "loadicbyvalue:loadicbyvalueAction", "module:moduleAction", + "moduleUseCjs:moduleUseCjsAction", "multiargs:multiargsAction", "newobjdynrange:newobjdynrangeAction", "objectcloneproperties:objectclonepropertiesAction", + "objoperate:objoperateAction", "promise:promiseAction", "proxy:proxyAction", "regexpcallthrow:regexpcallthrowAction", @@ -57,6 +61,7 @@ group("ark_asm_test") { testonly = true deps = [ "allocatearraybuffer:allocatearraybufferAsmAction", + "arrayjoin:arrayjoinAsmAction", "async:asyncAsmAction", "bindfunction:bindfunctionAsmAction", "bitwiseop:bitwiseopAsmAction", @@ -74,10 +79,12 @@ group("ark_asm_test") { "globalthis:globalthisAsmAction", "helloworld:helloworldAsmAction", "lexicalenv:lexicalenvAsmAction", + "loadicbyvalue:loadicbyvalueAsmAction", "module:moduleAsmAction", "multiargs:multiargsAsmAction", "newobjdynrange:newobjdynrangeAsmAction", "objectcloneproperties:objectclonepropertiesAsmAction", + "objoperate:objoperateAsmAction", "promise:promiseAsmAction", "proxy:proxyAsmAction", "regexpcallthrow:regexpcallthrowAsmAction", diff --git a/build/third_party_gn/jsoncpp/BUILD.gn b/test/moduletest/arrayjoin/BUILD.gn similarity index 40% rename from build/third_party_gn/jsoncpp/BUILD.gn rename to test/moduletest/arrayjoin/BUILD.gn index 60541350d33c28ddae64a461c759250d5abc4e53..6782fc8737b3cdee5aaa86167a4a8972b01eb12a 100644 --- a/build/third_party_gn/jsoncpp/BUILD.gn +++ b/test/moduletest/arrayjoin/BUILD.gn @@ -3,43 +3,16 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. +# limitations under the License. -import("$build_root/ark.gni") +import("//ark/js_runtime/test/test_helper.gni") -config("jsoncpp_config") { - cflags = [ - "-std=c++17", - "-Wno-error=implicit-fallthrough", - "-Wno-deprecated-declarations", - ] -} - -config("jsoncpp_public_config") { - cflags_cc = [ - "-fexceptions", - "-fPIC", - ] - include_dirs = [ "//third_party/jsoncpp/include/" ] -} - -ark_shared_library("jsoncpp") { - visibility = [ "*" ] - sources = [ - "//third_party/jsoncpp/src/lib_json/json_reader.cpp", - "//third_party/jsoncpp/src/lib_json/json_value.cpp", - "//third_party/jsoncpp/src/lib_json/json_writer.cpp", - ] - configs = [ ":jsoncpp_config" ] - include_dirs = [ - "//third_party/jsoncpp/include/json/", - "//third_party/jsoncpp/include/", - ] - public_configs = [ ":jsoncpp_public_config" ] +host_moduletest_action("arrayjoin") { + deps = [] } diff --git a/test/moduletest/arrayjoin/arrayjoin.js b/test/moduletest/arrayjoin/arrayjoin.js new file mode 100644 index 0000000000000000000000000000000000000000..13c966b84a7e8fa38d8bee8a22f5b3a4566ed90a --- /dev/null +++ b/test/moduletest/arrayjoin/arrayjoin.js @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var a=new Array(1).join(" "); +print(a.length); \ No newline at end of file diff --git a/test/moduletest/arrayjoin/expect_output.txt b/test/moduletest/arrayjoin/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..2f5c39d2a5057ecfc59d322ce1eff4da08beb654 --- /dev/null +++ b/test/moduletest/arrayjoin/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +0 diff --git a/test/moduletest/class/class.js b/test/moduletest/class/class.js index a5c20f68e264b65947180162ca76220648d70725..6ab3e12cffafd4a076b2ff843d79eae77a02a8f4 100644 --- a/test/moduletest/class/class.js +++ b/test/moduletest/class/class.js @@ -40,4 +40,30 @@ class Child extends Parent { var c = new Child(2, 3); print(c.value()); -print(Child.toString()); \ No newline at end of file +print(Child.toString()); + +try { + class C { + a = 1; + } + class D extends C { + constructo() { + delete super.a; + } + } + d = new D(); +} catch (err) { + print("PASS"); +} + +class A { + a = 10; +} +class B extends A { + constructor() { + let a = "a"; + super[a] = 1; + } +} +var par = new A; +print(par.a); \ No newline at end of file diff --git a/test/moduletest/class/expect_output.txt b/test/moduletest/class/expect_output.txt index 6b506e71e8a1bb9cccb7335bb380759f543a1851..e7212fb27a19fecae9b08ea03cc5620da80df55e 100644 --- a/test/moduletest/class/expect_output.txt +++ b/test/moduletest/class/expect_output.txt @@ -13,3 +13,5 @@ 6 parent child +PASS +10 diff --git a/test/moduletest/container/container.js b/test/moduletest/container/container.js index 219bc97458f1e7d30cc588f513521ef5dcf23f67..13043c1433e0b7879fc7a295fca806449bbbc07e 100644 --- a/test/moduletest/container/container.js +++ b/test/moduletest/container/container.js @@ -13,5 +13,5 @@ * limitations under the License. */ -var helloworld = "container test start" -print(helloworld) \ No newline at end of file +var string = "container test start" +print(string) diff --git a/test/moduletest/container/container_arraylist.js b/test/moduletest/container/container_arraylist.js index a9a18c7ec49daac85f73875fc447d9c100826ca4..23d1553736ecb8274802f8b2ee7e50a7795ae326 100644 --- a/test/moduletest/container/container_arraylist.js +++ b/test/moduletest/container/container_arraylist.js @@ -13,18 +13,44 @@ * limitations under the License. */ -var fastarray = undefined; +var arrayList = undefined; if (globalThis["ArkPrivate"] != undefined) { - fastarray = ArkPrivate.Load(ArkPrivate.ArrayList); - let arr = new fastarray(); + arrayList = ArkPrivate.Load(ArkPrivate.ArrayList); + let arr = new arrayList(); arr.add(1); arr.add(2); - print(arr[0]); + let map = new Map(); + let flag1 = false; try { arr["aa"] = 3; } catch (e) { - print(e); + flag1 = true; + } + map.set("flag1", flag1); + + let flag2 = true; + for (let i = 0; i < arr.length; i++) { + if (arr[i] != (i + 1)) { + flag2 = false; + break; + } + } + map.set("flag2", flag2); + let flag = undefined; + function elements(value, key, map) { + if (!value) { + if (!flag) { + flag = []; + } + flag.push(key); + } + } + map.forEach(elements); + if (!flag) { + print("Test ArrayList success!!!"); + } else { + print("Test ArrayList fail: " + flag); } } diff --git a/test/moduletest/container/container_linked_list.js b/test/moduletest/container/container_linked_list.js index 21945d0d1a2f44be8278272e54c88ae0bf1bbcc1..f130d5e31cb81541a1ecfbc70761e4d7e57b9852 100644 --- a/test/moduletest/container/container_linked_list.js +++ b/test/moduletest/container/container_linked_list.js @@ -18,15 +18,16 @@ if (globalThis["ArkPrivate"] != undefined) { LinkedList = ArkPrivate.Load(ArkPrivate.LinkedList); let list = new LinkedList(); let testArray = [] + let map = new Map(); for(let i = 0; i<10; i++) { list.add(i) testArray.push(i) } - print("test linkedlist has:", list.has(8)) - print("test linkedlist not has:", list.has(2)) - print("test linkedlist getLastIndexOf:", list.getLastIndexOf(1) === 1) - print("test linkedlist getIndexOf:", list.getIndexOf(5) === 5) - + map.set("test linkedlist has:", list.has(8)) + map.set("test linkedlist not has:", list.has(2)) + map.set("test linkedlist getLastIndexOf:", list.getLastIndexOf(1) === 1) + map.set("test linkedlist getIndexOf:", list.getIndexOf(5) === 5) + list.removeByIndex(9) testArray.splice(9, 1) @@ -36,7 +37,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test linkedlist removeByIndex:", res) + map.set("test linkedlist removeByIndex:", res) const removeRes = list.remove(8) testArray.splice(8, 1) @@ -46,10 +47,10 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test linkedlist remove:", res) - print("test linkedlist remove1:", removeRes) - print("test linkedlist getFirst:", list.getFirst() === 0) - print("test linkedlist getLast:", list.getLast() === 7) + map.set("test linkedlist remove:", res) + map.set("test linkedlist remove1:", removeRes) + map.set("test linkedlist getFirst:", list.getFirst() === 0) + map.set("test linkedlist getLast:", list.getLast() === 7) list.insert(3, 999) testArray.splice(3, 0, 999) @@ -59,7 +60,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test linkedlist insert:", res) + map.set("test linkedlist insert:", res) list.set(5, 888) testArray[5] = 888 @@ -69,15 +70,14 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test linkedlist set:", res) - - print("test linkedlist clone:", res) + map.set("test linkedlist set:", res) + map.set("test linkedlist clone:", res) - list.addFirst(1111) - print("test linkedlist addfirst:", list.getFirst() === 1111) + list.addFirst(1111) + map.set("test linkedlist addfirst:", list.getFirst() === 1111) const removefirstres = list.removeFirst() - print("test linkedlist removeFirst:", removefirstres === 1111) + map.set("test linkedlist removeFirst:", removefirstres === 1111) res = true let i = 0 @@ -87,7 +87,7 @@ if (globalThis["ArkPrivate"] != undefined) { } i++; } - print("test linkedlist intertor:", res) + map.set("test linkedlist intertor:", res) let list1 = new LinkedList(); let testArray1 = [] @@ -103,20 +103,22 @@ if (globalThis["ArkPrivate"] != undefined) { } }) - print("test linkedlist forEach:", res) + map.set("test linkedlist forEach:", res) list1.clear() - print("test linkedlist clear:", list1.length === 0) - print("test linkedlist get:", list.get(1232) === undefined) - print("test linkedlist getLastIndexOf:", list.getLastIndexOf('abc') === -1) + map.set("test linkedlist clear:", list1.length === 0) + map.set("test linkedlist get:", list.get(1232) === undefined) + map.set("test linkedlist getLastIndexOf:", list.getLastIndexOf('abc') === -1) + let flag = false; try { list.removeByIndex(99) } catch (error) { - print("test linkedlist removeByIndex:", 'There is no such element to delete') + flag = true; } + map.set("test linkedlist removeByIndex:", flag) testArray.splice(5, 1) const resRemove = list.remove(888) - print("test linkedlist remove:", resRemove) + map.set("test linkedlist remove:", resRemove) res = true const arr = list.convertToArray() @@ -125,6 +127,21 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test linkedlist convertToArray:", res) + map.set("test linkedlist convertToArray:", res) + flag = undefined; + function elements(value, key, map) { + if (!value) { + if (!flag) { + flag = []; + } + flag.push(key); + } + } + map.forEach(elements); + if (!flag) { + print("Test LinkedList success!!!"); + } else { + print("Test LinkedList fail: " + flag); + } } diff --git a/test/moduletest/container/container_list.js b/test/moduletest/container/container_list.js index 4e678c076c974c662c06bbf82cdbf3cdfbe3a16b..f702878bf7d296ced8d5a48286c64ff486d8d8b5 100644 --- a/test/moduletest/container/container_list.js +++ b/test/moduletest/container/container_list.js @@ -18,14 +18,15 @@ if (globalThis["ArkPrivate"] != undefined) { List = ArkPrivate.Load(ArkPrivate.List); let list = new List(); const testArray = [] + let map = new Map(); for(let i = 0; i < 10; i++) { list.add(i) testArray.push(i) } - print("test list get 1:", list.get(1) === 1) - print("test list has:", list.has(8)) - print("test list not has:", list.has(123) === false) + map.set("test list get 1:", list.get(1) === 1) + map.set("test list has:", list.has(8)) + map.set("test list not has:", list.has(123) === false) let list1 = new List(); const testArray2 = [] @@ -33,13 +34,13 @@ if (globalThis["ArkPrivate"] != undefined) { list1.add(i) testArray2.push(i) } - - print("test list equal:", list.equal(list1)) + + map.set("test list equal:", list.equal(list1)) list.add(10) testArray.push(10) - print("test list equal:", list.equal(list1) === false) - print("test list getLastIndexOf:", list.getLastIndexOf(1) === 1) - print("test list getIndexOf:", list.getIndexOf(5) === 5) + map.set("test list equal:", list.equal(list1) === false) + map.set("test list getLastIndexOf:", list.getLastIndexOf(1) === 1) + map.set("test list getIndexOf:", list.getIndexOf(5) === 5) list.removeByIndex(10) testArray.splice(10, 1) @@ -49,7 +50,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list removeByIndex:", res) + map.set("test list removeByIndex:", res) list.remove(9) testArray.splice(9, 1) @@ -60,7 +61,7 @@ if (globalThis["ArkPrivate"] != undefined) { } testArray[i] = testArray[i] * 2 } - print("test list remove:", res) + map.set("test list remove:", res) list.replaceAllElements((item, index) => { return item * 2 @@ -71,9 +72,9 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list replaceAllElements:", res) - print("test list getFirst:", list.getFirst() === 0) - print("test list getLast:", list.getLast() === 16) + map.set("test list replaceAllElements:", res) + map.set("test list getFirst:", list.getFirst() === 0) + map.set("test list getLast:", list.getLast() === 16) list.insert(999, 3) testArray.splice(3, 0, 999) res = true @@ -82,8 +83,8 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list insert:", res) - + map.set("test list insert:", res) + list.set(5, 888) testArray[5] = 888 res = true @@ -92,7 +93,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list set:", res) + map.set("test list set:", res) let list2 = new List(); list2.add(4); @@ -107,7 +108,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list sort:", res) + map.set("test list sort:", res) res = true let subList = list.getSubList(1, 3) @@ -117,7 +118,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list getSubList:", res) + map.set("test list getSubList:", res) res = true const arr = list.convertToArray() @@ -126,7 +127,7 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } } - print("test list convertToArray:", res) + map.set("test list convertToArray:", res) res = true let i = 0 @@ -136,7 +137,7 @@ if (globalThis["ArkPrivate"] != undefined) { } i++; } - print("test list itertor:", res) + map.set("test list itertor:", res) res = true list1.forEach((i, d) => { @@ -144,17 +145,34 @@ if (globalThis["ArkPrivate"] != undefined) { res = false } }) - print("test list forEach:", res) + map.set("test list forEach:", res) list2.clear() - print("test list clear:", list2.length === 0) - print("test list get:", list1.get(200) === undefined) - print("test list getLastIndexOf:", list1.getLastIndexOf('abc') === -1) + map.set("test list clear:", list2.length === 0) + map.set("test list get:", list1.get(200) === undefined) + map.set("test list getLastIndexOf:", list1.getLastIndexOf('abc') === -1) + let flag = false; try { list1.removeByIndex(99) } catch (error) { - print("test list removeByIndex:", 'There is no such element to delete') + flag = true; } + map.set("test list removeByIndex:", flag) res = list1.remove(888) - print("test list remove:", res) -} + map.set("test list remove:", !res) + flag = undefined; + function elements(value, key, map) { + if (!value) { + if (!flag) { + flag = []; + } + flag.push(key); + } + } + map.forEach(elements); + if (!flag) { + print("Test List success!!!"); + } else { + print("Test List fail: " + flag); + } +} diff --git a/test/moduletest/container/container_treemap.js b/test/moduletest/container/container_treemap.js index 2e64b2e86ca60d91ad9bf0f07cce48913b26dc50..7a5b9e44ae7fcaed755deb0341a04aef43daec6a 100644 --- a/test/moduletest/container/container_treemap.js +++ b/test/moduletest/container/container_treemap.js @@ -16,75 +16,90 @@ var fastmap = undefined; if (globalThis["ArkPrivate"] != undefined) { fastmap = ArkPrivate.Load(ArkPrivate.TreeMap); -} -let map = new fastmap(); -map.set("a", "aa"); -map.set("b", "bb"); + let res = new Map(); + let map = new fastmap(); + map.set("a", "aa"); + map.set("b", "bb"); -print("### test TreeMap start ###") -// test get, out: true -print("test get, out:", map.length == 2 && map.get("a") == "aa" && map.get("b") == "bb"); -// test hasKey and hasValue, out: true -print("test hasKey and hasValue, out:", map.hasKey("a") && map.hasKey("b") && map.hasValue("aa") && - map.hasValue("bb") && !map.hasKey("c") && !map.hasValue("cc")); + // test get: true + res.set("test get:", map.length == 2 && map.get("a") == "aa" && map.get("b") == "bb"); + // test hasKey and hasValue: true + res.set("test hasKey and hasValue:", map.hasKey("a") && map.hasKey("b") && map.hasValue("aa") && + map.hasValue("bb") && !map.hasKey("c") && !map.hasValue("cc")); -map.set("c", "cc"); -// test getFirstKey and getLastKey, out: true -print("test getFirstKey and getLastKey, out:", map.getFirstKey() == "a" && map.getLastKey() == "c"); -// test getLowerKey and getHigherKey, out: true -print("test getLowerKey and getHigherKey, out:", map.getLowerKey("b") == "a" && map.getLowerKey("a") == undefined && - map.getHigherKey("b") == "c" && map.getHigherKey("c") == undefined); -// test keys, out: true -let iteratorKey = map.keys(); -print("test keys, out:", iteratorKey.next().value == "a" && iteratorKey.next().value == "b" && - iteratorKey.next().value == "c" && iteratorKey.next().value == undefined); -// test values, out: true -let iteratorValues = map.values(); -print("test values, out:", iteratorValues.next().value == "aa" && iteratorValues.next().value == "bb" && - iteratorValues.next().value == "cc" && iteratorValues.next().value == undefined); -// test entries, out: [c,cc], undefined -let iteratorEntries = map.entries(); -iteratorEntries.next().value; -iteratorEntries.next().value; -print("test entries, out:", iteratorEntries.next().value); -print(iteratorEntries.next().value); + map.set("c", "cc"); + // test getFirstKey and getLastKey: true + res.set("test getFirstKey and getLastKey:", map.getFirstKey() == "a" && map.getLastKey() == "c"); + // test getLowerKey and getHigherKey: true + res.set("test getLowerKey and getHigherKey:", map.getLowerKey("b") == "a" && map.getLowerKey("a") == undefined && + map.getHigherKey("b") == "c" && map.getHigherKey("c") == undefined); + // test keys: true + let iteratorKey = map.keys(); + res.set("test keys:", iteratorKey.next().value == "a" && iteratorKey.next().value == "b" && + iteratorKey.next().value == "c" && iteratorKey.next().value == undefined); + // test values: true + let iteratorValues = map.values(); + res.set("test values:", iteratorValues.next().value == "aa" && iteratorValues.next().value == "bb" && + iteratorValues.next().value == "cc" && iteratorValues.next().value == undefined); + // test entries: [c,cc], undefined + let iteratorEntries = map.entries(); + iteratorEntries.next().value; + iteratorEntries.next().value; + res.set("test entries1:", iteratorEntries.next().value != undefined); + res.set("itest entries2:", iteratorEntries.next().value == undefined); -// test forof, out: [a, aa], [b, bb], [c, cc] -print("test forof, out:"); -for (const item of map) { - print(item); -} -// test forin, out: -print("test forin, out:"); -for (const item in map) { - print(item); -} -// test forEach, out: -let flag = false; -print("test forEach, out:"); -function TestForEach(value, key, map) { - flag = map.get(key) === value; - if (!flag) { - print(false) + // test forof: [a, aa], [b, bb], [c, cc] + let arr = ["aa", "bb", "cc"]; + let i = 0; + for (const item of map) { + res.set(arr[i], item[1] == arr[i]); + i++; } -} -map.forEach(TestForEach); + // test forin: + for (const item in map) { + res.set("test forin", false); + } + // test forEach: + let flag = false; + function TestForEach(value, key, map) { + flag = map.get(key) === value; + res.set("test forEach" + key, flag) + } + map.forEach(TestForEach); -let dmap = new fastmap(); -// test setAll, out: 3 -dmap.setAll(map); -print("test setAll, out:", dmap.length); -// test remove, out: true -print("test remove, out:", dmap.remove("a") == "aa" && dmap.length == 2); -// test replace, out: true -print("test replace, out:", dmap.replace("b", "dd") && dmap.get("b") == "dd"); -// test clear, out: 0 -dmap.clear(); -print("test clear, out:", dmap.length); + let dmap = new fastmap(); + // test setAll: 3 + dmap.setAll(map); + res.set("test setAll:", dmap.length == 3); + // test remove: true + res.set("test remove:", dmap.remove("a") == "aa" && dmap.length == 2); + // test replace: true + res.set("test replace:", dmap.replace("b", "dd") && dmap.get("b") == "dd"); + // test clear: 0 + dmap.clear(); + res.set("test clear:", dmap.length == 0); -try { - map["aa"] = 3; -} catch (e) { - print(e); + flag = false; + try { + map["aa"] = 3; + } catch (e) { + flag = true; + } + res.set("test map throw error", flag); + flag = undefined; + function elements(value, key, map) { + if (!value) { + if (!flag) { + flag = []; + } + flag.push(key); + } + } + res.forEach(elements); + if (!flag) { + print("Test TreeMap success!!!"); + } else { + print("Test TreeMap fail: " + flag); + } } diff --git a/test/moduletest/container/container_treeset.js b/test/moduletest/container/container_treeset.js index 94123d08b90e8bbf5747f15f8e8e57090d6b4d98..81aa6abbf0c83068031c24c632a7d42a6df29cce 100644 --- a/test/moduletest/container/container_treeset.js +++ b/test/moduletest/container/container_treeset.js @@ -16,73 +16,90 @@ var fastset = undefined; if (globalThis["ArkPrivate"] != undefined) { fastset = ArkPrivate.Load(ArkPrivate.TreeSet); -} -let set = new fastset(); -set.add("aa"); -set.add("bb"); + let map = new Map(); + let set = new fastset(); + set.add("aa"); + set.add("bb"); -print("### test TreeSet start ###") -// test has, out: true -print("test has, out:", set.length == 2 && set.has("aa") && set.has("bb") && !set.has("cc")); + // test has: true + map.set("test has:", set.length == 2 && set.has("aa") && set.has("bb") && !set.has("cc")); -set.add("cc"); -// test getFirstKey and getLastKey, out: true -print("test getFirstKey and getLastKey, out:", set.getFirstValue() == "aa" && set.getLastValue() == "cc"); -// test getLowerValue and getHigherValue out: true -print("test getLowerValue and getHigherValue out:", set.getLowerValue("bb") == "aa" && - set.getLowerValue("aa") == undefined && set.getHigherValue("bb") == "cc" && set.getHigherValue("cc") == undefined); + set.add("cc"); + // test getFirstKey and getLastKey: true + map.set("test getFirstKey and getLastKey:", set.getFirstValue() == "aa" && set.getLastValue() == "cc"); + // test getLowerValue and getHigherValue out: true + map.set("test getLowerValue and getHigherValue", set.getLowerValue("bb") == "aa" && + set.getLowerValue("aa") == undefined && set.getHigherValue("bb") == "cc" && + set.getHigherValue("cc") == undefined); -// test values, out: true -let iteratorSetValues = set.values(); -print("test values, out:", iteratorSetValues.next().value == "aa" && iteratorSetValues.next().value == "bb" && - iteratorSetValues.next().value == "cc" && iteratorSetValues.next().value == undefined); -// test entries, out: [cc, cc], undefined -let iteratorSetEntries = set.entries(); -iteratorSetEntries.next().value; -iteratorSetEntries.next().value; -print("test entries, out:", iteratorSetEntries.next().value); -print(iteratorSetEntries.next().value); + // test values: true + let iteratorSetValues = set.values(); + map.set("test values:", iteratorSetValues.next().value == "aa" && iteratorSetValues.next().value == "bb" && + iteratorSetValues.next().value == "cc" && iteratorSetValues.next().value == undefined); + // test entries: [cc, cc], undefined + let iteratorSetEntries = set.entries(); + iteratorSetEntries.next().value; + iteratorSetEntries.next().value; + map.set("test entries1:", iteratorSetEntries.next().value != undefined); + map.set("test entries2:", iteratorSetEntries.next().value == undefined); -// test forof, out: aa, bb, cc -print("test forof, out:"); -for (const item of set) { - print(item); -} + // test forof: aa, bb, cc + let arr = ["aa", "bb", "cc"]; + let i = 0; + for (const item of set) { + map.set(arr[i], item == arr[i]); + i++; + } -// test forin, out: -print("test forin, out:"); -for (const item in set) { - print(item); -} + // test forin: + for (const item in set) { + map.set("test forin:", item); + } -// test forEach, out: -let setFlag = false; -print("test forEach, out:"); -function TestForEach(value, key, set) { - setFlag= set.has(key) && set.has(value); - if (!setFlag) { - print(false); + // test forEach: + let setFlag = false; + function TestForEach(value, key, set) { + setFlag= set.has(key) && set.has(value); + map.set("test forEach" + key, setFlag); } -} -set.forEach(TestForEach); + set.forEach(TestForEach); + + // test isEmpty: false + map.set("test isEmpty:", !set.isEmpty()); -// test isEmpty, out: false -print("test isEmpty, out:", set.isEmpty()); + set.add("ee"); + set.add("dd"); + // test popFirst and popLast: true + map.set("test popFirst and popLast:", set.length == 5 && set.popFirst() == "aa" && + set.popLast() == "ee" && !set.has("aa")); + // test remove: true + map.set("test remove:", set.remove("bb") && set.length == 2 && !set.has("bb")); + // test clear: true + set.clear(); + map.set("test clear:", set.length == 0 && !set.has("cc") && set.isEmpty()); -set.add("ee"); -set.add("dd"); -// test popFirst and popLast, out: true -print("test popFirst and popLast, out:", set.length == 5 && set.popFirst() == "aa" && - set.popLast() == "ee" && !set.has("aa")); -// test remove, out: true -print("test remove, out:", set.remove("bb") && set.length == 2 && !set.has("bb")); -// test clear, out: true -set.clear(); -print("test clear, out:", set.length == 0 && !set.has("cc") && set.isEmpty()); + let flag = false; + try { + set["aa"] = 3; + } catch (e) { + flag = true; + } + map.set("test set throw error", flag); -try { - set["aa"] = 3; -} catch (e) { - print(e); + flag = undefined; + function elements(value, key, map) { + if (!value) { + if (!flag) { + flag = []; + } + flag.push(key); + } + } + map.forEach(elements); + if (!flag) { + print("Test TreeSet success!!!"); + } else { + print("Test TreeSet fail: " + flag); + } } diff --git a/test/moduletest/container/container_vector.js b/test/moduletest/container/container_vector.js index 239f5ee055ac27505f79036fe78c12beeee79866..17f0e9f695f2dc0b1678238017d086fb63ca4d82 100644 --- a/test/moduletest/container/container_vector.js +++ b/test/moduletest/container/container_vector.js @@ -16,52 +16,71 @@ var FastVector = undefined; if (globalThis["ArkPrivate"] != undefined) { FastVector = ArkPrivate.Load(ArkPrivate.Vector); -} -let vector = new FastVector(); -vector.add(4); // index is 0 -vector.add(3); -vector.add(1); -vector.add(5); -vector.add(14); -print("### test Vector start ###") -let res = vector.toString(); -print("test add and toString, out:", res); -// test insert, length, get, getIndexOf -vector.insert(2, 2); -print("test length, out:", vector.length == 6); -print("test get(index is 2), out:", vector.get(2) == 2); -print("test get(index is 3), out:", vector.get(3) == 3); // false -print("test getIndexOf(target is 3), out:", vector.getIndexOf(3) == 1); // true -print("test getIndexOf(target is 2), out:", vector.getIndexOf(2) == 5); // false -// test isEmpty -print("test isEmpty, out:", vector.isEmpty()); + let map = new Map(); + let vector = new FastVector(); + vector.add(4); // index is 0 + vector.add(3); + vector.add(1); + vector.add(5); + vector.add(14); + let res = vector.toString(); + map.set("test add and toString:", res); + // test insert, length, get, getIndexOf + vector.insert(2, 2); + map.set("test length:", vector.length == 6); + map.set("test get(index is 2):", vector.get(2) == 2); + map.set("test get(index is 3):", vector.get(3) !== 3); // false + map.set("test getIndexOf(target is 3):", vector.getIndexOf(3) == 1); // true + map.set("test getIndexOf(target is 2):", vector.getIndexOf(2) !== 5); // false + // test isEmpty + map.set("test isEmpty:", !vector.isEmpty()); -let vec = vector.clone(); -// test clear -vector.clear(); -print("test clear, out:", vector.isEmpty()); -// test set, clone -vec.set(2, 8); -print("test set, out:", vec.get(2) == 8 && vec.length == 6); -// test subvector -let subVec = vec.subVector(0, 3); -print("test subVector and tostring, out:", subVec.toString()); -// test replaceAllElements -subVec.replaceAllElements((item, index) => { - return (item = 2 * item); -}); -print("test replaceAllElements, out:", subVec.toString() == "8,6,16"); -// GetFirstElement -print("test GetFirstElement, out:", subVec.getFirstElement() == 8 && - vec.getFirstElement() == 4); -print("test forof, out:"); -for (const item of vec) { - print(item); -} + let vec = vector.clone(); + // test clear + vector.clear(); + map.set("test clear:", vector.isEmpty()); + // // test set, clone + vec.set(2, 8); + map.set("test set:", vec.get(2) == 8 && vec.length == 6); + // test subvector + let subVec = vec.subVector(0, 3); + map.set("test subVector and tostring:", subVec.toString()); + // test replaceAllElements + subVec.replaceAllElements((item, index) => { + return (item = 2 * item); + }); + map.set("test replaceAllElements:", subVec.toString() == "8,6,16"); + // GetFirstElement + map.set("test GetFirstElement:", subVec.getFirstElement() == 8 && + vec.getFirstElement() == 4); + + let arr = [4, 3, 8, 1, 5, 14]; + for (let i = 0; i < vector.length; i++) { + map.set("for of " + arr[i], vec.get(i) == arr[i]); + } -try { - vec["aa"] = 3; -} catch (e) { - print(e); -} \ No newline at end of file + let flag = false; + try { + vec["aa"] = 3; + } catch (e) { + flag = true; + } + + map.set("test vector throw error", flag); + flag = undefined; + function elements(value, key, map) { + if (!value) { + if (!flag) { + flag = []; + } + flag.push(key); + } + } + map.forEach(elements); + if (!flag) { + print("Test Vector success!!!"); + } else { + print("Test Vector fail: " + flag); + } +} diff --git a/test/moduletest/container/expect_output.txt b/test/moduletest/container/expect_output.txt index a7a47b12f3ff9e1724664018c73de4885f1bdd9a..5064b5a63eaa0e4e1f6f0c0ed0e942470fcd3300 100644 --- a/test/moduletest/container/expect_output.txt +++ b/test/moduletest/container/expect_output.txt @@ -12,110 +12,9 @@ # limitations under the License. container test start -1 -TypeError: Cannot set property on Container -test linkedlist has: true -test linkedlist not has: true -test linkedlist getLastIndexOf: true -test linkedlist getIndexOf: true -test linkedlist removeByIndex: true -test linkedlist remove: true -test linkedlist remove1: true -test linkedlist getFirst: true -test linkedlist getLast: true -test linkedlist insert: true -test linkedlist set: true -test linkedlist clone: true -test linkedlist addfirst: true -test linkedlist removeFirst: true -test linkedlist intertor: true -test linkedlist forEach: true -test linkedlist clear: true -test linkedlist get: true -test linkedlist getLastIndexOf: true -test linkedlist removeByIndex: There is no such element to delete -test linkedlist remove: true -test linkedlist convertToArray: true -test list get 1: true -test list has: true -test list not has: true -test list equal: true -test list equal: true -test list getLastIndexOf: true -test list getIndexOf: true -test list removeByIndex: true -test list remove: true -test list replaceAllElements: true -test list getFirst: true -test list getLast: true -test list insert: true -test list set: true -test list sort: true -test list getSubList: true -test list convertToArray: true -test list itertor: true -test list forEach: true -test list clear: true -test list get: true -test list getLastIndexOf: true -test list removeByIndex: There is no such element to delete -test list remove: false -### test TreeMap start ### -test get, out: true -test hasKey and hasValue, out: true -test getFirstKey and getLastKey, out: true -test getLowerKey and getHigherKey, out: true -test keys, out: true -test values, out: true -test entries, out: c,cc -undefined -test forof, out: -a,aa -b,bb -c,cc -test forin, out: -test forEach, out: -test setAll, out: 3 -test remove, out: true -test replace, out: true -test clear, out: 0 -TypeError: Cannot set property on Container -### test TreeSet start ### -test has, out: true -test getFirstKey and getLastKey, out: true -test getLowerValue and getHigherValue out: true -test values, out: true -test entries, out: cc,cc -undefined -test forof, out: -aa -bb -cc -test forin, out: -test forEach, out: -test isEmpty, out: false -test popFirst and popLast, out: true -test remove, out: true -test clear, out: true -TypeError: Cannot set property on Container -### test Vector start ### -test add and toString, out: 4,3,1,5,14 -test length, out: true -test get(index is 2), out: true -test get(index is 3), out: false -test getIndexOf(target is 3), out: true -test getIndexOf(target is 2), out: false -test isEmpty, out: false -test clear, out: true -test set, out: true -test subVector and tostring, out: 4,3,8 -test replaceAllElements, out: true -test GetFirstElement, out: true -test forof, out: -4 -3 -8 -1 -5 -14 -TypeError: Cannot set property on Container +Test ArrayList success!!! +Test LinkedList success!!! +Test List success!!! +Test TreeMap success!!! +Test TreeSet success!!! +Test Vector success!!! diff --git a/build/third_party_gn/bounds_checking_function/BUILD.gn b/test/moduletest/loadicbyvalue/BUILD.gn similarity index 39% rename from build/third_party_gn/bounds_checking_function/BUILD.gn rename to test/moduletest/loadicbyvalue/BUILD.gn index 73cbb3d8c340ddf513cdf759a8081c577851429a..0f80e7138f1cb6f83ca2bb2bbd1d2c6a48e748db 100644 --- a/build/third_party_gn/bounds_checking_function/BUILD.gn +++ b/test/moduletest/loadicbyvalue/BUILD.gn @@ -3,7 +3,7 @@ # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # -# http://www.apache.org/licenses/LICENSE-2.0 +# http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, @@ -11,38 +11,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//third_party/bounds_checking_function/libsec_src.gni") -import("$build_root/ark.gni") +import("//ark/js_runtime/test/test_helper.gni") -config("libsec_public_config") { - include_dirs = [ "//third_party/bounds_checking_function/include" ] - cflags_cc = [ "-fPIC" ] -} - -ark_static_library("libsec_static") { - sources = libsec_sources - public_configs = [ ":libsec_public_config" ] - cflags = [ - "-D_INC_STRING_S", - "-D_INC_WCHAR_S", - "-D_SECIMP=//", - "-D_STDIO_S_DEFINED", - "-D_INC_STDIO_S", - "-D_INC_STDLIB_S", - "-D_INC_MEMORY_S", - ] -} - -ark_shared_library("libsec_shared") { - sources = libsec_sources - public_configs = [ ":libsec_public_config" ] - cflags = [ - "-D_INC_STRING_S", - "-D_INC_WCHAR_S", - "-D_SECIMP=//", - "-D_STDIO_S_DEFINED", - "-D_INC_STDIO_S", - "-D_INC_STDLIB_S", - "-D_INC_MEMORY_S", - ] +host_moduletest_action("loadicbyvalue") { + deps = [] } diff --git a/test/moduletest/loadicbyvalue/expect_output.txt b/test/moduletest/loadicbyvalue/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..aa7ff3ba40aeaffb485d35f587370b442fe0303e --- /dev/null +++ b/test/moduletest/loadicbyvalue/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +icsuccess diff --git a/test/moduletest/loadicbyvalue/loadicbyvalue.js b/test/moduletest/loadicbyvalue/loadicbyvalue.js new file mode 100644 index 0000000000000000000000000000000000000000..84cb2e26f6f4e43dde45c09c952daf5260f5f032 --- /dev/null +++ b/test/moduletest/loadicbyvalue/loadicbyvalue.js @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var i = 3; +var obj = {3:"icsuccess"}; +function func1(a) +{ + var b = a[i]; +} +for (let j = 300; j > 0; j--) +{ + func1(obj); +} +print(obj[i]); \ No newline at end of file diff --git a/test/moduletest/moduleUseCjs/BUILD.gn b/test/moduletest/moduleUseCjs/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..bccf164a1baa5d40c0a912f6cce87d9a76eaf1cd --- /dev/null +++ b/test/moduletest/moduleUseCjs/BUILD.gn @@ -0,0 +1,25 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_moduletest_action("Cjs") { + deps = [] + is_commonjs = true +} + +host_moduletest_action("moduleUseCjs") { + extra_modules = [ "Cjs" ] + deps = [ ":gen_Cjs_abc" ] + is_module = true +} diff --git a/test/moduletest/moduleUseCjs/Cjs.js b/test/moduletest/moduleUseCjs/Cjs.js new file mode 100644 index 0000000000000000000000000000000000000000..ca423479fbc1140f0f506ad6ae786cc66cfb9f0e --- /dev/null +++ b/test/moduletest/moduleUseCjs/Cjs.js @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +var cjs = "module use cjsModule" +module.exports = cjs diff --git a/test/moduletest/moduleUseCjs/expect_output.txt b/test/moduletest/moduleUseCjs/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..2dcf09e3795a8a5a5c3614ccf4f48356e74279f5 --- /dev/null +++ b/test/moduletest/moduleUseCjs/expect_output.txt @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"module use cjsModule" diff --git a/test/moduletest/moduleUseCjs/moduleUseCjs.js b/test/moduletest/moduleUseCjs/moduleUseCjs.js new file mode 100644 index 0000000000000000000000000000000000000000..5bea095465fe22c76a7e29dca09a53c3f2a267e1 --- /dev/null +++ b/test/moduletest/moduleUseCjs/moduleUseCjs.js @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import cjs from "./Cjs" +print(JSON.stringify(cjs)) \ No newline at end of file diff --git a/test/moduletest/objoperate/BUILD.gn b/test/moduletest/objoperate/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..332c5f83d709a8920344a57b3ed4f97af7355f0f --- /dev/null +++ b/test/moduletest/objoperate/BUILD.gn @@ -0,0 +1,18 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//ark/js_runtime/test/test_helper.gni") + +host_moduletest_action("objoperate") { + deps = [] +} diff --git a/test/moduletest/objoperate/expect_output.txt b/test/moduletest/objoperate/expect_output.txt new file mode 100644 index 0000000000000000000000000000000000000000..d684a92a3c92917f46065574aa2d4a6d9c890c0a --- /dev/null +++ b/test/moduletest/objoperate/expect_output.txt @@ -0,0 +1,15 @@ +# Copyright (c) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +PASS +PASS diff --git a/test/moduletest/objoperate/objoperate.js b/test/moduletest/objoperate/objoperate.js new file mode 100644 index 0000000000000000000000000000000000000000..ef0266bc2dc4b6f2917d073f0e6419ce926eed0b --- /dev/null +++ b/test/moduletest/objoperate/objoperate.js @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +function assertEqual(a, b) { + var t1 = JSON.stringify(a); + var t2 = JSON.stringify(b); + if (t1 == t2) { + print("PASS"); + } else { + print("FAIL"); + } +} + +var obj1 = {a:2, b:3, c:4}; +var obj2 = {d:1, ...obj1, e:5}; +assertEqual(obj2, {d:1, a:2, b:3, c:4, e:5}); + +var obj = {["a" + "b" + "de"]:function() {return 1;}} +assertEqual(obj.abde.name, "abde"); \ No newline at end of file diff --git a/test/resource/js_runtime/ohos_test.xml b/test/resource/js_runtime/ohos_test.xml index 2f36dbc66adc32df9871e0ca50d34dea8f79980f..bf3739f98c27c2c1c6f9fe1b0647494121769e79 100755 --- a/test/resource/js_runtime/ohos_test.xml +++ b/test/resource/js_runtime/ohos_test.xml @@ -17,26 +17,39 @@ + - + - + - + + + + + @@ -46,12 +59,12 @@ - + - + @@ -66,12 +79,17 @@ - + + + + + - + diff --git a/test/run_test262.sh b/test/run_test262.sh index 43539778dd6821e43b36dde0f5182f9526efa2e0..233a493c8eec1d94ed5c60d1de373173d91799fc 100644 --- a/test/run_test262.sh +++ b/test/run_test262.sh @@ -26,12 +26,12 @@ pushd ark/ts2abc pushd ../../ if [ -d out/rk3568 ];then pushd ark/ts2abc - python3 test262/run_test262.py --es2015 all --threads=16 --libs-dir ../../out/rk3568/clang_x64/ark/ark:../../out/rk3568/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=../../out/rk3568/clang_x64/ark/ark/build/src/index.js + python3 test262/run_test262.py --es2021 all --threads=16 --libs-dir ../../out/rk3568/clang_x64/ark/ark:../../out/rk3568/clang_x64/ark/ark_js_runtime:../../out/rk3568/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/rk3568/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=../../out/rk3568/clang_x64/ark/ark/build/src/index.js popd fi if [ -d out/hispark_taurus ];then pushd ark/ts2abc - python3 test262/run_test262.py --es2015 all --threads=16 --libs-dir ../../out/hispark_taurus/clang_x64/ark/ark:../../out/hispark_taurus/clang_x64/ark/ark_js_runtime:../../out/hispark_taurus/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=../../out/hispark_taurus/clang_x64/ark/ark/build/src/index.js + python3 test262/run_test262.py --es2021 all --threads=16 --libs-dir ../../out/hispark_taurus/clang_x64/ark/ark:../../out/hispark_taurus/clang_x64/ark/ark_js_runtime:../../out/hispark_taurus/clang_x64/thirdparty/icu:../../prebuilts/clang/ohos/linux-x86_64/llvm/lib --ark-tool=../../out/hispark_taurus/clang_x64/ark/ark_js_runtime/ark_js_vm --ark-frontend-tool=../../out/hispark_taurus/clang_x64/ark/ark/build/src/index.js popd fi popd @@ -46,10 +46,10 @@ pushd ark/ts2abc exit 1; fi - cp out/test262/result.txt report/result_es2015_${time}.txt + cp out/test262/result.txt report/result_es2021_${time}.txt pushd report - es2015_fail=$(grep FAIL result_es2015_${time}.txt | wc -l) + es2015_fail=$(grep FAIL result_es2021_${time}.txt | wc -l) threshold=0 if [ ${es2015_fail} -gt ${threshold} ];then echo 'test262 fail case over thresgold' diff --git a/test/test_helper.gni b/test/test_helper.gni index 67d492dd05adc57ee6ab461c1990f413c0cc8275..1475c6c66d1bc8d278b93d25e94551560d727917 100644 --- a/test/test_helper.gni +++ b/test/test_helper.gni @@ -172,7 +172,6 @@ template("host_moduletest_action") { _root_out_dir_ = get_label_info(_host_jsvm_target_, "root_out_dir") deps = [ ":gen_${_target_name_}_abc", - "//ark/js_runtime/ecmascript/compiler:gen_stub_file(${host_toolchain})", _host_jsvm_target_, ] deps += _deps_ @@ -290,7 +289,6 @@ template("host_aot_test_action") { deps = [ ":${_target_name_}AotCompileAction", ":gen_${_target_name_}_abc", - "//ark/js_runtime/ecmascript/compiler:gen_stub_file(${host_toolchain})", _host_jsvm_target_, ] deps += _deps_ @@ -302,6 +300,11 @@ template("host_aot_test_action") { " --snapshot-output-file=" + rebase_path(_test_snapshot_path_) + " --asm-interpreter=true" + if (defined(invoker.is_enable_enableArkTools) && + invoker.is_enable_enableArkTools) { + _aot_run_options_ += " --enable-ark-tools=true" + } + args = [ "--script-file", rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_js_vm",